package stdcompat

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file stdcompat__list.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
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
147
148
149
150
151
152
153
154
155
156
157
158
include List

(*
type 'a t = 'a list

  = [] | (::) of 'a * 'a list


let filter_map f list =
  let rec aux accu list =
    match list with
    | [] -> rev accu
    | head :: tail ->
        let accu' =
          match f head with
          | None -> accu
          | Some head' -> head' :: accu in
        aux accu' tail in
  aux [] list
*)

(*
let rec iteri_aux i f l =
  match l with
  | [] -> ()
  | hd :: tl ->
      f i hd;
      iteri_aux (succ i) f tl

let iteri f l =
  iteri_aux 0 f l

let rec mapi_aux i f l =
  match l with
  | [] -> []
  | hd :: tl ->
      let hd = f i hd in
      hd :: mapi_aux (succ i) f tl

let mapi f l =
  mapi_aux 0 f l
*)

(*
let sort_uniq cmp l =
  let cmp' a b = - (cmp a b) in
  let rev_l = sort cmp' l in
  Stdcompat__tools.uniq_rev_append cmp rev_l []
*)

(*
let cons x xs =
  x :: xs
*)

(*
let rec compare_lengths l l' =
  match l, l' with
  | [], [] -> 0
  | [], _ -> -1
  | _, [] -> 1
  | _ :: tl, _ :: tl' ->
      compare_lengths tl tl'

let rec compare_length_with l n =
  if n < 0 then 1
  else if n = 0 then
    if l = [] then 0
    else 1
  else
    match l with
    | [] -> -1
    | _ :: tl -> compare_length_with tl (pred n)

let nth_opt l n =
  Stdcompat__tools.option_fail (nth l) n

let find_opt p l =
  try
    Stdcompat__tools.option_find
      (find (Stdcompat__tools.pickle_predicate_not_found p)) l
  with Stdcompat__tools.Predicate_not_found ->
    raise Not_found

let assoc_opt key l =
  Stdcompat__tools.option_find (assoc key) l

let assq_opt key l=
  Stdcompat__tools.option_find (assq key) l
*)

(*
let rec init_aux i len f accu =
  if i >= len then
    accu
  else
    init_aux (succ i) len f (f i :: accu)

let rec init len f =
  if len < 0 then
    invalid_arg "List.init"
  else if len = 0 then
    []
  else
    rev (init_aux 0 len f [])
*)

(*
let of_seq seq =
  rev (Stdcompat__seq.fold_left (fun accu x -> x :: accu) [] seq)

let rec to_seq l () =
  match l with
  | [] -> Stdcompat__seq.Nil
  | hd :: tl -> Stdcompat__seq.Cons (hd, to_seq tl)
*)

(*
let rec find_map f l =
  match l with
  | [] -> None
  | hd :: tl ->
      match f hd with
      | None -> find_map f tl
      | some -> some

let rec concat_rev_map_aux f l accu =
  match l with
  | [] -> accu
  | hd :: tl ->
      concat_rev_map_aux f tl (rev_append (f hd) accu)

let concat_map f l =
  rev (concat_rev_map_aux f l [])
*)

(*
let rec filteri_rev_aux f l i accu =
  match l with
  | [] -> accu
  | hd :: tl ->
      let accu =
        if f i hd then
          hd :: accu
        else
          accu in
      filteri_rev_aux f tl (succ i) accu

let filteri f l =
  rev (filteri_rev_aux f l 0 [])

let fold_left_map f accu l =
  let accu, rev =
    fold_left (fun (accu, rev) item ->
      let accu, x = f accu item in
      (accu, x :: rev)) (accu, []) l in
  accu, List.rev rev
*)