Lesson 38 of 55
10 mins readPython Applicative Functors: pure & (<*>)
In Plain English
Applicative Functors sit between Functors and Monads. They allow applying functions that are themselves inside a context (f (a -> b)) to wrapped arguments (f a).
Deep Dive: How It Works
class (Functor f) => Applicative f where pure :: a -> f a; (<*>) :: f (a -> b) -> f a -> f b.
Lifting: pure (+) <*> Just 3 <*> Just 5 evaluates to Just 8.
Idiom: f <$> arg1 <*> arg2 applies a normal multi-argument function f over wrapped contexts.
Core Rules to Remember

Multi-Argument Context Application: Combine multiple wrapped values with standard pure functions.

f <$> a <*> b: The standard idiom for applying functions across independent computations.
Live Interactive Example
Hit Run Code to see it liveCombining Multiple Wrapped Values with Applicative
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Output Console
Click "Run Code" to view the rendered output.
How it works: (+) <$> Just 10 <*> Just 20 extracted 10 and 20 and returned Just 30.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Multiply Two Maybes with Applicative
Compute `(*) <$> Just 6 <*> Just 7`.
Print `"Product: "` followed by the result.
1
2
3
4
5
6
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.