on master help sign in
Added zip and unzip definitions for Vect
f383b59Daniel Waterworth
lib/Prelude/Vect.idr+13
@@ -75,6 +75,19 @@ replicate : (n : Nat) -> a -> Vect a n
75replicate O x = []
75replicate O x = []
76replicate (S k) x = x :: replicate k x
76replicate (S k) x = x :: replicate k x
77
77
78+--------------------------------------------------------------------------------
79+-- Zips and unzips
80+--------------------------------------------------------------------------------
81+
82+zip : Vect a n -> Vect b n -> Vect (a, b) n
83+zip [] [] = []
84+zip (x :: xs) (y :: ys) = (x, y) :: (zip xs ys)
85+
86+unzip : Vect (a, b) n -> (Vect a n, Vect b n)
87+unzip [] = ([], [])
88+unzip ((l, r)::xs) with (unzip xs)
89+ | (lefts, rights) = (l::lefts, r::rights)
90+
78--------------------------------------------------------------------------------
91--------------------------------------------------------------------------------
79-- Maps
92-- Maps
80--------------------------------------------------------------------------------
93--------------------------------------------------------------------------------