[sledge] Add Array.of_list_map

Reviewed By: ngorogiannis

Differential Revision: D28907815

fbshipit-source-id: 40ed1f29e
master
Josh Berdine 4 years ago committed by Facebook GitHub Bot
parent a6f3e15cec
commit 69c4f089bd

@ -27,6 +27,19 @@ let of_list_rev = function
in
back_fill (len - 2) tl
let of_list_map xs ~f =
match xs with
| [] -> [||]
| hd :: tl ->
let a = make (1 + List.length tl) (f hd) in
let rec fill i = function
| [] -> a
| hd :: tl ->
unsafe_set a i (f hd) ;
fill (i + 1) tl
in
fill 1 tl
let is_empty = function [||] -> true | _ -> false
let map xs ~f = map ~f xs
let mapi xs ~f = mapi ~f xs

@ -13,6 +13,7 @@ type 'a t = 'a array [@@deriving compare, equal, sexp]
val of_ : 'a -> 'a t
val of_iter : 'a iter -> 'a t
val of_list_rev : 'a list -> 'a t
val of_list_map : 'a list -> f:('a -> 'b) -> 'b t
val map : 'a t -> f:('a -> 'b) -> 'b t
val mapi : 'a t -> f:(int -> 'a -> 'b) -> 'b t

Loading…
Cancel
Save