forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathext_list.mli
146 lines (91 loc) · 4.41 KB
/
ext_list.mli
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
(** Extension to the standard library [List] module *)
(** TODO some function are no efficiently implemented. *)
val filter_map : ('a -> 'b option) -> 'a list -> 'b list
val excludes : ('a -> bool) -> 'a list -> bool * 'a list
val exclude_with_fact : ('a -> bool) -> 'a list -> 'a option * 'a list
val exclude_with_fact2 :
('a -> bool) -> ('a -> bool) -> 'a list -> 'a option * 'a option * 'a list
val same_length : 'a list -> 'b list -> bool
val init : int -> (int -> 'a) -> 'a list
val take : int -> 'a list -> 'a list * 'a list
val try_take : int -> 'a list -> 'a list * int * 'a list
val exclude_tail : 'a list -> 'a * 'a list
val length_compare : 'a list -> int -> [`Gt | `Eq | `Lt ]
(**
{[length xs = length ys + n ]}
input n should be positive
TODO: input checking
*)
val length_larger_than_n :
int -> 'a list -> 'a list -> bool
val filter_map2 : ('a -> 'b -> 'c option) -> 'a list -> 'b list -> 'c list
val filter_map2i : (int -> 'a -> 'b -> 'c option) -> 'a list -> 'b list -> 'c list
val filter_mapi : (int -> 'a -> 'b option) -> 'a list -> 'b list
val flat_map2 : ('a -> 'b -> 'c list) -> 'a list -> 'b list -> 'c list
val flat_map_acc : ('a -> 'b list) -> 'b list -> 'a list -> 'b list
val flat_map : ('a -> 'b list) -> 'a list -> 'b list
(** for the last element the first element will be passed [true] *)
val fold_right2_last : (bool -> 'a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'c
val map_last : (bool -> 'a -> 'b) -> 'a list -> 'b list
val stable_group : ('a -> 'a -> bool) -> 'a list -> 'a list list
val drop : int -> 'a list -> 'a list
val for_all_ret : ('a -> bool) -> 'a list -> 'a option
val for_all_opt : ('a -> 'b option) -> 'a list -> 'b option
(** [for_all_opt f l] returns [None] if all return [None],
otherwise returns the first one.
*)
val fold : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b
(** same as [List.fold_left].
Provide an api so that list can be easily swapped by other containers
*)
val rev_map_append : ('a -> 'b) -> 'a list -> 'b list -> 'b list
val rev_map_acc : 'a list -> ('b -> 'a) -> 'b list -> 'a list
val map_acc : 'a list -> ('b -> 'a) -> 'b list -> 'a list
val rev_iter : ('a -> unit) -> 'a list -> unit
val for_all2_no_exn : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
val find_opt : ('a -> 'b option) -> 'a list -> 'b option
(** [f] is applied follow the list order *)
val split_map : ('a -> 'b * 'c) -> 'a list -> 'b list * 'c list
val reduce_from_right : ('a -> 'a -> 'a) -> 'a list -> 'a
(** [fn] is applied from left to right *)
val reduce_from_left : ('a -> 'a -> 'a) -> 'a list -> 'a
type 'a t = 'a list ref
val create_ref_empty : unit -> 'a t
val ref_top : 'a t -> 'a
val ref_empty : 'a t -> bool
val ref_push : 'a -> 'a t -> unit
val ref_pop : 'a t -> 'a
val rev_except_last : 'a list -> 'a list * 'a
val sort_via_array :
('a -> 'a -> int) -> 'a list -> 'a list
val last : 'a list -> 'a
(** When [key] is not found unbox the default,
if it is found return that, otherwise [assert false ]
*)
val assoc_by_string :
'a option -> string -> (string * 'a) list -> 'a
val assoc_by_int :
'a option -> int -> (int * 'a) list -> 'a