Functional

compose


(let compose (fun (_f _g) (...))) Compose function calls

Parameters

  • _f: the first function
  • _g: the second function

Author

@rstefanic

Example

(let foo (fun (a) (* a a)))
(let bar (fun (b) (+ b b)))
(let composed (compose foo bar))
(print (composed 12))  # return value is (12 + 12) * (12 + 12)

left


(let left (fun (_x) (...))) Take a value as its argument and return a function taking 2 arguments which will call the first function on the value

Parameter

  • _x: the value

Author

@SuperFola

Example

(let val (left 12))
(val (fun (x) (print x " i am called")) (fun (x) (print x " i am NOT called")))

(let right (fun (_y) (...))) Take a value as its argument and return a function taking 2 arguments which will call the second function on the value

Parameter

  • _y: the value

Author

@SuperFola

Example

(let val (right 12))
(val (fun (x) (print x " i am NOT called")) (fun (x) (print x " i am called")))

flip


(let flip (fun (_f _a) (...))) Flip the arguments of a function

Note: Returns a function taking 1 argument: the second argument of the function to flip

Parameters

  • _f: the function
  • _a: the first argument

Author

@rstefanic

Example

(let foo (fun (a b) (- a b)))
((flip foo 14) 12) # will call (foo 12 14) instead of (foo 14 12)