You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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");