12 | interface Zippable z where
16 | zipWith : (func : a -> b -> c) -> z a -> z b -> z c
20 | zip : z a -> z b -> z (a, b)
23 | export infixr 6 `zip`
28 | zipWith3 : (func : a -> b -> c -> d) -> z a -> z b -> z c -> z d
29 | zipWith3 f = zipWith (uncurry f) .: zip
33 | zip3 : z a -> z b -> z c -> z (a, b, c)
34 | zip3 = zipWith3 (,,)
40 | unzipWith : (func : a -> (b, c)) -> z a -> (z b, z c)
44 | unzip : z (a, b) -> (z a, z b)
45 | unzip = unzipWith id
51 | unzipWith3 : (func : a -> (b, c, d)) -> z a -> (z b, z c, z d)
52 | unzipWith3 = mapSnd unzip .: unzipWith
57 | unzip3 : z (a, b, c) -> (z a, z b, z c)
58 | unzip3 = unzipWith3 id
61 | [Compose] Zippable f => Zippable g => Zippable (f . g) where
62 | zipWith f = zipWith $
zipWith f
63 | zipWith3 f = zipWith3 $
zipWith3 f
64 | unzipWith f = unzipWith $
unzipWith f
65 | unzipWith3 f = unzipWith3 $
unzipWith3 f
68 | zip3 = zipWith3 zip3
69 | unzip = unzipWith unzip
70 | unzip3 = unzipWith3 unzip3
81 | [FromApplicative] Applicative f => Zippable f where
82 | zipWith f x y = [| f x y |]
83 | zipWith3 f x y z = [| f x y z |]
85 | unzip u = (map fst u, map snd u)
86 | unzip3 u = (map fst u, map (fst . snd) u, map (snd . snd) u)
87 | unzipWith f = unzip . map f
88 | unzipWith3 f = unzip3 . map f
92 | Semigroup a => Zippable (Pair a) where
93 | zipWith f (l, x) (r, y) = (l <+> r, f x y)
94 | zipWith3 f (l, x) (m, y) (r, z) = (l <+> m <+> r, f x y z)
96 | unzipWith f (l, x) = bimap (l,) (l,) (f x)
97 | unzipWith3 f (l, x) = bimap (l,) (bimap (l,) (l,)) (f x)