liftA2 -package:sop-core

Lift a binary function to actions. Some functors support an implementation of liftA2 that is more efficient than the default one. In particular, if fmap is an expensive operation, it is likely better to use liftA2 than to fmap over the structure and then use <*>. This became a typeclass method in 4.10.0.0. Prior to that, it was a function defined in terms of <*> and fmap.

Example

>>> liftA2 (,) (Just 3) (Just 5)
Just (3,5)
>>> liftA2 (+) [1, 2, 3] [4, 5, 6]
[5,6,7,6,7,8,7,8,9]
Lift a binary function to actions. Some functors support an implementation of liftA2 that is more efficient than the default one. In particular, if fmap is an expensive operation, it is likely better to use liftA2 than to fmap over the structure and then use <*>. This became a typeclass method in 4.10.0.0. Prior to that, it was a function defined in terms of <*> and fmap.

Example

>>> liftA2 (,) (Just 3) (Just 5)
Just (3,5)
Lift a binary function to actions. Some functors support an implementation of liftA2 that is more efficient than the default one. In particular, if fmap is an expensive operation, it is likely better to use liftA2 than to fmap over the structure and then use <*>. This became a typeclass method in 4.10.0.0. Prior to that, it was a function defined in terms of <*> and fmap. Using ApplicativeDo: 'liftA2 f as bs' can be understood as the do expression
do a <- as
b <- bs
pure (f a b)
Like liftA2, but for sorted lists, requiring an Ord instance. The behavior is same as with lists, but with sorted results.
Equivalent of liftA2 for rank 2 data types
Lifted liftA2. Lifts backpropagatable functions to be backpropagatable functions on Traversable Applicatives.
liftA2, but taking explicit add and zero.
liftA2, but with Num constraints instead of Backprop constraints.
Like liftA2, but traverses over its first argument
Like liftA2, but traverses over its second argument
Like liftA2, but traverses over both its arguments
Append an action to the left of an Aps.
Combine two EnvelopeTs. Generalize the set of errors to include the errors from both EnvelopeTs. Similar to liftA2 but more general.

Examples

>>> let env1 = pure "hello" :: EnvelopeT '[Double, Int] Identity String

>>> let env2 = pure " world" :: EnvelopeT '[Char]  Identity String

>>> liftA2EnvT (<>) env1 env2 :: EnvelopeT '[Double, Int, Char] Identity String
EnvelopeT (Identity (SuccEnvelope "hello world"))
If either of the Envelopes is an ErrEnvelope, then return the ErrEnvelope.
>>> let env3 = throwErrEnvT "some err" :: EnvelopeT '[String, Double] Identity Int

>>> let env4 = pure 1 :: EnvelopeT '[Char]  Identity Int

>>> liftA2EnvT (+) env3 env4 :: EnvelopeT '[String, Double, Char] Identity Int
EnvelopeT (Identity (ErrEnvelope (Identity "some err")))
>>> let env5 = pure "hello" :: EnvelopeT '[Char] Identity String

>>> let env6 = throwErrEnvT 3.5 :: EnvelopeT '[(), Double] Identity String

>>> liftA2EnvT (<>) env5 env6 :: EnvelopeT '[Char, (), Double] Identity String
EnvelopeT (Identity (ErrEnvelope (Identity 3.5)))
If both of the EnvelopeTs is an ErrEnvelope, then short-circuit and only return the first ErrEnvelope.
>>> let env7 = throwErrEnvT 4.5 :: EnvelopeT '[(), Double] Identity String

>>> let env8 = throwErrEnvT 'x' :: EnvelopeT '[Int, Char] Identity String

>>> liftA2EnvT (<>) env7 env8 :: EnvelopeT '[(), Double, Int, Char] Identity String
EnvelopeT (Identity (ErrEnvelope (Identity 4.5)))
Similar to liftA2, but more general. This allows you to operate on two Envelopes with different sets of errors. The resulting Envelope is a combination of the errors in each of the input Envelopes.

Examples

>>> let env1 = toSuccEnvelope "hello" :: Envelope '[Double, Int] String

>>> let env2 = toSuccEnvelope " world" :: Envelope '[Char] String

>>> liftA2Envelope (<>) env1 env2 :: Envelope '[Double, Int, Char] String
SuccEnvelope "hello world"
If either of the Envelopes is an ErrEnvelope, then return the ErrEnvelope.
>>> let env3 = toErrEnvelope "some err" :: Envelope '[String, Double] Int

>>> let env4 = toSuccEnvelope 1 :: Envelope '[Char] Int

>>> liftA2Envelope (+) env3 env4 :: Envelope '[String, Double, Char] Int
ErrEnvelope (Identity "some err")
>>> let env5 = toSuccEnvelope "hello" :: Envelope '[Char] String

>>> let env6 = toErrEnvelope 3.5 :: Envelope '[(), Double] String

>>> liftA2Envelope (<>) env5 env6 :: Envelope '[Char, (), Double] String
ErrEnvelope (Identity 3.5)
If both of the Envelopes is an ErrEnvelope, then short-circuit and only return the first ErrEnvelope.
>>> let env7 = toErrEnvelope 3.5 :: Envelope '[(), Double] String

>>> let env8 = toErrEnvelope 'x' :: Envelope '[Int, Char] String

>>> liftA2Envelope (<>) env7 env8 :: Envelope '[(), Double, Int, Char] String
ErrEnvelope (Identity 3.5)