1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 14:54:16 +03:00

Implement unzip over Both.

This commit is contained in:
Rob Rix 2016-02-29 01:46:43 -05:00
parent b6ffeeba2a
commit ecdb3c3e9b

View File

@ -7,6 +7,10 @@ newtype Both a = Both { runBoth :: (a, a) }
both :: a -> a -> Both a
both = curry Both
unzip :: [Both a] -> Both [a]
unzip = foldr pair (pure [])
where pair (Both (a, b)) (Both (as, bs)) = Both (a : as, b : bs)
instance Applicative Both where
pure a = Both (a, a)
Both (f, g) <*> Both (a, b) = Both (f a, g b)