utility-ht-0.0.11: src/Control/Functor/HT.hs
module Control.Functor.HT where
import Data.Tuple.HT (fst3, snd3, thd3, )
void :: Functor f => f a -> f ()
void = fmap (const ())
map :: Functor f => (a -> b) -> f a -> f b
map = fmap
for :: Functor f => f a -> (a -> b) -> f b
for = flip fmap
{- |
Caution:
Every pair member has a reference to the argument of 'unzip'.
Depending on the consumption pattern this may cause a memory leak.
For lists, I think, you should generally prefer 'List.unzip'.
-}
unzip :: Functor f => f (a, b) -> (f a, f b)
unzip x = (fmap fst x, fmap snd x)
{- |
Caution: See 'unzip'.
-}
unzip3 :: Functor f => f (a, b, c) -> (f a, f b, f c)
unzip3 x = (fmap fst3 x, fmap snd3 x, fmap thd3 x)
{- |
Generalization of 'Data.List.HT.outerProduct'.
-}
outerProduct ::
(Functor f, Functor g) =>
(a -> b -> c) -> f a -> g b -> f (g c)
outerProduct f xs ys = fmap (flip fmap ys . f) xs