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 Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
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
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
Append an element
Append an element
Value parameters
- next
-
The next element of the same type
Attributes
- Returns
-
NonEmptyList[A]
Prepend an element
Prepend an element
Value parameters
- first
-
The new head element of the same type
Attributes
- 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 parameters
- p
-
Predicate function
Attributes
- 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 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.
Alias for head
Alias for head
Attributes
- Returns
-
A
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 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 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"
Checks that a predicate holds for all elements
Checks that a predicate holds for all elements
Value parameters
- p
-
Predicate function
Attributes
- Returns
-
Boolean
Returns the last element in the list
Returns the last element in the list
Attributes
- Returns
-
A
A count of the elements in the list
A count of the elements in the list
Attributes
- Returns
-
Int
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 inNonEmptyList(10, 20, 30)
Delegates to mkString(separator: String): String
Delegates to mkString(separator: String): String
Attributes
- Returns
-
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
Value parameters
- f
-
a function for combining to
A
's into a singleA
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]
Converts the NonEmptyList back to a regular Batch.
Converts the NonEmptyList back to a regular Batch.
Attributes
Converts the NonEmptyList back to a regular List.
Converts the NonEmptyList back to a regular List.
Attributes
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
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 inNonEmptyList(("a", 1), ("b", 2), ("c", 3))
Attributes
- Example
-
NonEmptyList("a", "b", "c").zipWithIndex
results inNonEmptyList(("a", 0), ("b", 1), ("c",2))
Inherited methods
Attributes
- Inherited from:
- Product
Attributes
- Inherited from:
- Product