Opt
1 Option
(require option) |
Utility functions useful for Typed Rackets Option type.
Total head function for a hetergeneous list. If the list is non-empty returns the first element else #f.
Is the option value defined? Of little to no utility, but provided for completeness.
Does the option value exist and does the value match the provided predicate?
Returns the option’s value if defined else the value returned by the provided thunk. }
Returns the options’ value if defined else the provided default value.
Returns the provided option itself if its value is defined otherwise the given alternative option. }
Apply the given procedure to the option value if defined.
Apply the given procedure to the option’s value if defined and return it, otherwise return the provided default value.
procedure
x : (Option a) fn : (-> a b) default-expr : (Thunk b)
Apply the given procedure to the option’s value if defined and return it, otherwise return the value returned from the provided thunk when evaluated.
Use the provided function to translate from an option value of one type to an option value of another type.
If the option is defined and the predicate is satisfied return the option’s value else #f.
Drop’s the options value (i.e. returns #f) if the value does not match the provided predicate.
Apply a side-effecting procedure to the option’s value if defined, otherwise does nothing. Returns a void value.
2 Either
(require either) |
struct
(struct Left (val) #:extra-constructor-name make-Left) val : E
The left possible value of an Either type. By convention is often the error or failure value or message.
struct
(struct Right (val) #:extra-constructor-name make-Right) val : D
The right possible value of an Either type. By convention is often the correct or success value.
A type whose value is of one type or another. By convention often the Left type value is a failure value value and the Right type value is a success value.
Project (return) the Either’s value IF it is a Left value, otherwise and error is thrown.
Project (return the Either’s value IF it is a Right value, otherwise an error is thrown.
procedure
left-fn : (-> E T) right-fn : (-> D T) an-either : (Either E D)
Applies one of the provided procedures to the value of the provided Either argument. Which procedure is applied depends on the type of the provided Either’s value.