|(require rebellion/base/option)||package: rebellion|
Constructs a present value containing v.
Returns the value wrapped by pres.
The absent constant.
Inspects opt and, if it is present, calls present-handler on the present value. If it is absent, calls absent-handler. Returns the result of the called handler.
> (option-case (present 42) #:present add1 #:absent (λ () (error "missing!")))
> (option-case absent #:present add1 #:absent (λ () (error "missing!")))
Applies f to the value contained in opt if it is present and returns the result wrapped in a present value. If opt is absent, returns absent.
Applies f to the value contained in opt if it is present and returns the result of f. If opt is absent, returns absent.
(define (inverse x) (if (zero? x) absent (present (/ 1 x))))
> (option-flat-map (present 42) inverse)
> (option-flat-map absent inverse)
> (option-flat-map (present 0) inverse)
If opt is present, tests its value with pred and returns it if pred results in #t. Otherwise, returns absent.
> (option-filter (present 42) number?)
> (option-filter (present "hello") number?)
> (option-filter absent number?)
Returns the value in opt if it is present, otherwise returns default.
Returns either a sequence that contains the present value of opt, or an empty sequence if opt is absent. This function is particularly useful in transduce pipelines, as it can be used with append-mapping and similar transducers in order to safely filter out absent values while simultaneously unwrapping present values.
Constructs a contract for option values that accepts either the absent value or a present value that satisfies contract. Equivalent to (or/c absent? (present/c contract)).
Constructs a contract for present values that satisfy contract.