Commit ceb6b89e authored by Camil Staps's avatar Camil Staps 🚀

Document StdMaybe

parent 82890d13
......@@ -6,31 +6,57 @@ definition module StdMaybe
from StdOverloaded import class ==(..);
/**
* The Maybe type represents an optional value by providing a constructor
* for no value (`Nothing`) and a constructor for just a value (`Just`).
*/
:: Maybe x
= Just x
| Nothing
isJust :: !(Maybe .x) -> Bool // case @1 of (Just _) -> True; _ -> False
isNothing :: !(Maybe .x) -> Bool // not o isJust
fromJust :: !(Maybe .x) -> .x // \(Just x) -> x
/**
* `case @1 of ({{Just}} _) -> True; _ -> False`
*/
isJust :: !(Maybe .x) -> Bool
// for possibly unique elements:
/**
* `{{not}} {{o}} {{isJust}}`
*/
isNothing :: !(Maybe .x) -> Bool
/**
* `\({{Just}} x) -> x`
*/
fromJust :: !(Maybe .x) -> .x
/**
* {{`isJust`}} for a possibly unique value.
*/
isJustU :: !u:(Maybe .x) -> (!Bool, !u:Maybe .x)
/**
* {{`isNothing`}} for a possibly unique value.
*/
isNothingU :: !u:(Maybe .x) -> (!Bool, !u:Maybe .x)
/**
* Apply a function on the value boxed in {{`Just`}}, or pass on {{`Nothing`}}.
*/
mapMaybe :: .(.x -> .y) !(Maybe .x) -> Maybe .y
// mapMaybe f (Just x) = Just (f x)
// mapMaybe f Nothing = Nothing
instance == (Maybe x) | == x
// Nothing==Nothing
// Just a ==Just b <= a==b
/**
* @result A list with no or one element.
*/
maybeToList :: !(Maybe .a) -> [.a];
// returns list with no or one element
/**
* @result {{`Just`}} the head of the list or {{`Nothing`}} if it is empty.
*/
listToMaybe :: ![.a] -> .Maybe .a;
// returns Just head of list if possible
/**
* `catMaybes ms = [m \\ {{Just}} m <- ms]`
*/
catMaybes :: ![Maybe .a] -> .[.a];
// catMaybes ms = [ m \\ Just m <- ms ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment