Control
contains functions that deal with functions, control flow, and other higher order concepts.
iterate
(Fn [Int, (Ref (Fn [a] a) b), a] a)
(iterate n f start)
Apply function f n times, first to start and then to the result of f. TODO: Mention fix points.
iterate-until
(Fn [(Ref (Fn [a] a) b), (Ref (Fn [a] Bool) c), a] a)
(iterate-until f pred start)
Like iterate, but f is applied repeatedly until the predicate pred is true.
when-error
(Fn [(Ref (Fn [] ()) a), (Result b c)] ())
(when-error f result)
Executes a side effect, f, when result is Erroroneus.
(def suc (the (Result Int Int) (Result.Success 0)))
(def err (the (Result Int Int) (Result.Error 0)))
(when-error &(fn [] (IO.println "error!")) err)
=> error!
(when-error &(fn [] (IO.println "error!")) suc)
=>
when-just
(Fn [(Ref (Fn [] ()) a), (Maybe b)] ())
(when-just f maybe)
Executes a side-effect, f, when maybe is Just.
(def just (Maybe.Just 2))
(def nothing (the (Maybe Int) (Maybe.Nothing)))
(when-just &(fn [] (IO.println "just!")) just)
=> just!
(when-just &(fn [] (IO.println "just!")) nothing)
=>
when-nothing
(Fn [(Ref (Fn [] ()) a), (Maybe b)] ())
(when-nothing f maybe)
Executes a side-effect, f, when maybe is Nothing.
(def just (Maybe.Just 2))
(def nothing (the (Maybe Int) (Maybe.Nothing)))
(when-nothing &(fn [] (IO.println "nothing!")) nothing)
=> nothing!
(when-nothing &(fn [] (IO.println "nothing!")) just)
=>
when-success
(Fn [(Ref (Fn [] ()) a), (Result b c)] ())
(when-success f result)
Executes a side effect, f, when result is Successful.
(def suc (the (Result Int Int) (Result.Success 0)))
(def err (the (Result Int Int) (Result.Error 0)))
(when-success &(fn [] (IO.println "success!")) suc)
=> success!
(when-success &(fn [] (IO.println "success!")) err)
=>