aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/function.lux
blob: 5c318eb78c137df439711e5e98c239cd97f6c854 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(.module:
  lux
  (lux (control [monoid #+ Monoid])))

(def: #export (compose f g)
  {#.doc "Function composition."}
  (All [a b c]
    (-> (-> b c) (-> a b) (-> a c)))
  (|>> g f))

(def: #export (constant c)
  {#.doc "Create constant functions."}
  (All [a b] (-> a (-> b a)))
  (function (_ _) c))

(def: #export (flip f)
  {#.doc "Flips the order of the arguments of a function."}
  (All [a b c]
    (-> (-> a b c) (-> b a c)))
  (function (_ x y) (f y x)))

(structure: #export Monoid<Function> (All [a] (Monoid (-> a a)))
  (def: identity id)
  (def: compose ..compose))