final case classOneAnd[F[_], A](head: A, tail: F[A]) extends Product with Serializable
A generalization of NonEmptyList to non-List things. For
example, OneAnd[Vector, A] is a non-empty Vector of A.
Only head and tail are provided as direct methods, because
there's little you can do with a OneAnd without knowing a bit
about F. So useful functions are provided in the form of
typeclass instances on OneAnd's companion; in combination with
syntax extensions provided by scalaz.syntax, OneAnd has a
large possible set of methods available by importing. For
example, Applicative on this requires ApplicativePlus[F], and
Traverse1 on this requires Traverse[F]. See the companion
documentation for a complete list of instances.
Additionally, unlike λ[α => (α, F[α])], the behavior of typeclass
operations on OneAnd should be preserved across the natural
transformation to scalaz.NonEmptyList where one exists. That
is it should "be like" a nonempty structure. For example,
ap-ing two OneAnd[Vector, ?]s or NonEmptyLists of lengths
*a* and *b* yields a sequence of same type of length *a*×*b*, but
two λ[α => (α, Vector[α])]s of length *c* and *d* ap to one of
length 1+(*c*–1)×(*d*–1). For another example, point of the
former two yield a one-element sequence, but point of the latter
yields a two-element sequence.
A generalization of
NonEmptyList
to non-List
things. For example,OneAnd[Vector, A]
is a non-emptyVector
ofA
.Only
head
andtail
are provided as direct methods, because there's little you can do with aOneAnd
without knowing a bit aboutF
. So useful functions are provided in the form of typeclass instances onOneAnd
's companion; in combination with syntax extensions provided byscalaz.syntax
,OneAnd
has a large possible set of methods available by importing. For example,Applicative
on this requiresApplicativePlus[F]
, andTraverse1
on this requiresTraverse[F]
. See the companion documentation for a complete list of instances.Additionally, unlike
λ[α => (α, F[α])]
, the behavior of typeclass operations onOneAnd
should be preserved across the natural transformation to scalaz.NonEmptyList where one exists. That is it should "be like" a nonempty structure. For example,ap
-ing twoOneAnd[Vector, ?]
s orNonEmptyList
s of lengths *a* and *b* yields a sequence of same type of length *a*×*b*, but twoλ[α => (α, Vector[α])]
s of length *c* and *d*ap
to one of length 1+(*c*–1)×(*d*–1). For another example,point
of the former two yield a one-element sequence, butpoint
of the latter yields a two-element sequence.7.0.3