From d345967909b1e29f1d660f7b9ad1c1d4d02e0f6d Mon Sep 17 00:00:00 2001 From: Ivan Lazar Miljenovic Date: Tue, 13 Jun 2017 15:48:11 +1000 Subject: [PATCH] Add uncurry' --- src/Streaming/Prelude.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Streaming/Prelude.hs b/src/Streaming/Prelude.hs index 4e30c30..b3e3ae1 100644 --- a/src/Streaming/Prelude.hs +++ b/src/Streaming/Prelude.hs @@ -223,6 +223,7 @@ module Streaming.Prelude ( , fst' , snd' , mapOf + , uncurry' , _first , _second @@ -365,6 +366,15 @@ mapOf :: (a -> b) -> Of a r -> Of b r mapOf f (a:> b) = (f a :> b) {-#INLINE mapOf #-} +{-| The analogue of 'uncurry' to apply a function to both elements of a left-strict pair. + + This can be especially useful combined with functions like 'mapped'. + +-} +uncurry' :: (a -> b -> c) -> Of a b -> c +uncurry' f (a :> b) = f a b +{-# INLINE uncurry' #-} + {-| A lens into the first element of a left-strict pair -} _first :: Functor f => (a -> f a') -> Of a b -> f (Of a' b) _first afb (a:>b) = fmap (\c -> (c:>b)) (afb a)