Replace List.filteri with custom list_take
This commit is contained in:
parent
bce085878d
commit
46485ffae5
@ -48,12 +48,18 @@ let list_fs dir =
|
||||
| f::fs -> loop (f::result) fs
|
||||
in loop [] [dir]
|
||||
|
||||
let list_take n =
|
||||
let rec take acc n = function [] -> []
|
||||
| x::_ when n = 1 -> x::acc
|
||||
| x::xs -> take (x::acc) (n-1) xs
|
||||
in take [] n
|
||||
|
||||
let iter ?(predicate=fun _ -> true) ?order ?number fn {store;_} =
|
||||
match order with
|
||||
| None -> List.iter (iter_valid_text predicate fn) @@ list_fs store
|
||||
| Some comp ->
|
||||
List.iter fn
|
||||
@@ (match number with None -> (fun x -> x) | Some n -> List.filteri (fun x _ -> x < n))
|
||||
@@ (match number with None -> (fun x -> x) | Some n -> list_take n)
|
||||
@@ List.fast_sort comp
|
||||
@@ List.fold_left (fold_valid_text predicate (fun a e -> List.cons e a)) []
|
||||
@@ list_fs store
|
||||
@ -63,7 +69,7 @@ let fold ?(predicate=fun _ -> true) ?order ?number fn acc {store;_} =
|
||||
| None -> List.fold_left (fold_valid_text predicate fn) acc @@ list_fs store
|
||||
| Some comp ->
|
||||
List.fold_left fn acc
|
||||
@@ (match number with None -> (fun x -> x) | Some n -> List.filteri (fun x _ -> x < n))
|
||||
@@ (match number with None -> (fun x -> x) | Some n -> list_take n)
|
||||
@@ List.fast_sort comp
|
||||
@@ List.fold_left (fold_valid_text predicate (fun a e -> List.cons e a)) []
|
||||
@@ list_fs store
|
||||
|
Loading…
x
Reference in New Issue
Block a user