Import Upstream version 20180207
[hcoop/debian/mlton.git] / lib / mlton / basic / fold.sig
1 (* Copyright (C) 2009 Matthew Fluet.
2 * Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 *
5 * MLton is released under a BSD-style license.
6 * See the file MLton-LICENSE for details.
7 *)
8
9 signature FOLD_STRUCTS =
10 sig
11 type 'a t
12 type 'a elt
13
14 val fold: 'a t * 'b * ('a elt * 'b -> 'b) -> 'b
15 end
16
17 signature FOLD =
18 sig
19 include FOLD_STRUCTS
20
21 val foldi: 'a t * 'b * (int * 'a elt * 'b -> 'b) -> 'b
22 val foreachi: 'a t * (int * 'a elt -> unit) -> unit
23 val foreach: 'a t * ('a elt -> unit) -> unit
24 (* keepAll (l, f) keeps all x in l such that f x. *)
25 val keepAll: 'a t * ('a elt -> bool) -> 'a elt list
26 (* keepAllMap (l, f) keeps all y in l such that f x = SOME y.*)
27 val keepAllMap: 'a t * ('a elt -> 'b option) -> 'b list
28 val last: 'a t -> 'a elt
29 val layout: ('a elt -> Layout.t) -> 'a t -> Layout.t
30 val length: 'a t -> int
31 val map: 'a t * ('a elt -> 'b) -> 'b list
32 val mapi: 'a t * (int * 'a elt -> 'b) -> 'b list
33 (* removeAll (l, f) removes all x in l such that f x. *)
34 val removeAll: 'a t * ('a elt -> bool) -> 'a elt list
35 (* The "rev" versions of functions are there for efficiency, when it is
36 * easier to fold over the input and accumulate the result in reverse.
37 *)
38 val revKeepAll: 'a t * ('a elt -> bool) -> 'a elt list
39 val revKeepAllMap: 'a t * ('a elt -> 'b option) -> 'b list
40 val revRemoveAll: 'a t * ('a elt -> bool) -> 'a elt list
41 end