NonEmptyBatch

final case class NonEmptyBatch[A](head: A, tail: Batch[A])

An ordered batch-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 batch.

Companion:
object
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any

Value members

Concrete methods

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

Concatenate two NonEmptyBatch's together

Concatenate two NonEmptyBatch's together

Value parameters:
other

A second NonEmptyBatch of the same type

Returns:

A new NonEmptyBatch containing the elements of both lists

def ++(other: Batch[A]): NonEmptyBatch[A]

Concatenate a NonEmptyBatch with a Batch

Concatenate a NonEmptyBatch with a Batch

Value parameters:
other

A Batch of the same type

Returns:

A new NonEmptyBatch containing the elements of both lists

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

Append an element

Append an element

Value parameters:
next

The next element of the same type

Returns:

NonEmptyBatch[A]

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

Prepend an element

Prepend an element

Value parameters:
first

The new head element of the same type

Returns:

NonEmptyBatch[A]

override def equals(that: Any): Boolean
Definition Classes
Equals -> Any
def exists(p: A => Boolean): Boolean

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

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

Value parameters:
p

Predicate function

Returns:

Boolean

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

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

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

Value parameters:
p

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

Returns:

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

def first: A

Alias for head

Alias for head

Returns:

A

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

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

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

Type parameters:
B

Resultant type of the new NonEmptyBatch

Value parameters:
f

function to apply to each element

Returns:

A NonEmptyBatch of a potentially different type

Example:

NonEmptyBatch(1, 2, 3).flatMap(i => NonEmptyBatch(i * 10)) results in NonEmptyBatch(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 batch 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

Returns:

the final accumulated value

Example:

NonEmptyBatch(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

Returns:

Boolean

def last: A

Returns the last element in the batch

Returns the last element in the batch

Returns:

A

def length: Int

A count of the elements in the batch

A count of the elements in the batch

Returns:

Int

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

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

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

Type parameters:
B

Resultant type of the new NonEmptyBatch

Value parameters:
f

function to apply to each element

Returns:

A NonEmptyBatch of a potentially different type

Example:

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

Delegates to mkString(separator: String): String

Delegates to mkString(separator: String): String

Returns:

String

def mkString(separator: String): String

Converts the batch into a String

Converts the batch into a String

Value parameters:
separator

A string to add between the elements

Returns:

String

def mkString(prefix: String, separator: String, suffix: String): String

Converts the batch into a String

Converts the batch into a String

Value parameters:
prefix

A string to add before the elements

separator

A string to add between the elements

suffix

A string to add after the elements

Returns:

String

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

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

Returns:

The final A value

Example:

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

Reverse the order of the batch

Reverse the order of the batch

Returns:

NonEmptyBatch[A]

def size: Int

A count of the elements in the batch

A count of the elements in the batch

Returns:

Int

def toBatch: Batch[A]

Converts the NonEmptyBatch back to a regular Batch.

Converts the NonEmptyBatch back to a regular Batch.

def toList: List[A]

Converts the NonEmptyBatch back to a List.

Converts the NonEmptyBatch back to a List.

override def toString: String
Definition Classes
Any
def zip[B](other: NonEmptyBatch[B]): NonEmptyBatch[(A, B)]

Takes two NonEmptyBatchs and creates a new NonEmptyBatch of the elements of both inputs tupled together.

Takes two NonEmptyBatchs and creates a new NonEmptyBatch of the elements of both inputs tupled together.

Type parameters:
B

The type of the second NonEmptyBatch

Value parameters:
other

The second NonEmptyBatch to zip with.

Returns:

NonEmptyBatch[(A, B)]

Example:

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

Example:

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

Inherited methods

Inherited from:
Product