@Test public void testSequenceOpt() { assertTrue(eqListSorted(list(1, 2, 3), sequenceOpt(list(some(1), none(-1), some(2), some(3), none(-1))).get())); assertTrue(eqListSorted(list(), sequenceOpt(list(none(-1), none(-1))).get())); }
public static <A> Option<List<A>> sequenceOpt(List<Option<A>> as) { final List<A> seq = mlist(as).foldl(new ArrayList<A>(), new Function2<List<A>, Option<A>, List<A>>() { @Override public List<A> apply(List<A> sum, Option<A> o) { for (A a : o) { sum.add(a); return sum; } return sum; } }); return some(seq); }
Options { public static <A> Option<List<A>> sequenceOpt(List<Option<A>> as) { final List<A> seq = mlist(as).foldl(new ArrayList<A>(), new Function2<List<A>, Option<A>, List<A>>() { @Override public List<A> apply(List<A> sum, Option<A> o) { for (A a : o) { sum.add(a); return sum; } return sum; } }); return some(seq); } }
Options { public static <A> Option<List<A>> sequenceOpt(List<Option<A>> as) { final List<A> seq = mlist(as).foldl(new ArrayList<A>(), new Function2<List<A>, Option<A>, List<A>>() { @Override public List<A> apply(List<A> sum, Option<A> o) { for (A a : o) { sum.add(a); return sum; } return sum; } }); return some(seq); } private  Options(); }
Options { public static <A> Option<List<A>> sequenceOpt(List<Option<A>> as) { final List<A> seq = mlist(as).foldl(new ArrayList<A>(), new Function2<List<A>, Option<A>, List<A>>() { @Override public List<A> apply(List<A> sum, Option<A> o) { for (A a : o) { sum.add(a); return sum; } return sum; } }); return some(seq); } 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> Option<List<A>> sequenceOpt(List<Option<A>> as) { final List<A> seq = mlist(as).foldl(new ArrayList<A>(), new Function2<List<A>, Option<A>, List<A>>() { @Override public List<A> apply(List<A> sum, Option<A> o) { for (A a : o) { sum.add(a); return sum; } return sum; } }); return some(seq); } 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);  }