DecodeResult { public final DecodeResult<A> filter(Predicate<A> p) { return filter(p, () -> "Filter failed"); } private  DecodeResult(); final DecodeResult<B> map(Function<A, B> f); final DecodeResult<A> filter(Predicate<A> p); final DecodeResult<A> filter(Predicate<A> p, Supplier<String> errorSupplier); final void forEach(Consumer<A> f); final DecodeResult<B> flatMap(Function<A, DecodeResult<B>> f); final A getOrElse(Supplier<A> orElse); final DecodeResult<A> orElse(DecodeResult<A> orThis); abstract A getOrElseThrow(Function<String, X> exProvider); final A unsafeGet(); final Optional<A> toOption(); abstract B fold(Function<String, B> failFunction, Function<A, B> okFunction); abstract void consume(Consumer<String> failFunction, Consumer<A> okFunction); boolean isOk(); boolean isFailure(); static DecodeResult<List<A>> sequence(List<DecodeResult<A>> decodeResults); static DecodeResult<R> sequence(final Iterable<DecodeResult<T>> results, final Collector<T, A, R> collector); static DecodeResult<A> ok(A value); static DecodeResult<A> fromOption(Optional<A> value); static DecodeResult<A> fromCallable(Callable<A> value); static DecodeResult<A> fromOption(Optional<A> value, Supplier<String> error); @SuppressWarnings("unchecked") static DecodeResult<A> fail(String message); static DecodeResult<A> decode(Json.JObject object, FieldDecoder<A> decoder); static DecodeResult<A> decode(Json.JObject object, String name, DecodeJson<A> decoder);  }
@Test public void filter() throws Exception { DecodeResult<String> res2 = DecodeResult.ok("Hello"); assertEquals("Hello", res2.filter(a -> a.equals("Hello")).unsafeGet()); assertEquals("Hello", res2.filter(Predicate.isEqual("Hello")).unsafeGet()); assertEquals("Hello", res2.filter(Objects::nonNull).unsafeGet()); }