Applicative Functors
Monadics

Prev:Functors
Next:Monads


fmap'ping a function over a structure can alternatively be thought of as raising a unary function ( a -- b ) to a higher level of abstraction ( M-a -- M-b ).

Applicative functors extend this notion to functions of any arity. The lift/<$>words perform the same lazy "raising" as fmap while preserving function input order. This lifted, partially applied function can then be collapsed to a value by applying inputs through the reify/<*> words.

Examples
USING: arrays monadics quotations prettyprint ; [ 3array ] { 1 4 7 } <$> { 2 5 8 } <*> { 3 6 9 } <*> .
{ { 1 2 3 } { 4 5 6 } { 7 8 9 } }


USING: math monadics quotations prettyprint ; [ + ] 6 right <$> 1 right <*> .
T{ Right { value 7 } }


For the curious...
"Lifted partially applied function" actually means "A datastructure of incomplete quotations":
USING: arrays monadics ; { 1 4 7 } [ 3array ] fmap .
{ [ 1 3array ] [ 4 3array ] [ 7 3array ] }

Unlike in e.g. Haskell, <$> is not a direct alias of fmap, as Factor's stack based nature means that using fmap directly for applicative style code would result in inputs being reversed.