@Test public void testHead() { List<String> list = newTestList(); Option.Match<String, Boolean> match = new Option.Match<String, Boolean>() { @Override public Boolean some(String s) { return true; } @Override public Boolean none() { return false; } }; assertTrue(head(list).fold(match)); List<String> empty = list(); assertFalse(head(empty).fold(match)); }
public static <A> Option<A> head(List<A> as) { if (!as.isEmpty()) { return some(as.get(0)); } else { return Option.none(); } }
Collections { public static <A> Option<A> head(List<A> as) { if (!as.isEmpty()) { return some(as.get(0)); } else { return Option.none(); } } }
Collections { public static <A> Option<A> head(List<A> as) { if (!as.isEmpty()) { return some(as.get(0)); } else { return Option.none(); } } private  Collections(); }
Collections { public static <A> Option<A> head(List<A> as) { if (!as.isEmpty()) { return some(as.get(0)); } else { return Option.none(); } } private  Collections(); @Deprecated static M map(Collection<A> as, M bs, Function<A, B> f); @Deprecated static B foldl(Collection<A> as, B start, Function2<B, A, B> f); @Deprecated static Collection<B> map(Collection<A> as, Function<A, B> f); @Deprecated static Collection<B> flatMap(Collection<A> as, Function<A, Collection<B>> f); @Deprecated static M flatMap(Collection<A> as, M bs, Function<A, Collection<B>> f); @Deprecated static Option<A> find(Collection<A> as, Predicate<A> p); @Deprecated static boolean exists(Collection<A> as, Predicate<A> p); @Deprecated static M filter(M as, Predicate<A> p); static Option<A> head(List<A> as); static String mkString(Collection<?> as, String sep); static T appendTo(T target, S as); @SafeVarargs static T appendToM(T target, S... as); @SafeVarargs static T appendToA(T target, X... as); static List<A> concat(M as, M bs); static Map<A, B> merge(Map<? extends A, ? extends B> a, Map<? extends A, ? extends B> b); static List<A> toList(Iterator<? extends A> as); static List<A> toList(Collection<A> as); @Deprecated static List<A> mkList(List<A> as); static List<A> nullToNil(List<A> as); @SafeVarargs static List<A> list(A... as); @SafeVarargs static List<A> nonNullList(A... as); @SuppressWarnings("unchecked") static List<A> nil(); @SuppressWarnings("unchecked") static List<A> nil(Class<A> type); static List<A> cons(A a, List<? extends A> as); @SafeVarargs static Set<A> set(A... as); static Set<A> toSet(List<A> as); @SafeVarargs static Map<K, V> map(Tuple<? extends K, ? extends V>... ts); @SafeVarargs static Dictionary<K, V> dict(Tuple<? extends K, ? extends V>... ts); @SuppressWarnings("unchecked") static A[] toArray(Class<A> elemType, Collection<B> a); static double[] toDoubleArray(Collection<Double> as); @SafeVarargs static Iterator<A> iterator(final A... as); static Iterator<A> repeat(final X a, final int times); static Iterator<A> join(final Iterator<A> a, final Iterator<A> b); static Iterable<A> forc(final Iterator<A> as); static List<A> concat(M as); }
Collections { public static <A> Option<A> head(List<A> as) { if (!as.isEmpty()) { return some(as.get(0)); } else { return Option.none(); } } private  Collections(); @Deprecated static M map(Collection<A> as, M bs, Function<A, B> f); @Deprecated static B foldl(Collection<A> as, B start, Function2<B, A, B> f); @Deprecated static Collection<B> map(Collection<A> as, Function<A, B> f); @Deprecated static Collection<B> flatMap(Collection<A> as, Function<A, Collection<B>> f); @Deprecated static M flatMap(Collection<A> as, M bs, Function<A, Collection<B>> f); @Deprecated static Option<A> find(Collection<A> as, Predicate<A> p); @Deprecated static boolean exists(Collection<A> as, Predicate<A> p); @Deprecated static M filter(M as, Predicate<A> p); static Option<A> head(List<A> as); static String mkString(Collection<?> as, String sep); static T appendTo(T target, S as); @SafeVarargs static T appendToM(T target, S... as); @SafeVarargs static T appendToA(T target, X... as); static List<A> concat(M as, M bs); static Map<A, B> merge(Map<? extends A, ? extends B> a, Map<? extends A, ? extends B> b); static List<A> toList(Iterator<? extends A> as); static List<A> toList(Collection<A> as); @Deprecated static List<A> mkList(List<A> as); static List<A> nullToNil(List<A> as); @SafeVarargs static List<A> list(A... as); @SafeVarargs static List<A> nonNullList(A... as); @SuppressWarnings("unchecked") static List<A> nil(); @SuppressWarnings("unchecked") static List<A> nil(Class<A> type); static List<A> cons(A a, List<? extends A> as); @SafeVarargs static Set<A> set(A... as); static Set<A> toSet(List<A> as); @SafeVarargs static Map<K, V> map(Tuple<? extends K, ? extends V>... ts); @SafeVarargs static Dictionary<K, V> dict(Tuple<? extends K, ? extends V>... ts); @SuppressWarnings("unchecked") static A[] toArray(Class<A> elemType, Collection<B> a); static double[] toDoubleArray(Collection<Double> as); @SafeVarargs static Iterator<A> iterator(final A... as); static Iterator<A> repeat(final X a, final int times); static Iterator<A> join(final Iterator<A> a, final Iterator<A> b); static Iterable<A> forc(final Iterator<A> as); static List<A> concat(M as);  }