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 Params
- A
The type of element to be stored in the list.
- Companion
- object
Value members
Concrete methods
Concatenate two NonEmptyList
's together
Concatenate two NonEmptyList
's together
- Value Params
- other
A second NonEmptyList of the same type
- Returns
A new NonEmptyList containing the elements of both lists
Concatenate a NonEmptyList
with a List
Concatenate a NonEmptyList
with a List
- Value Params
- other
A List of the same type
- Returns
A new NonEmptyList containing the elements of both lists
Append an element
Append an element
- Value Params
- next
The next element of the same type
- Returns
NonEmptyList[A]
Prepend an element
Prepend an element
- Value Params
- first
The new head element of the same type
- Returns
NonEmptyList[A]
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 Params
- p
Predicate function
- Returns
Boolean
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 Params
- p
Predicate, returns the first elements for which this predicate holds true
- Returns
Optional A, if no match can be found None is returned.
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 Params
- B
Resultant type of the new NonEmptyList
- Value Params
- f
function to apply to each element
- Returns
A NonEmptyList of a potentially different type
- Example
NonEmptyList(1, 2, 3).flatMap(i => NonEmptyList(i * 10))
results inNonEmptyList(10, 20, 30)
foldLeft
differs from reduce it two important ways:
foldLeft
differs from reduce it two important ways:
- It has an initial value onto which all other values are applied
- It does not require the result type to be the same as the list type.
- Type Params
- Z
The accumulator type
- Value Params
- acc
The initial accumulator value to accumulate against
- f
A function for combining the accumulator and the next value
- Returns
the final accumulated value
- Example
NonEmptyList(1, 2, 3)("")((a, b) => a + b) results in "123"
Checks that a predicate holds for all elements
Checks that a predicate holds for all elements
- Value Params
- p
Predicate function
- Returns
Boolean
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 Params
- B
Resultant type of the new NonEmptyList
- Value Params
- f
function to apply to each element
- Returns
A NonEmptyList of a potentially different type
- Example
NonEmptyList(1, 2, 3).map(_ * 10)
results inNonEmptyList(10, 20, 30)
Delegates to mkString(separator: String): String
Delegates to mkString(separator: String): String
- Returns
String
Converts the list into a String
Converts the list into a String
- Value Params
- separator
A string to add between the elements
- Returns
String
- Value Params
- f
a function for combining to
A
's into a singleA
- Returns
The final
A
value- Example
NonEmptyList(1, 2, 3)((a, b) => a + b) results in 6
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 Params
- B
The type of the second NonEmptyList
- Value Params
- other
The second NonEmptyList to zip with.
- Returns
NonEmptyList[(A, B)]
- Example
NonEmptyList("a", "b", "c").zip(NonEmptyList(1, 2, 3))
results inNonEmptyList(("a", 1), ("b", 2), ("c", 3))