See: Description
Interface | Description |
---|---|
Option<T> |
Indicates presence or absence of a value (null is a valid, present value).
|
Or<G,B> |
`Or` represents the presence of a successful outcome, or an error.
|
Class | Description |
---|---|
None<T> |
Represents the absence of a value
|
OneOf2<A,B> |
This is designed to represent a union of 2 types, meaning an object that can be one type, or another.
|
OneOf2OrNone<A,B> |
Holds one of 2 values or
None . |
OneOf3<A,B,C> |
Holds one of 3 values.
|
OneOf4<A,B,C,D> |
Holds one of 4 values.
|
Option.Some<T> |
Represents the presence of a value, even if that value is null.
|
Or.Bad<G,B> |
Represents the presence of a Bad value (and absence of a Good).
|
Or.Good<G,B> |
Represents the presence of a Good value (and absence of a Bad).
|
This approximates union types for Java - for when something (like a return type) can be exactly one of a few different things. This is NOT variance or inheritance (Cars and Trucks are Vehicles), this is one un-related thing or another (a set of things that are either Trucks, Happiness, or Timestamps).
Java has specifically avoided union types in favor of defining a super-type and making those other two types extend the new parent. But sometimes you don't have control of the two types to make them inherit from a common ancestor (like Trucks and Happiness). Sometimes, one hierarchy makes sense in one context and another hierarchy makes sense in another.
Really, we want to move to a type system where types are sets. ML had this in 1990. Haskell took it from there. Then Object Oriented programming took the world by storm and types without Objects waned. In retrospect, we may have missed something.
If you like Paguro and are interested in a new JVM and maybe compile-to-JavaScript language with Union and Intersection types instead of Object Oriented hierarchies, take a look at the evolving spec for the Cymling programming language. It may need some help to become reality.
Copyright © 2017. All rights reserved.