@Test public void testForeach() { final Integer[] r = new Integer[1]; final Function<String, Option<Integer>> f = Options.foreach(new Function<String, Option<Integer>>() { @Override public Option<Integer> apply(String s) { return s.length() > 0 ? some(s.length()) : none(Integer.class); } }, new Effect<Integer>() { @Override protected void run(Integer integer) { r[0] = integer; } }); assertEquals(none(Integer.class), f.apply("")); assertNull(r[0]); assertEquals(some(3), f.apply("bla")); assertEquals(new Integer(3), r[0]); }
public static <A, B> Function<A, Option<B>> foreach(final Function<? super A, ? extends Option<? extends B>> f, final Effect<? super B> e) { return new Function<A, Option<B>>() { @Override public Option<B> apply(A a) { return (Option<B>) f.apply(a).foreach(e); } }; }
Options { public static <A, B> Function<A, Option<B>> foreach(final Function<? super A, ? extends Option<? extends B>> f, final Effect<? super B> e) { return new Function<A, Option<B>>() { @Override public Option<B> apply(A a) { return (Option<B>) f.apply(a).foreach(e); } }; } }
Options { public static <A, B> Function<A, Option<B>> foreach(final Function<? super A, ? extends Option<? extends B>> f, final Effect<? super B> e) { return new Function<A, Option<B>>() { @Override public Option<B> apply(A a) { return (Option<B>) f.apply(a).foreach(e); } }; } private  Options(); }
Options { public static <A, B> Function<A, Option<B>> foreach(final Function<? super A, ? extends Option<? extends B>> f, final Effect<? super B> e) { return new Function<A, Option<B>>() { @Override public Option<B> apply(A a) { return (Option<B>) f.apply(a).foreach(e); } }; } private  Options(); static Option<A> join(Option<Option<A>> a); static Function<Option<A>, List<A>> asList(); static Option<String> toOption(boolean predicate, String message); static Option<List<A>> sequenceOpt(List<Option<A>> as); static Function<A, Option<B>> foreach(final Function<? super A, ? extends Option<? extends B>> f,
          final Effect<? super B> e); }
Options { public static <A, B> Function<A, Option<B>> foreach(final Function<? super A, ? extends Option<? extends B>> f, final Effect<? super B> e) { return new Function<A, Option<B>>() { @Override public Option<B> apply(A a) { return (Option<B>) f.apply(a).foreach(e); } }; } private  Options(); static Option<A> join(Option<Option<A>> a); static Function<Option<A>, List<A>> asList(); static Option<String> toOption(boolean predicate, String message); static Option<List<A>> sequenceOpt(List<Option<A>> as); static Function<A, Option<B>> foreach(final Function<? super A, ? extends Option<? extends B>> f,
          final Effect<? super B> e);  }