{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE Trustworthy #-}
module Data.Functor.Apply (
Functor(..)
, (<$>)
, ( $>)
, Apply(..)
, (<..>)
, liftF3
, gliftF2
, gliftF3
, WrappedApplicative(..)
, MaybeApply(..)
, (<.*>)
, (<*.>)
) where
import Data.Functor
import Data.Functor.Bind.Class
import GHC.Generics
infixl 4 <..>
(<..>) :: Apply w => w a -> w (a -> b) -> w b
<..> :: forall (w :: * -> *) a b. Apply w => w a -> w (a -> b) -> w b
(<..>) = (a -> (a -> b) -> b) -> w a -> w (a -> b) -> w b
forall a b c. (a -> b -> c) -> w a -> w b -> w c
forall (f :: * -> *) a b c.
Apply f =>
(a -> b -> c) -> f a -> f b -> f c
liftF2 (((a -> b) -> a -> b) -> a -> (a -> b) -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> b) -> a -> b
forall a. a -> a
id)
{-# INLINE (<..>) #-}
liftF3 :: Apply w => (a -> b -> c -> d) -> w a -> w b -> w c -> w d
liftF3 :: forall (w :: * -> *) a b c d.
Apply w =>
(a -> b -> c -> d) -> w a -> w b -> w c -> w d
liftF3 a -> b -> c -> d
f w a
a w b
b w c
c = a -> b -> c -> d
f (a -> b -> c -> d) -> w a -> w (b -> c -> d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> w a
a w (b -> c -> d) -> w b -> w (c -> d)
forall a b. w (a -> b) -> w a -> w b
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> w b
b w (c -> d) -> w c -> w d
forall a b. w (a -> b) -> w a -> w b
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> w c
c
{-# INLINE liftF3 #-}
gliftF2 :: (Generic1 w, Apply (Rep1 w)) => (a -> b -> c) -> w a -> w b -> w c
gliftF2 :: forall (w :: * -> *) a b c.
(Generic1 w, Apply (Rep1 w)) =>
(a -> b -> c) -> w a -> w b -> w c
gliftF2 a -> b -> c
f w a
wa w b
wb = Rep1 w c -> w c
forall a. Rep1 w a -> w a
forall k (f :: k -> *) (a :: k). Generic1 f => Rep1 f a -> f a
to1 (Rep1 w c -> w c) -> Rep1 w c -> w c
forall a b. (a -> b) -> a -> b
$ (a -> b -> c) -> Rep1 w a -> Rep1 w b -> Rep1 w c
forall a b c. (a -> b -> c) -> Rep1 w a -> Rep1 w b -> Rep1 w c
forall (f :: * -> *) a b c.
Apply f =>
(a -> b -> c) -> f a -> f b -> f c
liftF2 a -> b -> c
f (w a -> Rep1 w a
forall a. w a -> Rep1 w a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 w a
wa) (w b -> Rep1 w b
forall a. w a -> Rep1 w a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 w b
wb)
gliftF3 :: (Generic1 w, Apply (Rep1 w)) => (a -> b -> c -> d) -> w a -> w b -> w c -> w d
gliftF3 :: forall (w :: * -> *) a b c d.
(Generic1 w, Apply (Rep1 w)) =>
(a -> b -> c -> d) -> w a -> w b -> w c -> w d
gliftF3 a -> b -> c -> d
f w a
wa w b
wb w c
wc = Rep1 w d -> w d
forall a. Rep1 w a -> w a
forall k (f :: k -> *) (a :: k). Generic1 f => Rep1 f a -> f a
to1 (Rep1 w d -> w d) -> Rep1 w d -> w d
forall a b. (a -> b) -> a -> b
$ (a -> b -> c -> d) -> Rep1 w a -> Rep1 w b -> Rep1 w c -> Rep1 w d
forall (w :: * -> *) a b c d.
Apply w =>
(a -> b -> c -> d) -> w a -> w b -> w c -> w d
liftF3 a -> b -> c -> d
f (w a -> Rep1 w a
forall a. w a -> Rep1 w a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 w a
wa) (w b -> Rep1 w b
forall a. w a -> Rep1 w a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 w b
wb) (w c -> Rep1 w c
forall a. w a -> Rep1 w a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 w c
wc)