Skip to content

Type Interfaces : Unit

johnmcclean-aol edited this page Nov 23, 2016 · 1 revision

The Unit interface

The Unit interface defines a unit method that allows us to create new instances of the implementing type (with a configurable generic type).

Unit contains a single method

  • unit : create a new instance of the concrete type of the Unit with the supplied generic parameter

Examples

ListX<String> list = ListX.of(1,2,3)
                           .unit("hello");

This can be very useful for AnyM based types (AnyM, AnyMSeq, AnyMValue & Monad Transformers) as it allows us to create an instance of the underlying type without even knowing what it is.

E.g. with a Javaslang Either

AnyMSeq<String> list = Javaslang.value(Either.left(1))
                                .unit("hello");   //Either.right("hello");

Implementations

AnyM, AnyMSeq, AnyMValue, CompletableFutureT, DequeX, EmptyUnit, Eval, FeatureToggle, FluentCollectionX, FluentSequenceX, FutureWT, Ior<ST,PT>, LazyFutureStream, ListX, Maybe, PBagX, PersistentCollectionX, POrderedSetX, PQueueX, PSetX, PStackX, PVectorX, QueueX, ReactiveSeq, SetX, SortedSetX, Streamable, TransformerValue, Try<T,X>, Xor<ST,PT>

Clone this wiki locally