]> gitweb.factorcode.org Git - factor.git/blob - core/classes/maybe/maybe-docs.factor
Switch to https urls
[factor.git] / core / classes / maybe / maybe-docs.factor
1 ! Copyright (C) 2017 Alexander Ilin.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax kernel ;
4 IN: classes.maybe
5
6 ABOUT: "maybes"
7
8 ARTICLE: "maybes" "Maybe classes"
9 "A " { $snippet "maybe" } " is an anonymous union class (" { $link "unions" } ") of its members and the " { $link POSTPONE: f } " class. An object is an instance of a " { $snippet "maybe" } " class if it is either an instance of any of its participants, or " { $link POSTPONE: f } "." $nl
10 "The " { $snippet "maybe" } " classes are used to declare typed slots that are optional for a tuple. Without this mechanism it would be an error to assign " { $link POSTPONE: f } " to such a typed slot, and therefore any tuple containing them without specifying an " { $link POSTPONE: initial: } " value could not be created with the word " { $link new } "." $nl
11 "A slot with an empty " { $snippet "maybe{ }" } " class can only hold the " { $link POSTPONE: f } " value."
12 { $examples
13     { $example
14         "USING: prettyprint ;"
15         "TUPLE: test-maybe { value maybe{ fixnum string } } ;"
16         "test-maybe new value>> ."
17         "f"
18     }
19 }
20 { $see-also "unions" POSTPONE: maybe{ } ;