VectorOps

cats.syntax.VectorOps
final class VectorOps[A](va: Vector[A]) extends AnyVal

Attributes

Source
vector.scala
Graph
Supertypes
class AnyVal
trait Matchable
class Any

Members list

Value members

Concrete methods

def groupByNev[B](f: A => B)(implicit B: Order[B]): SortedMap[B, NonEmptyVector[A]]

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

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

scala> import cats.data.NonEmptyVector
scala> import scala.collection.immutable.SortedMap
scala> import cats.syntax.all._

scala> val vector = Vector(12, -2, 3, -5)

scala> val expectedResult = SortedMap(false -> NonEmptyVector.of(-2, -5), true -> NonEmptyVector.of(12, 3))

scala> vector.groupByNev(_ >= 0) === expectedResult
res0: Boolean = true

Attributes

Source
vector.scala
def groupByNevA[F[_], B](f: A => F[B])(implicit F: Applicative[F], B: Order[B]): F[SortedMap[B, NonEmptyVector[A]]]

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

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

scala> import cats.data.NonEmptyVector
scala> import scala.collection.immutable.SortedMap
scala> import cats.syntax.all._

scala> val vector = Vector(12, -2, 3, -5)

scala> val expectedResult = Option(SortedMap(false -> NonEmptyVector.of(-2, -5), true -> NonEmptyVector.of(12, 3)))

scala> vector.groupByNevA(num => Option(0).map(num >= _)) === expectedResult
res0: Boolean = true

Attributes

Source
vector.scala
def scanLeftNev[B](b: B)(f: (B, A) => B): NonEmptyVector[B]

Produces a NonEmptyVector containing cumulative results of applying the operator going left to right.

Produces a NonEmptyVector containing cumulative results of applying the operator going left to right.

Example:

scala> import cats.data.NonEmptyVector
scala> import cats.syntax.all._

scala> val result1: Vector[Int] = Vector(1, 2)
scala> result1.scanLeftNev(100)(_ + _)
res0: NonEmptyVector[Int] = NonEmptyVector(100, 101, 103)

scala> val result2: Vector[Int] = Vector.empty[Int]
scala> result2.scanLeftNev(1)(_ + _)
res1: NonEmptyVector[Int] = NonEmptyVector(1)

Attributes

Source
vector.scala
def scanRightNev[B](b: B)(f: (A, B) => B): NonEmptyVector[B]

Produces a NonEmptyVector containing cumulative results of applying the operator going right to left.

Produces a NonEmptyVector containing cumulative results of applying the operator going right to left.

Example:

scala> import cats.data.NonEmptyVector
scala> import cats.syntax.all._

scala> val result1: Vector[Int] = Vector(1, 2)
scala> result1.scanRightNev(100)(_ + _)
res0: NonEmptyVector[Int] = NonEmptyVector(103, 102, 100)

scala> val result2: Vector[Int] = Vector.empty[Int]
scala> result2.scanRightNev(1)(_ + _)
res1: NonEmptyVector[Int] = NonEmptyVector(1)

Attributes

Source
vector.scala

Returns an Option of NonEmptyVector from a Vector

Returns an Option of NonEmptyVector from a Vector

Example:

scala> import cats.data.NonEmptyVector
scala> import cats.syntax.all._

scala> val result1: Vector[Int] = Vector(1, 2)
scala> result1.toNev
res0: Option[NonEmptyVector[Int]] = Some(NonEmptyVector(1, 2))

scala> val result2: Vector[Int] = Vector.empty[Int]
scala> result2.toNev
res1: Option[NonEmptyVector[Int]] = None

Attributes

Source
vector.scala