1+ ###
2+ # @meta Functional
3+ # @brief Compose function calls
4+ # ---
5+ # (let foo (fun (a) (* a a)))
6+ # (let bar (fun (b) (+ b b)))
7+ # (let composed (compose foo bar))
8+ # (print (composed 12)) # return value is (12 + 12) * (12 + 12)
9+ # ---
10+ # @param _f the first function
11+ # @param _g the second function
12+ # @author https://github.com/rstefanic
13+ ###
14+ (let compose (fun (_f _g)
15+ (fun (_y &_f &_g) (_f (_g _y)))))
16+
17+ ###
18+ # @meta Functional
19+ # @brief Take a value as its argument and return a function taking 2 arguments which will call the first function on the value
20+ # ---
21+ # (let val (left 12))
22+ # (val (fun (x) (print x " i am called")) (fun (x) (print x " i am NOT called")))
23+ # ---
24+ # @param _x the value
25+ # @author https://github.com/SuperFola
26+ ###
27+ (let left (fun (_x)
28+ (fun (_injl _injr &_x) (_injl _x))
29+ ))
30+
31+ ###
32+ # @meta Functional
33+ # @brief Take a value as its argument and return a function taking 2 arguments which will call the second function on the value
34+ # ---
35+ # (let val (right 12))
36+ # (val (fun (x) (print x " i am NOT called")) (fun (x) (print x " i am called")))
37+ # ---
38+ # @param _y the value
39+ # @author https://github.com/SuperFola
40+ ###
41+ (let right (fun (_y)
42+ (fun (_injl _injr &_y) (_injr _y))
43+ ))
44+
45+ ###
46+ # @meta Functional
47+ # @brief Flip the arguments of a function
48+ # @details Returns a function taking 1 argument: the second argument of the function to flip
49+ # ---
50+ # (let foo (fun (a b) (- a b)))
51+ # ((flip foo 14) 12) # will call (foo 12 14) instead of (foo 14 12)
52+ # ---
53+ # @param _f the function
54+ # @param _a the first argument
55+ # @author https://github.com/rstefanic
56+ ###
57+ (let flip (fun (_f _a)
58+ (fun (_b &_f &_a) (_f _b _a))))
0 commit comments