Maybe classes
Factor handbook » The language » Objects » Classes

Prev:Intersection classes
Next:Mixin classes


A maybe is an anonymous union class (Union classes) of its members and the f class. An object is an instance of a maybe class if it is either an instance of any of its participants, or f.

The maybe classes are used to declare typed slots that are optional for a tuple. Without this mechanism it would be an error to assign f to such a typed slot, and therefore any tuple containing them without specifying an initial: value could not be created with the word new.

A slot with an empty maybe{ } class can only hold the f value.

Examples
USING: prettyprint ; TUPLE: test-maybe { value maybe{ fixnum string } } ; test-maybe new value>> .
f



See also
Union classes, maybe{