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
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 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 thetoF
method.In fact, given any
NonEmpty[Foo]
whereFoo
can be matched to type parametersC[T]
,toF
will infer aNonEmptyF[C, T]
for whatever values of C and T scalac chooses. For example, ifbar: NonEmpty[Map[K, V]]
, thenbar.toF: NonEmptyF[Map[K, *], V]
, because that's how scalac destructures that type.
Value Members
- val :∓: :-+.type
- val NonEmpty: NonEmptyColl
- val ±:: +-:.type
- object +-:
Total version of +:.
- object :-+
Total version of :+.
- object NonEmptyColl extends NonEmptyCollInstances
If you ever have to import NonEmptyColl or anything from it, your Scala settings are probably wrong.
- 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.