NonEmptyList

indigo.shared.collections.NonEmptyList
See theNonEmptyList companion object
final case class NonEmptyList[A](head: A, tail: List[A])

An ordered list-type object that requires there to always be at least one element present, ruling out the possibility of unsafely accessing the head element.

Type parameters

A

The type of element to be stored in the list.

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def ++(other: NonEmptyList[A]): NonEmptyList[A]

Concatenate two NonEmptyList's together

Concatenate two NonEmptyList's together

Value parameters

other

A second NonEmptyList of the same type

Attributes

Returns

A new NonEmptyList containing the elements of both lists

def ++(other: List[A]): NonEmptyList[A]

Concatenate a NonEmptyList with a List

Concatenate a NonEmptyList with a List

Value parameters

other

A List of the same type

Attributes

Returns

A new NonEmptyList containing the elements of both lists

def :+(next: A): NonEmptyList[A]

Append an element

Append an element

Value parameters

next

The next element of the same type

Attributes

Returns

NonEmptyList[A]

def ::(first: A): NonEmptyList[A]

Prepend an element

Prepend an element

Value parameters

first

The new head element of the same type

Attributes

Returns

NonEmptyList[A]

def exists(p: A => Boolean): Boolean

List find, but only returns a Boolean indicating if an element matching the predicate was found.

List find, but only returns a Boolean indicating if an element matching the predicate was found.

Value parameters

p

Predicate function

Attributes

Returns

Boolean

def find(p: A => Boolean): Option[A]

Search the NonEmptyList using a predicate and return the first element that matches

Search the NonEmptyList using a predicate and return the first element that matches

Value parameters

p

Predicate, returns the first elements for which this predicate holds true

Attributes

Returns

Optional A, if no match can be found None is returned.

def first: A

Alias for head

Alias for head

Attributes

Returns

A

def flatMap[B](f: A => NonEmptyList[B]): NonEmptyList[B]

Apply a function f to each element of the list to produce a new list. Differs from map because f produces another NonEmptyList, which is then flattened. Useful in monadic comprehensions.

Apply a function f to each element of the list to produce a new list. Differs from map because f produces another NonEmptyList, which is then flattened. Useful in monadic comprehensions.

Type parameters

B

Resultant type of the new NonEmptyList

Value parameters

f

function to apply to each element

Attributes

Returns

A NonEmptyList of a potentially different type

Example

NonEmptyList(1, 2, 3).flatMap(i => NonEmptyList(i * 10)) results in NonEmptyList(10, 20, 30)

def foldLeft[Z](acc: Z)(f: (Z, A) => Z): Z

foldLeft differs from reduce it two important ways:

foldLeft differs from reduce it two important ways:

  1. It has an initial value onto which all other values are applied
  2. It does not require the result type to be the same as the list type.

Type parameters

Z

The accumulator type

Value parameters

acc

The initial accumulator value to accumulate against

f

A function for combining the accumulator and the next value

Attributes

Returns

the final accumulated value

Example

NonEmptyList(1, 2, 3)("")((a, b) => a + b) results in "123"

def forall(p: A => Boolean): Boolean

Checks that a predicate holds for all elements

Checks that a predicate holds for all elements

Value parameters

p

Predicate function

Attributes

Returns

Boolean

def last: A

Returns the last element in the list

Returns the last element in the list

Attributes

Returns

A

def length: Int

A count of the elements in the list

A count of the elements in the list

Attributes

Returns

Int

def map[B](f: A => B): NonEmptyList[B]

Apply a function f to each element of the list to produce a new list.

Apply a function f to each element of the list to produce a new list.

Type parameters

B

Resultant type of the new NonEmptyList

Value parameters

f

function to apply to each element

Attributes

Returns

A NonEmptyList of a potentially different type

Example

NonEmptyList(1, 2, 3).map(_ * 10) results in NonEmptyList(10, 20, 30)

def mkString: String

Delegates to mkString(separator: String): String

Delegates to mkString(separator: String): String

Attributes

Returns

String

def mkString(separator: String): String

Converts the list into a String

Converts the list into a String

Value parameters

separator

A string to add between the elements

Attributes

Returns

String

def reduce(f: (A, A) => A): A

Value parameters

f

a function for combining to A's into a single A

Attributes

Returns

The final A value

Example

NonEmptyList(1, 2, 3)((a, b) => a + b) results in 6

Reverse the order of the list

Reverse the order of the list

Attributes

Returns

NonEmptyList[A]

def toBatch: Batch[A]

Converts the NonEmptyList back to a regular Batch.

Converts the NonEmptyList back to a regular Batch.

Attributes

def toList: List[A]

Converts the NonEmptyList back to a regular List.

Converts the NonEmptyList back to a regular List.

Attributes

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
def zip[B](other: NonEmptyList[B]): NonEmptyList[(A, B)]

Takes two NonEmptyLists and creates a new NonEmptyList of the elements of both inputs tupled together.

Takes two NonEmptyLists and creates a new NonEmptyList of the elements of both inputs tupled together.

Type parameters

B

The type of the second NonEmptyList

Value parameters

other

The second NonEmptyList to zip with.

Attributes

Returns

NonEmptyList[(A, B)]

Example

NonEmptyList("a", "b", "c").zip(NonEmptyList(1, 2, 3)) results in NonEmptyList(("a", 1), ("b", 2), ("c", 3))

def zipWithIndex: NonEmptyList[(A, Int)]

Attributes

Example

NonEmptyList("a", "b", "c").zipWithIndex results in NonEmptyList(("a", 0), ("b", 1), ("c",2))

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product