package tablecloth-base

  1. Overview
  2. Docs

Source file TableclothSet.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
module Comparator = TableclothComparator

type ('a, 'id) t = ('a, 'id) Base.Set.t

module Of (M : TableclothComparator.S) = struct
  type nonrec t = (M.t, M.identity) t
end

let empty comparator = Base.Set.empty (Internal.to_base_comparator comparator)

let singleton
    (comparator : ('a, 'identity) TableclothComparator.s) (element : 'a) :
    ('a, 'identity) t =
  Base.Set.of_list (Internal.to_base_comparator comparator) [ element ]


let from_array
    (comparator : ('a, 'identity) TableclothComparator.s) (elements : 'a array)
    : ('a, 'identity) t =
  Base.Set.of_list
    (Internal.to_base_comparator comparator)
    (Array.to_list elements)


let from_array = from_array

let from_list
    (comparator : ('a, 'identity) TableclothComparator.s) (elements : 'a list) :
    ('a, 'identity) t =
  Base.Set.of_list (Internal.to_base_comparator comparator) elements


let length = Base.Set.length

let is_empty = Base.Set.is_empty

let includes set ~value = Base.Set.mem set value

let ( .?{} ) (set : ('element, _) t) (element : 'element) : bool =
  includes set ~value:element


let add set ~value = Base.Set.add set value

let remove set ~value = Base.Set.remove set value

let difference = Base.Set.diff

let intersection = Base.Set.inter

let union = Base.Set.union

let filter = Base.Set.filter

let partition = Base.Set.partition_tf

let find = Base.Set.find

let all = Base.Set.for_all

let any = Base.Set.exists

let for_each = Base.Set.iter

let fold s ~initial ~f = Base.Set.fold s ~init:initial ~f

let to_array = Base.Set.to_array

let to_list = Base.Set.to_list

module Poly = struct
  type identity = Base.Comparator.Poly.comparator_witness

  type nonrec 'a t = ('a, identity) t

  let empty () = Base.Set.Poly.empty

  let singleton = Base.Set.Poly.singleton

  let from_array = Base.Set.Poly.of_array

  let from_list = Base.Set.Poly.of_list
end

module Int = struct
  type nonrec t = Of(TableclothInt).t

  let empty = empty (module TableclothInt)

  let singleton = singleton (module TableclothInt)

  let from_array = from_array (module TableclothInt)

  let from_list = from_list (module TableclothInt)
end

module String = struct
  type nonrec t = Of(TableclothString).t

  let empty = empty (module TableclothString)

  let singleton = singleton (module TableclothString)

  let from_array = from_array (module TableclothString)

  let from_list = from_list (module TableclothString)
end
OCaml

Innovation. Community. Security.