:: (a -> b -> c) -> f a -> f b -> f c

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)
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 <*>.
Promote a function to a monad, scanning the monadic arguments from left to right. For example,
liftM2 (+) [0,1] [0,2] = [0,2,1,3]
liftM2 (+) (Just 1) Nothing = Nothing
O(min(m,n)) Zip two vectors with the given function.
Zip two vector together using function. Examples:
>>> import Data.Vector.Fixed.Boxed (Vec3)

>>> let b0 = basis 0 :: Vec3 Int

>>> let b1 = basis 1 :: Vec3 Int

>>> let b2 = basis 2 :: Vec3 Int

>>> let vplus x y = zipWith (+) x y

>>> vplus b0 b1
fromList [1,1,0]

>>> vplus b0 b2
fromList [1,0,1]

>>> vplus b1 b2
fromList [0,1,1]
Lift a binary function into a comonad with zipping
Generic liftF2. Caveats:
  1. Will not compile if w is a sum type.
  2. Types in w that do not mention the type variable must be instances of Semigroup.
Apply a function to the components of two vectors.
  • For a dense vector this is equivalent to liftA2.
  • For a sparse vector this is equivalent to intersectionWith.
Lift a binary function into a Comonad with zipping
Get the intersection of two maps with a supplied function that takes in the left map's value and the right map's value.
Combines two structures by taking the intersection of their shapes and combining the elements with the given function.
Like liftM2, but evaluating its two monadic arguments in parallel.
Generic liftA2. See also gpure.
Zip two vector together using function.
Apply a function to the components of two vectors.
  • For a dense vector this is equivalent to liftA2.
  • For a sparse vector this is equivalent to intersectionWith.