package tablecloth-base

  1. Overview
  2. Docs

Source file TableclothFun.ml

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
external identity : 'a -> 'a = "%identity"

external ignore : _ -> unit = "%ignore"

let constant a _ = a

let sequence _ b = b

let flip f x y = f y x

let negate f t = not (f t)

let apply f a = f a

let ( <| ) a b = a b

external pipe : 'a -> ('a -> 'b) -> 'b = "%revapply"

external ( |> ) : 'a -> ('a -> 'b) -> 'b = "%revapply"

let compose g f a = g (f a)

let ( << ) = compose

let compose_right g f a = f (g a)

let ( >> ) = compose_right

let tap a ~f =
  f a ;
  a


let rec times n ~f =
  if n <= 0
  then ()
  else (
    f () ;
    times (n - 1) ~f )


let forever f =
  try
    while true do
      f ()
    done ;
    failwith "[while true] managed to return, you are in trouble now."
  with
  | exn ->
      exn


let curry (f : 'a * 'b -> 'c) a b : 'c = f (a, b)

let uncurry (f : 'a -> 'b -> 'c) ((a, b) : 'a * 'b) : 'c = f a b

let curry3 f a b c = f (a, b, c)

let uncurry3 f (a, b, c) = f a b c