package nonempty
- Alphabetic
- By Inheritance
- nonempty
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- type NonEmpty[+A] = nonempty.NonEmptyColl.NonEmpty[A]
A non-empty
A
.A non-empty
A
. Implicitly converts toA
in relevant contexts.Why use this instead of scalaz.OneAnd?
OneAnd
is constructively non-empty; there is no way to "cheat". However, its focus on functorial use cases means that it is well-suited for uninterpreted sequences like List and Vector, but less so those where parts of the elements have some semantics, such as with Map and Set. For cases like Set you also have to do some extra work to make sure thehead
doesn't break the invariant of the underlying structure.By contrast,
NonEmpty
is nominally non-empty. We take care to define only those primitives that will preserve non-emptiness, but it is possible to make a mistake (for example, if you added flatMap but wrote the wrong signature). The benefits are that you get to treat them more like the underlying structure, because there is no structural difference, and operations on existing code will more transparently continue to work (and preserve the non-empty property where reasonable) than the equivalent port to useOneAnd
.Using this library sensibly with Scala 2.12 requires
-Xsource:2.13
and-Ypartial-unification
. - sealed abstract class NonEmptyColl extends AnyRef
The visible interface of NonEmpty; use that value to access these members.
- sealed abstract class NonEmptyCollInstances extends NonEmptyCollInstances0
- sealed abstract class NonEmptyCollInstances0 extends AnyRef
- type NonEmptyF[F[_], A] = nonempty.NonEmptyColl.NonEmptyF[F, A]
A subtype of
NonEmpty[F[A]]
whereA
is in position to be inferred properly.A subtype of
NonEmpty[F[A]]
whereA
is in position to be inferred properly. When attempting to fit a type to the type paramsC[T]
, scalac will infer the following:type shape
C
T
NonEmpty[F[A]]
NonEmpty
F[A]
NonEmptyF[F, A]
NonEmpty[F, *]
A
If you want to
traverse
orfoldLeft
ormap
on A, the latter is far more convenient. So any value whose type is the former can be converted to the latter via thetoNEF
method.In fact, given any
NonEmpty[Foo]
whereFoo
can be matched to type parametersC[T]
,toNEF
will infer aNonEmptyF[C, T]
for whatever values of C and T scalac chooses. For example, ifbar: NonEmpty[Map[K, V]]
, thenbar.toNEF: NonEmptyF[Map[K, *], V]
, because that's how scalac destructures that type.
Value Members
- val :∓: :-+.type
- val ±:: +-:.type
- object +-:
Total version of +:.
- object :-+
Total version of :+.
- object NonEmpty
- object NonEmptyColl extends NonEmptyCollInstances
If you ever have to import NonEmptyColl or anything from it, your Scala settings are probably wrong.
- object NonEmptyCollInstances
- object NonEmptyReturningOps
Functions where the receiver is non-empty can be found implicitly with no further imports; they "just work".
Functions where the receiver is non-empty can be found implicitly with no further imports; they "just work". However, if we wish to refine a method on a built-in type that merely returns a nonempty-annotated type, we must import the contents of this object.
- object Singleton
The sole element of an iterable.
The sole element of an iterable. Works with sets and maps.
These patterns form a complete partition of
NonEmpty[T]
whereT
is a Seq. Note that empty is excluded by the type.case Singleton(hd) => case hd +-: NonEmpty(tl) =>