packages feed

kleisli 0.0.3 → 0.0.4

raw patch · 3 files changed

+32/−1 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Kleisli: fromMaybe :: (Unwrapped t ~ (a -> Identity b), Unwrapped s ~ (a -> Maybe b), Rewrapped s t, Rewrapped t s) => b -> s -> t

Files

changelog.md view
@@ -1,3 +1,8 @@+0.0.4++* Add `fromMaybe` for replacing Nothing results with a default value,+  collapsing the Maybe layer into Identity+ 0.0.3  * Add `mkKleisli'`, `mkProKleisli'`, `mkContraKleisli'` for constructing
kleisli.cabal view
@@ -1,6 +1,6 @@ cabal-version:        2.4 name:                 kleisli-version:              0.0.3+version:              0.0.4 synopsis:             Kleisli-like newtypes with different type parameter orderings description:   Three newtype wrappers around @p a (f b)@ with different type parameter
src/Data/Kleisli.hs view
@@ -72,6 +72,9 @@     hoistContraKleisli,     hoistContraKleisli',     pureContraKleisli,++    -- * Maybe+    fromMaybe,   ) where @@ -109,6 +112,7 @@ import Data.Functor.Extend (Extend (..)) import Data.Functor.Plus (Plus (..)) import qualified Data.Functor.Rep as FRep (Rep, Representable (..))+import qualified Data.Maybe as Maybe import Data.Profunctor (Closed, Strong) import Data.Profunctor.Choice (Cochoice) import Data.Profunctor.Mapping (Mapping)@@ -405,6 +409,28 @@ pureContraKleisli :: (Profunctor p, Applicative g) => ContraKleisli' p x a -> ContraKleisli p x g a pureContraKleisli = hoistContraKleisli' pure {-# INLINE pureContraKleisli #-}++-- | Replace 'Nothing' results with a default value, collapsing the 'Maybe'+-- layer into 'Identity'.+--+-- >>> let Kleisli f = fromMaybe 0 (Kleisli Just :: KleisliA Int Maybe Int) in runIdentity (f 5)+-- 5+-- >>> let Kleisli f = fromMaybe 0 (Kleisli (const Nothing) :: KleisliA Int Maybe Int) in runIdentity (f 5)+-- 0+-- >>> let ProKleisli f = fromMaybe 0 (ProKleisli Just :: ProKleisliA Maybe Int Int) in runIdentity (f 5)+-- 5+-- >>> let ProKleisli f = fromMaybe 0 (ProKleisli (const Nothing) :: ProKleisliA Maybe Int Int) in runIdentity (f 5)+-- 0+-- >>> let ContraKleisli f = fromMaybe 0 (ContraKleisli Just :: ContraKleisliA Int Maybe Int) in runIdentity (f 5)+-- 5+-- >>> let ContraKleisli f = fromMaybe 0 (ContraKleisli (const Nothing) :: ContraKleisliA Int Maybe Int) in runIdentity (f 5)+-- 0+fromMaybe ::+  (Unwrapped t ~ (a -> Identity b), Unwrapped s ~ (a -> Maybe b),  Rewrapped s t, Rewrapped t s) => b -> s -> t+fromMaybe b = over _Wrapped (\k -> (Identity . Maybe.fromMaybe b) . k)+{-# SPECIALIZE fromMaybe :: b -> KleisliA a Maybe b -> KleisliA' a b #-}+{-# SPECIALIZE fromMaybe :: b -> ProKleisliA Maybe a b -> ProKleisliA' a b #-}+{-# SPECIALIZE fromMaybe :: b -> ContraKleisliA b Maybe a -> ContraKleisliA' b a #-}  -- | >>> import Control.Lens (op, _Wrapped') -- >>> op Kleisli (Kleisli Just :: Kleisli (->) Int Maybe Int) 5