NonEmptyBatch

indigo.shared.collections.NonEmptyBatch
See theNonEmptyBatch companion object
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.

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: NonEmptyBatch[A]): NonEmptyBatch[A]

Concatenate two NonEmptyBatch's together

Concatenate two NonEmptyBatch's together

Value parameters

other

A second NonEmptyBatch of the same type

Attributes

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

Attributes

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

Attributes

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

Attributes

Returns

NonEmptyBatch[A]

override def equals(that: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if the receiver object is equivalent to the argument; false otherwise.

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

Attributes

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

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 => 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

Attributes

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

Attributes

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

Attributes

Returns

Boolean

def last: A

Returns the last element in the batch

Returns the last element in the batch

Attributes

Returns

A

def length: Int

A count of the elements in the batch

A count of the elements in the batch

Attributes

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

Attributes

Returns

A NonEmptyBatch of a potentially different type

Example

NonEmptyBatch(1, 2, 3).map(_ * 10) results in NonEmptyBatch(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 batch into a String

Converts the batch into a String

Value parameters

separator

A string to add between the elements

Attributes

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

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

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

Reverse the order of the batch

Reverse the order of the batch

Attributes

Returns

NonEmptyBatch[A]

def size: Int

A count of the elements in the batch

A count of the elements in the batch

Attributes

Returns

Int

def toBatch: Batch[A]

Converts the NonEmptyBatch back to a regular Batch.

Converts the NonEmptyBatch back to a regular Batch.

Attributes

def toList: List[A]

Converts the NonEmptyBatch back to a List.

Converts the NonEmptyBatch back to a 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: 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.

Attributes

Returns

NonEmptyBatch[(A, B)]

Example

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

def zipWithIndex: NonEmptyBatch[(A, Int)]

Attributes

Example

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

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product