From 2c9fce0bf2b74b0774144cd1d5688f5e2c2706b1 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Fri, 23 Aug 2019 07:19:37 -0700 Subject: [PATCH] [sledge] Add Vector.unzip Reviewed By: jvillard Differential Revision: D16905895 fbshipit-source-id: 98891d4b0 --- sledge/src/import/vector.ml | 5 +++++ sledge/src/import/vector.mli | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sledge/src/import/vector.ml b/sledge/src/import/vector.ml index c0963d157..53092b7f2 100644 --- a/sledge/src/import/vector.ml +++ b/sledge/src/import/vector.ml @@ -81,5 +81,10 @@ let of_list x = v (Array.of_list x) let of_list_rev x = v (Array.of_list_rev x) let of_option x = v (Option.to_array x) let reduce_exn x ~f = Array.reduce_exn (a x) ~f + +let unzip x = + let y, z = Array.unzip (a x) in + (v y, v z) + let to_list x = Array.to_list (a x) let to_array = a diff --git a/sledge/src/import/vector.mli b/sledge/src/import/vector.mli index fca160dbe..b025d1616 100644 --- a/sledge/src/import/vector.mli +++ b/sledge/src/import/vector.mli @@ -175,7 +175,9 @@ val reduce_exn : 'a t -> f:('a -> 'a -> 'a) -> 'a (* val random_element_exn : ?random_state:Base.Random.State.t -> 'a t -> 'a *) (* val zip : 'a t -> 'b t -> ('a * 'b) t option *) (* val zip_exn : 'a t -> 'b t -> ('a * 'b) t *) -(* val unzip : ('a * 'b) t -> 'a t * 'b t *) + +val unzip : ('a * 'b) t -> 'a t * 'b t + (* val sorted_copy : 'a t -> compare:('a -> 'a -> int) -> 'a t *) (* val last : 'a t -> 'a *)