aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/control/function.lux
blob: 068a9f40d1877d7b1cc99a02b056c80467786caf (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
25
26
27
28
29
30
31
32
33
34
35
36
37
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
 [library
  [lux (.except)
   [abstract
    [monoid (.only Monoid)]]]])

(def .public identity
  (All (_ a) (-> a a))
  (|>>))

(def .public (composite f g)
  (All (_ a b c)
    (-> (-> b c) (-> a b) (-> a c)))
  (|>> g f))

(def .public (constant value)
  (All (_ o) (-> o (All (_ i) (-> i o))))
  (function (_ _) value))

(def .public (flipped f)
  (All (_ a b c)
    (-> (-> a b c) (-> b a c)))
  (function (_ x y) (f y x)))

(def .public (on input function)
  (All (_ i o)
    (-> i (-> i o) o))
  (function input))

(def .public monoid
  (All (_ a) (Monoid (-> a a)))
  (implementation
   (def identity ..identity)
   (def composite ..composite)))