Packages

sealed abstract class Chain[+A] extends ChainCompat[A]

Trivial catenable sequence. Supports O(1) append, and (amortized) O(1) uncons, such that walking the sequence via N successive uncons steps takes O(N).

Source
Chain.scala
Linear Supertypes
ChainCompat[A], AnyRef, Any
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Chain
  2. ChainCompat
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ++[A2 >: A](c: Chain[A2]): Chain[A2]

    Alias for concat

  4. final def +:[A2 >: A](a: A2): Chain[A2]

    Alias for prepend.

  5. final def :+[A2 >: A](a: A2): Chain[A2]

    Alias for append.

  6. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  7. def ===[AA >: A](that: Chain[AA])(implicit A: Eq[AA]): Boolean

    Typesafe equality operator.

    Typesafe equality operator.

    This method is similar to == except that it only allows two Chain[A] values to be compared to each other, and uses equality provided by Eq[_] instances, rather than using the universal equality provided by .equals.

  8. final def append[A2 >: A](a: A2): Chain[A2]

    Returns a new Chain consisting of this followed by a.

    Returns a new Chain consisting of this followed by a. O(1) runtime.

  9. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  10. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  11. final def collect[B](pf: PartialFunction[A, B]): Chain[B]

    Collect B from this for which f is defined

  12. final def collectFirst[B](pf: PartialFunction[A, B]): Option[B]

    Finds the first element of this Chain for which the given partial function is defined, and applies the partial function to it.

  13. final def collectFirstSome[B](f: (A) => Option[B]): Option[B]

    Like collectFirst from scala.collection.Traversable but takes A => Option[B] instead of PartialFunctions.

  14. final def concat[A2 >: A](c: Chain[A2]): Chain[A2]

    Concatenates this with c in O(1) runtime.

  15. final def contains[AA >: A](a: AA)(implicit A: Eq[AA]): Boolean

    Check whether an element is in this structure

  16. final def deleteFirst(f: (A) => Boolean): Option[(A, Chain[A])]

    Yields to Some(a, Chain[A]) with a removed where f holds for the first time, otherwise yields None, if a was not found Traverses only until a is found.

  17. def distinct[AA >: A](implicit O: Order[AA]): Chain[AA]

    Remove duplicates.

    Remove duplicates. Duplicates are checked using Order[_] instance.

    Example:

    scala> import cats.data.Chain
    scala> val chain = Chain(1, 2, 2, 3)
    scala> chain.distinct
    res0: cats.data.Chain[Int] = Chain(1, 2, 3)
  18. def distinctBy[B](f: (A) => B)(implicit O: Order[B]): Chain[A]

    Remove duplicates by a predicate.

    Remove duplicates by a predicate. Duplicates are checked using Order[_] instance.

    Example:

    scala> import cats.data.Chain
    scala> val chain = Chain(1, 2, 3, 4)
    scala> chain.distinctBy(_ / 2)
    res0: cats.data.Chain[Int] = Chain(1, 2, 4)
  19. final def dropWhile(p: (A) => Boolean): Chain[A]

    Drops longest prefix of elements that satisfy a predicate.

    Drops longest prefix of elements that satisfy a predicate.

    p

    The predicate used to test elements.

    returns

    the longest suffix of this sequence whose first element does not satisfy the predicate p.

  20. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. def equals(o: Any): Boolean
    Definition Classes
    Chain → AnyRef → Any
  22. final def exists(f: (A) => Boolean): Boolean

    Check whether at least one element satisfies the predicate

  23. final def filter(f: (A) => Boolean): Chain[A]

    Remove elements not matching the predicate

  24. final def filterNot(f: (A) => Boolean): Chain[A]

    Remove elements matching the predicate

  25. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  26. final def find(f: (A) => Boolean): Option[A]

    Find the first element matching the predicate, if one exists

  27. final def flatMap[B](f: (A) => Chain[B]): Chain[B]

    Applies the supplied function to each element and returns a new Chain from the concatenated results

  28. final def foldLeft[B](z: B)(f: (B, A) => B): B

    Folds over the elements from left to right using the supplied initial value and function.

  29. final def foldRight[B](z: B)(f: (A, B) => B): B

    Folds over the elements from right to left using the supplied initial value and function.

  30. final def forall(f: (A) => Boolean): Boolean

    Check whether all elements satisfy the predicate

  31. final def get(idx: Long): Option[A]
  32. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  33. final def groupBy[B](f: (A) => B)(implicit B: Order[B]): SortedMap[B, NonEmptyChain[A]]

    Groups elements inside this Chain according to the Order of the keys produced by the given mapping function.

    Groups elements inside this Chain according to the Order of the keys produced by the given mapping function.

    scala> import scala.collection.immutable.SortedMap
    scala> import cats.data.{Chain, NonEmptyChain}
    scala> import cats.syntax.all._
    scala> val chain = Chain(12, -2, 3, -5)
    scala> val expectedResult = SortedMap(false -> NonEmptyChain(-2, -5), true -> NonEmptyChain(12, 3))
    scala> val result = chain.groupBy(_ >= 0)
    scala> result === expectedResult
    res0: Boolean = true
  34. final def groupMap[K, B](key: (A) => K)(f: (A) => B)(implicit K: Order[K]): SortedMap[K, NonEmptyChain[B]]

    Groups elements inside this Chain according to the Order of the keys produced by the given key function.

    Groups elements inside this Chain according to the Order of the keys produced by the given key function. And each element in a group is transformed into a value of type B using the mapping function.

    scala> import scala.collection.immutable.SortedMap
    scala> import cats.data.{Chain, NonEmptyChain}
    scala> import cats.syntax.all._
    scala> val chain = Chain(12, -2, 3, -5)
    scala> val expectedResult = SortedMap(false -> NonEmptyChain("-2", "-5"), true -> NonEmptyChain("12", "3"))
    scala> val result = chain.groupMap(_ >= 0)(_.toString)
    scala> result === expectedResult
    res0: Boolean = true
  35. final def groupMapReduce[K, B](key: (A) => K)(f: (A) => B)(implicit K: Order[K], S: Semigroup[B]): SortedMap[K, B]

    Groups elements inside this Chain according to the Order of the keys produced by the given key function.

    Groups elements inside this Chain according to the Order of the keys produced by the given key function. Then each element in a group is transformed into a value of type B using the mapping function. And finally they are all reduced into a single value using their Semigroup

    scala> import scala.collection.immutable.SortedMap
    scala> import cats.data.Chain
    scala> import cats.syntax.all._
    scala> val chain = Chain("Hello", "World", "Goodbye", "World")
    scala> val expectedResult = SortedMap("goodbye" -> 1, "hello" -> 1, "world" -> 2)
    scala> val result = chain.groupMapReduce(_.trim.toLowerCase)(_ => 1)
    scala> result === expectedResult
    res0: Boolean = true
  36. final def groupMapReduceWith[K, B](key: (A) => K)(f: (A) => B)(combine: (B, B) => B)(implicit K: Order[K]): SortedMap[K, B]

    Groups elements inside this Chain according to the Order of the keys produced by the given key function.

    Groups elements inside this Chain according to the Order of the keys produced by the given key function. Then each element in a group is transformed into a value of type B using the mapping function. And finally they are all reduced into a single value using the provided combine function.

    scala> import scala.collection.immutable.SortedMap
    scala> import cats.data.Chain
    scala> import cats.syntax.all._
    scala> val chain = Chain("Hello", "World", "Goodbye", "World")
    scala> val expectedResult = SortedMap("goodbye" -> 1, "hello" -> 1, "world" -> 2)
    scala> val result = chain.groupMapReduceWith(_.trim.toLowerCase)(_ => 1)(_ + _)
    scala> result === expectedResult
    res0: Boolean = true
  37. def hash[AA >: A](implicit hashA: Hash[AA]): Int
  38. def hashCode(): Int
    Definition Classes
    Chain → AnyRef → Any
  39. def headOption: Option[A]

    Returns the head of this Chain if non empty, none otherwise.

    Returns the head of this Chain if non empty, none otherwise. Amortized O(1).

  40. final def initLast: Option[(Chain[A], A)]

    Returns the init and last of this Chain if non empty, none otherwise.

    Returns the init and last of this Chain if non empty, none otherwise. Amortized O(1).

  41. def isEmpty: Boolean

    Returns true if there are no elements in this collection.

  42. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  43. final def iterator: Iterator[A]
  44. final def knownSize: Long

    The number of elements in this chain, if it can be cheaply computed, -1 otherwise.

    The number of elements in this chain, if it can be cheaply computed, -1 otherwise. Cheaply usually means: Not requiring a collection traversal.

    Definition Classes
    ChainCompat
  45. final def lastOption: Option[A]

    Returns the last of this Chain if non empty, none otherwise.

    Returns the last of this Chain if non empty, none otherwise. Amortized O(1).

  46. final def length: Long

    Returns the number of elements in this structure

  47. final def lengthCompare(len: Long): Int

    Compares the length of this chain to a test value.

    Compares the length of this chain to a test value.

    The method does not call length directly; its running time is O(length min len) instead of O(length).

    len

    the test value that gets compared with the length.

    returns

    a negative value if this.length < len, zero if this.length == len or a positive value if this.length > len.

    Note

    an adapted version of Iterable#sizeCompare from Scala Library v2.13.10 is used in a part of the implementation.

    scala> import cats.data.Chain
    scala> val chain = Chain(1, 2, 3)
    scala> val isLessThan4 = chain.lengthCompare(4) < 0
    scala> val isEqualTo3 = chain.lengthCompare(3) == 0
    scala> val isGreaterThan2 = chain.lengthCompare(2) > 0
    scala> isLessThan4 && isEqualTo3 && isGreaterThan2
    res0: Boolean = true
  48. final def map[B](f: (A) => B): Chain[B]

    Applies the supplied function to each element and returns a new Chain.

  49. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  50. final def nonEmpty: Boolean

    Returns false if there are no elements in this collection.

  51. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  52. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  53. final def prepend[A2 >: A](a: A2): Chain[A2]

    Returns a new Chain consisting of a followed by this.

    Returns a new Chain consisting of a followed by this. O(1) runtime.

  54. def reverse: Chain[A]

    Reverses this Chain

  55. final def reverseIterator: Iterator[A]
  56. def show[AA >: A](implicit AA: Show[AA]): String
  57. final def size: Long

    Alias for length

  58. final def sizeCompare(size: Long): Int

    Alias for lengthCompare

  59. final def sortBy[B](f: (A) => B)(implicit B: Order[B]): Chain[A]
  60. final def sorted[AA >: A](implicit AA: Order[AA]): Chain[AA]
  61. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  62. final def takeWhile(p: (A) => Boolean): Chain[A]

    Takes longest prefix of elements that satisfy a predicate.

    Takes longest prefix of elements that satisfy a predicate.

    p

    The predicate used to test elements.

    returns

    the longest prefix of this chain whose elements all satisfy the predicate p.

  63. final def toList: List[A]

    Converts to a list.

  64. def toString(): String
    Definition Classes
    Chain → AnyRef → Any
  65. final def toVector: Vector[A]

    Converts to a vector.

  66. final def uncons: Option[(A, Chain[A])]

    Returns the head and tail of this Chain if non empty, none otherwise.

    Returns the head and tail of this Chain if non empty, none otherwise. Amortized O(1).

  67. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  68. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  69. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  70. final def zipWith[B, C](other: Chain[B])(f: (A, B) => C): Chain[C]

    Zips this Chain with another Chain and applies a function for each pair of elements.

  71. final def zipWithIndex: Chain[(A, Int)]

    Zips each element of this Chain with its index.

Inherited from ChainCompat[A]

Inherited from AnyRef

Inherited from Any

Ungrouped