Class NonEmptyList<A>

java.lang.Object
ch.bluecare.commons.data.NonEmptyList<A>
All Implemented Interfaces:
Iterable<A>, IntFunction<A>

public final class NonEmptyList<A> extends Object implements Iterable<A>, IntFunction<A>
A PList that has at least one element.
  • Constructor Details

    • NonEmptyList

      public NonEmptyList(A head, PList<A> tail)
  • Method Details

    • of

      public static <A> NonEmptyList<A> of(A first, A... other)
    • single

      public static <A> NonEmptyList<A> single(A el)
      Creates a single-element list.
    • fromIter

      public static <A> Optional<NonEmptyList<A>> fromIter(Iterable<A> iter)
      Create a non-empty list from a given iterable. Use the various constructors on PList to create iterables from other values.
    • head

      public A head()
      Return the head of this list.
    • tail

      public PList<A> tail()
      Return the tail of this list.
    • concat

      public NonEmptyList<A> concat(Iterable<A> next)
      Appends an iterable to this list.
    • cons

      public NonEmptyList<A> cons(A el)
      Prepend the given element to this list.
    • add

      public NonEmptyList<A> add(A element)
      Create a new list by adding element to the tail of this list, i. e. the head of the list remains the same. Use this method carefully as it is expensive, use PList.cons(Object) if possible.
    • map

      public <B> NonEmptyList<B> map(Function<A,B> f)
      Map the given function across this list.
    • flatMap

      public <B> NonEmptyList<B> flatMap(Function<A,NonEmptyList<B>> f)
      Apply the function to every element and flatten the results.
    • reduce

      public A reduce(BinaryOperator<A> f)
      Reduces this list to a single value using the merge function f.
    • reverse

      public NonEmptyList<A> reverse()
      Reverses this list.
    • sort

      public NonEmptyList<A> sort(Comparator<A> comparator)
      Sorts this list according to the given comparator.
    • size

      public int size()
    • toPList

      public PList<A> toPList()
      Convert this to a PList which will be non-empty.
    • zipWithIndex

      public NonEmptyList<Pair<A,Integer>> zipWithIndex()
    • apply

      public A apply(int value)
      Specified by:
      apply in interface IntFunction<A>
    • iterator

      public Iterator<A> iterator()
      Specified by:
      iterator in interface Iterable<A>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object