Repository: marimo-team/learn
Pull request #92: refactor(functors): v0.1.4 of notebook functors for fp course
Author: login: ghost
Created: 2025-04-08T16:07:05Z | Merged: 2025-04-20T14:41:00Z

## 📝 Summary

+ Migrate to `python3.13`

    + Replace all occurrences of 

        ```python
        class Functor(Generic[A])
        ```

        with

        ```python
        class Functor[A]
        ```

        for conciseness

+ Use `fa` in function signatures instead of `a` when `fa` is a *Functor*
* restructure the notebook
* replace `f` in the function signatures with `g` to indicate regular functions and distinguish from functors
* move `Maybe` funtor to section `More Functor instances`
+ add `Either` functor
+ add `unzip` utility function for functors

## 📋 Checklist

- [x] I have included package dependencies in the notebook file [using `--sandbox`](https://docs.marimo.io/guides/package_reproducibility/)
- [ ] If adding a course, include a `README.md`
- [x] Keep language direct and simple.



Diff:
diff --git a/functional_programming/05_functors.py b/functional_programming/05_functors.py
index a2846b3..8954f4b 100644
--- a/functional_programming/05_functors.py
+++ b/functional_programming/05_functors.py
@@ -1,5 +1,5 @@
 # /// script
-# requires-python = ">=3.9"
+# requires-python = ">=3.13"
 # dependencies = [
 #     "marimo",
 # ]
@@ -7,7 +7,7 @@
 
 import marimo
 
-__generated_with = "0.11.17"
+__generated_with = "0.12.8"
 app = marimo.App(app_title="Category Theory and Functors")
 
 
@@ -37,7 +37,7 @@ def _(mo):
         /// details | Notebook metadata
             type: info
 
-        version: 0.1.1 | last modified: 2025-03-16 | author: [métaboulie](https://github.com/metaboulie)<br/>
+        version: 0.1.5 | last modified: 2025-04-11 | author: [métaboulie](https://github.com/metaboulie)<br/>
         reviewer: [Haleshot](https://github.com/Haleshot)
 
         ///
@@ -77,13 +77,13 @@ def _(mo):
 
         ```python
         from dataclasses import dataclass
-        from typing import Callable, Generic, TypeVar
+        from typing import TypeVar
 
         A = TypeVar("A")
         B = TypeVar("B")
 
         @dataclass
-        class Wrapper(Generic[A]):
+        class Wrapper[A]:
             value: A
         ```
 
@@ -96,49 +96,55 @@ class Wrapper(Generic[A]):
         ### Mapping Functions Over Wrapped Data
 
         To modify wrapped data while keeping it wrapped, we define an `fmap` method:
-
-        ```python
-        @dataclass
-        class Wrapper(Functor, Generic[A]):
-            value: A
-
-            @classmethod
-            def fmap(cls, f: Callable[[A], B], a: "Wrapper[A]") -> "Wrapper[B]":
-                return Wrapper(f(a.value))
-        ```
-
-        Now, we can apply transformations without unwrapping:
-
-        ```python
-        >>> Wrapper.fmap(lambda x: x + 1, wrapper)
-        Wrapper(value=2)
-
-        >>> Wrapper.fmap(lambda x: [x], wrapper)
-        Wrapper(value=[1])
-        ```
-
-        > Try using the `Wrapper` in the cell below.
         """
     )
     return
 
 
 @app.cell
-def _(A, B, Callable, Functor, Generic, dataclass, pp):
+def _(B, Callable, Functor, dataclass):
     @dataclass
-    class Wrapper(Functor, Generic[A]):
+    class Wrapper[A](Functor):
         value: A
 
         @classmethod
-        def fmap(cls, f: Callable[[A], B], a: "Wrapper[A]") -> "Wrapper[B]":
-            return Wrapper(f(a.value))
+        def fmap(cls, g: Callable[[A], B], fa: "Wrapper[A]") -> "Wrapper[B]":
+            return Wrapper(g(fa.value))
+    return (Wrapper,)
+
+
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(
+        r"""
+        /// attention
+
+        To distinguish between regular types and functors, we use the prefix `f` to indicate `Functor`.
+
+        For instance,
+
+        - `a: A` is a regular variable of type `A`
+        - `g: Callable[[A], B]` is a regular function from type `A` to `B`
+        - `fa: Functor[A]` is a *Functor* wrapping a value of type `A`  
+        - `fg: Functor[Callable[[A], B]]` is a *Functor* wrapping a function from type `A` to `B`  
+
+        and we will avoid using `f` to represent a function
+
+        ///
+
+        > Try with Wrapper below
+        """
+    )
+    return
 
 
+@app.cell
+def _(Wrapper, pp):
     wrapper = Wrapper(1)
 
     pp(Wrapper.fmap(lambda x: x + 1, wrapper))
     pp(Wrapper.fmap(lambda x: [x], wrapper))
-    return Wrapper, wrapper
+    return (wrapper,)
 
 
 @app.cell(hide_code=True)
@@ -147,14 +153,14 @@ def _(mo):
         """
         We can analyze the type signature of `fmap` for `Wrapper`:
 
-        * `f` is of type `Callable[[A], B]`
-        * `a` is of type `Wrapper[A]`
+        * `g` is of type `Callable[[A], B]`
+        * `fa` is of type `Wrapper[A]`
         * The return value is of type `Wrapper[B]`
 
         Thus, in Python's type system, we can express the type signature of `fmap` as:
 
         ```python
-        fmap(f: Callable[[A], B], a: Wrapper[A]) -> Wrapper[B]:
+        fmap(g: Callable[[A], B], fa: Wrapper[A]) -> Wrapper[B]:
         ```
 
         Essentially, `fmap`:
@@ -173,49 +179,38 @@ def _(mo):
 def _(mo):
     mo.md(
         """
-        ## The List Wrapper
+        ## The List Functor
 
         We can define a `List` class to represent a wrapped list that supports `fmap`:
-
-        ```python
-        @dataclass
-        class List(Functor, Generic[A]):
-            value: list[A]
-
-            @classmethod
-            def fmap(cls, f: Callable[[A], B], a: "List[A]") -> "List[B]":
-                return List([f(x) for x in a.value])
-        ```
-
-        Now, we can apply transformations:
-
-        ```python
-        >>> flist = List([1, 2, 3, 4])
-        >>> List.fmap(lambda x: x + 1, flist)
-        List(value=[2, 3, 4, 5])
-        >>> List.fmap(lambda x: [x], flist)
-        List(value=[[1], [2], [3], [4]])
-        ```
         """
     )
     return
 
 
 @app.cell
-def _(A, B, Callable, Functor, Generic, dataclass, pp):
+def _(B, Callable, Functor, dataclass):
     @dataclass
-    class List(Functor, Generic[A]):
+    class List[A](Functor):
         value: list[A]
 
         @classmethod
-        def fmap(cls, f: Callable[[A], B], a: "List[A]") -> "List[B]":
-            return List([f(x) for x in a.value])
+        def fmap(cls, g: Callable[[A], B], fa: "List[A]") -> "List[B]":
+            return List([g(x) for x in fa.value])
+    return (List,)
 
 
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(r"""> Try with List below""")
+    return
+
+
+@app.cell
+def _(List, pp):
     flist = List([1, 2, 3, 4])
     pp(List.fmap(lambda x: x + 1, flist))
     pp(List.fmap(lambda x: [x], flist))
-    return List, flist
+    return (flist,)
 
 
 @app.cell(hide_code=True)
@@ -227,19 +222,19 @@ def _(mo):
         The type signature of `fmap` for `List` is:
 
         ```python
-        fmap(f: Callable[[A], B], a: List[A]) -> List[B]
+        fmap(g: Callable[[A], B], fa: List[A]) -> List[B]
         ```
 
         Similarly, for `Wrapper`:
 
         ```python
-        fmap(f: Callable[[A], B], a: Wrapper[A]) -> Wrapper[B]
+        fmap(g: Callable[[A], B], fa: Wrapper[A]) -> Wrapper[B]
         ```
 
         Both follow the same pattern, which we can generalize as:
 
         ```python
-        fmap(f: Callable[[A], B], a: Functor[A]) -> Functor[B]
+        fmap(g: Callable[[A], B], fa: Functor[A]) -> Functor[B]
         ```
 
         where `Functor` can be `Wrapper`, `List`, or any other wrapper type that follows the same structure.
@@ -277,24 +272,29 @@ def _(mo):
         To define `Functor` in Python, we use an abstract base class:
 
         ```python
-        from dataclasses import dataclass
-        from typing import Callable, Generic, TypeVar
-        from abc import ABC, abstractmethod
-
-        A = TypeVar("A")
-        B = TypeVar("B")
-
         @dataclass
-        class Functor(ABC, Generic[A]):
+        class Functor[A](ABC):
             @classmethod
             @abstractmethod
-            def fmap(f: Callable[[A], B], a: "Functor[A]") -> "Functor[B]":
+            def fmap(g: Callable[[A], B], fa: "Functor[A]") -> "Functor[B]":
                 raise NotImplementedError
         ```
 
         We can now extend custom wrappers, containers, or computation contexts with this `Functor` base class, implement the `fmap` method, and apply any function.
+        """
+    )
+    return
+
 
-        Next, let's implement a more complex data structure: [RoseTree](https://en.wikipedia.org/wiki/Rose_tree).
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(
+        r"""
+        # More Functor instances (optional)
+
+        In this section, we will explore more *Functor* instances to help you build up a better comprehension.
+
+        The main reference is [Data.Functor](https://hackage.haskell.org/package/base-4.21.0.0/docs/Data-Functor.html)
         """
     )
     return
@@ -303,96 +303,147 @@ def fmap(f: Callable[[A], B], a: "Functor[A]") -> "Functor[B]":
 @app.cell(hide_code=True)
 def _(mo):
     mo.md(
+        r"""
+        ## The [Maybe](https://hackage.haskell.org/package/base-4.21.0.0/docs/Data-Maybe.html#t:Maybe) Functor
+
+        **`Maybe`** is a functor that can either hold a value (`Just(value)`) or be `Nothing` (equivalent to `None` in Python). 
+
+        - It the value exists, `fmap` applies the function to this value inside the functor.
+        - If the value is `None`, `fmap` simply returns `None`.
+
+        /// admonition
+        By using `Maybe` as a functor, we gain the ability to apply transformations (`fmap`) to potentially absent values, without having to explicitly handle the `None` case every time.
+        ///
+
+        We can implement the `Maybe` functor as:
         """
-        ## Case Study: RoseTree
+    )
+    return
 
-        A **RoseTree** is a tree where:
 
-        - Each node holds a **value**.
-        - Each node has a **list of child nodes** (which are also RoseTrees).
+@app.cell
+def _(B, Callable, Functor, dataclass):
+    @dataclass
+    class Maybe[A](Functor):
+        value: None | A
 
-        This structure is useful for representing hierarchical data, such as:
+        @classmethod
+        def fmap(cls, g: Callable[[A], B], fa: "Maybe[A]") -> "Maybe[B]":
+            return cls(None) if fa.value is None else cls(g(fa.value))
 
-        - Abstract Syntax Trees (ASTs)
-        - File system directories
-        - Recursive computations
+        def __repr__(self):
+            return "Nothing" if self.value is None else f"Just({self.value!r})"
+    return (Maybe,)
 
-        We can implement `RoseTree` by extending the `Functor` class:
 
-        ```python
-        from dataclasses import dataclass
-        from typing import Callable, Generic, TypeVar
+@app.cell
+def _(Maybe, pp):
+    pp(Maybe.fmap(lambda x: x + 1, Maybe(1)))
+    pp(Maybe.fmap(lambda x: x + 1, Maybe(None)))
+    return
 
-        A = TypeVar("A")
-        B = TypeVar("B")
 
-        @dataclass
-        class RoseTree(Functor, Generic[a]):
-    
-            value: A
-            children: list["RoseTree[A]"]
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(
+        r"""
+        ## The [Either](https://hackage.haskell.org/package/base-4.21.0.0/docs/Data-Either.html#t:Either) Functor
 
-            @classmethod
-            def fmap(cls, f: Callable[[A], B], a: "RoseTree[A]") -> "RoseTree[B]":
-                return RoseTree(
-                    f(a.value), [cls.fmap(f, child) for child in a.children]
-                )
+        The `Either` type represents values with two possibilities: a value of type `Either a b` is either `Left a` or `Right b`.
 
-            def __repr__(self) -> str:
-                return f"Node: {self.value}, Children: {self.children}"
-        ```
+        The `Either` type is sometimes used to represent a value which is **either correct or an error**; by convention, the `left` attribute is used to hold an error value and the `right` attribute is used to hold a correct value.
 
-        - The function is applied **recursively** to each node's value.
-        - The tree structure **remains unchanged**.
-        - Only the values inside the tree are modified.
+        `fmap` for `Either` will ignore Left values, but will apply the supplied function to values contained in the Right.
 
-        > Try using `RoseTree` in the cell below.
+        The implementation is:
         """
     )
     return
 
 
-@app.cell(hide_code=True)
-def _(A, B, Callable, Functor, Generic, dataclass, mo):
+@app.cell
+def _(B, Callable, Functor, Union, dataclass):
     @dataclass
-    class RoseTree(Functor, Generic[A]):
-        """
-        ### Doc: RoseTree
+    class Either[A](Functor):
+        left: A = None
+        right: A = None
+
+        def __post_init__(self):
+            if (self.left is not None and self.right is not None) or (
+                self.left is None and self.right is None
+            ):
+                raise TypeError(
+                    "Provide either the value of the left or the value of the right."
+                )
 
-        A Functor implementation of `RoseTree`, allowing transformation of values while preserving the tree structure.
+        @classmethod
+        def fmap(
+            cls, g: Callable[[A], B], fa: "Either[A]"
+        ) -> Union["Either[A]", "Either[B]"]:
+            if fa.left is not None:
+                return cls(left=fa.left)
+            return cls(right=g(fa.right))
 
-        **Attributes**
+        def __repr__(self):
+            if self.left is not None:
+                return f"Left({self.left!r})"
+            return f"Right({self.right!r})"
+    return (Either,)
 
-        - `value (A)`: The value stored in the node.
-        - `children (list[RoseTree[A]])`: A list of child nodes forming the tree structure.
 
-        **Methods:**
+@app.cell
+def _(Either):
+    print(Either.fmap(lambda x: x + 1, Either(left=TypeError("Parse Error"))))
+    print(Either.fmap(lambda x: x + 1, Either(right=1)))
+    return
 
-        - `fmap(f: Callable[[A], B], a: "RoseTree[A]") -> "RoseTree[B]"`
 
-            Applies a function to each value in the tree, producing a new `RoseTree[b]` with transformed values.
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(
+        """
+        ## The [RoseTree](https://en.wikipedia.org/wiki/Rose_tree) Functor
+
+        A **RoseTree** is a tree where:
+
+        - Each node holds a **value**.
+        - Each node has a **list of child nodes** (which are also RoseTrees).
 
-        **Implementation logic:**
+        This structure is useful for representing hierarchical data, such as:
 
-          - The function `f` is applied to the root node's `value`.
-          - Each child in `children` recursively calls `fmap`, ensuring all values in the tree are mapped.
-          - The overall tree structure remains unchanged.
+        - Abstract Syntax Trees (ASTs)
+        - File system directories
+        - Recursive computations
+
+        The implementation is:
         """
+    )
+    return
 
-        value: A
-        children: list["RoseTree[A]"]
+
+@app.cell
+def _(B, Callable, Functor, dataclass):
+    @dataclass
+    class RoseTree[A](Functor):
+        value: A  # The value stored in the node.
+        children: list[
+            "RoseTree[A]"
+        ]  # A list of child nodes forming the tree structure.
 
         @classmethod
-        def fmap(cls, f: Callable[[A], B], a: "RoseTree[A]") -> "RoseTree[B]":
+        def fmap(cls, g: Callable[[A], B], fa: "RoseTree[A]") -> "RoseTree[B]":
+            """
+            Applies a function to each value in the tree, producing a new `RoseTree[b]` with transformed values.
+
+            1. `g` is applied to the root node's `value`.
+            2. Each child in `children` recursively calls `fmap`.
+            """
             return RoseTree(
-                f(a.value), [cls.fmap(f, child) for child in a.children]
+                g(fa.value), [cls.fmap(g, child) for child in fa.children]
             )
 
         def __repr__(self) -> str:
             return f"Node: {self.value}, Children: {self.children}"
-
-
-    mo.md(RoseTree.__doc__)
     return (RoseTree,)
 
 
@@ -423,7 +474,7 @@ def _(mo):
         Translating to Python, we get:
 
         ```python
-        def fmap(func: Callable[[A], B]) -> Callable[[Functor[A]], Functor[B]]
+        def fmap(g: Callable[[A], B]) -> Callable[[Functor[A]], Functor[B]]
         ```
 
         This means that `fmap`:
@@ -433,51 +484,42 @@ def fmap(func: Callable[[A], B]) -> Callable[[Functor[A]], Functor[B]]
             - Takes a **functor** of type `Functor[A]` as input.
             - Outputs a **functor** of type `Functor[B]`.
 
-        We can implement a similar idea in Python:
-
-        ```python
-        fmap = lambda f, functor: functor.__class__.fmap(f, functor)
-        inc = lambda functor: fmap(lambda x: x + 1, functor)
-        ```
-
-        - **`fmap`**: Lifts an ordinary function (`f`) to the functor world, allowing the function to operate on the wrapped value inside the functor.
-        - **`inc`**: A specific instance of `fmap` that operates on any functor. It takes a functor, applies the function `lambda x: x + 1` to every value inside it, and returns a new functor with the updated values.
-
-        Thus, **`fmap`** transforms an ordinary function into a **function that operates on functors**, and **`inc`** is a specific case where it increments the value inside the functor.
+        Inspired by this, we can implement an `inc` function which takes a functor, applies the function `lambda x: x + 1` to every value inside it, and returns a new functor with the updated values.
+        """
+    )
+    return
 
-        ### Applying the `inc` Function to Various Functors
 
-        You can now apply `inc` to any functor like `Wrapper`, `List`, or `RoseTree`:
+@app.cell
+def _():
+    inc = lambda functor: functor.fmap(lambda x: x + 1, functor)
+    return (inc,)
 
-        ```python
-        # Applying `inc` to a Wrapper
-        wrapper = Wrapper(5)
-        inc(wrapper)  # Wrapper(value=6)
 
-        # Applying `inc` to a List
-        list_wrapper = List([1, 2, 3])
-        inc(list_wrapper)  # List(value=[2, 3, 4])
+@app.cell
+def _(flist, inc, pp, rosetree, wrapper):
+    pp(inc(wrapper))
+    pp(inc(flist))
+    pp(inc(rosetree))
+    return
 
-        # Applying `inc` to a RoseTree
-        tree = RoseTree(1, [RoseTree(2, []), RoseTree(3, [])])
-        inc(tree)  # RoseTree(value=2, children=[RoseTree(value=3, children=[]), RoseTree(value=4, children=[])])
-        ```
 
-        > Try using `fmap` in the cell below.
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(
+        r"""
+        /// admonition | exercise
+        Implement other generic functions and apply them to different *Functor* instances.
+        ///
         """
     )
     return
 
 
-@app.cell
-def _(flist, pp, rosetree, wrapper):
-    fmap = lambda f, functor: functor.__class__.fmap(f, functor)
-    inc = lambda functor: fmap(lambda x: x + 1, functor)
-
-    pp(inc(wrapper))
-    pp(inc(flist))
-    pp(inc(rosetree))
-    return fmap, inc
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(r"""# Functor laws and utility functions""")
+    return
 
 
 @app.cell(hide_code=True)
@@ -497,25 +539,20 @@ def _(mo):
         2. `fmap` should also preserve **function composition**. Applying two composed functions `g` and `h` to a functor via `fmap` should give the same result as first applying `fmap` to `g` and then applying `fmap` to `h`.
 
         /// admonition | 
-        - Any `Functor` instance satisfying the first law `(fmap id = id)` will automatically satisfy the [second law](https://github.com/quchen/articles/blob/master/second_functor_law.mo) as well.
+        - Any `Functor` instance satisfying the first law `(fmap id = id)` will [automatically satisfy the second law](https://github.com/quchen/articles/blob/master/second_functor_law.md) as well.
         ///
+        """
+    )
+    return
 
-        ### Functor Law Verification
-
-        We can define `id` and `compose` in `Python` as below:
-
-        ```python
-        id = lambda x: x
-        compose = lambda f, g: lambda x: f(g(x))
-        ```
-
-        We can add a helper function `check_functor_law` to verify that an instance satisfies the functor laws.
 
-        ```Python
-        check_functor_law = lambda functor: repr(fmap(id, functor)) == repr(functor)
-        ```
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(
+        r"""
+        ### Functor laws verification
 
-        We can verify the functor we've defined.
+        We can define `id` and `compose` in `Python` as:
         """
     )
     return
@@ -528,12 +565,26 @@ def _():
     return compose, id
 
 
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(r"""We can add a helper function `check_functor_law` to verify that an instance satisfies the functor laws:""")
+    return
+
+
 @app.cell
-def _(fmap, id):
-    check_functor_law = lambda functor: repr(fmap(id, functor)) == repr(functor)
+def _(id):
+    check_functor_law = lambda functor: repr(functor.fmap(id, functor)) == repr(
+        functor
+    )
     return (check_functor_law,)
 
 
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(r"""We can verify the functor we've defined:""")
+    return
+
+
 @app.cell
 def _(check_functor_law, flist, pp, rosetree, wrapper):
     for functor in (wrapper, flist, rosetree):
@@ -543,202 +594,136 @@ def _(check_functor_law, flist, pp, rosetree, wrapper):
 
 @app.cell(hide_code=True)
 def _(mo):
-    mo.md(
-        """
-        And here is an `EvilFunctor`. We can verify it's not a valid `Functor`.
-
-        ```python
-        @dataclass
-        class EvilFunctor(Functor, Generic[A]):
-            value: list[A]
-
-            @classmethod
-            def fmap(cls, f: Callable[[A], B], a: "EvilFunctor[A]") -> "EvilFunctor[B]":
-                return (
-                    cls([a.value[0]] * 2 + list(map(f, a.value[1:])))
-                    if a.value
-                    else []
-                )
-        ```
-        """
-    )
+    mo.md("""And here is an `EvilFunctor`. We can verify it's not a valid `Functor`.""")
     return
 
 
 @app.cell
-def _(A, B, Callable, Functor, Generic, check_functor_law, dataclass, pp):
+def _(B, Callable, Functor, dataclass):
     @dataclass
-    class EvilFunctor(Functor, Generic[A]):
+    class EvilFunctor[A](Functor):
         value: list[A]
 
         @classmethod
         def fmap(
-            cls, f: Callable[[A], B], a: "EvilFunctor[A]"
+            cls, g: Callable[[A], B], fa: "EvilFunctor[A]"
         ) -> "EvilFunctor[B]":
             return (
-                cls([a.value[0]] * 2 + [f(x) for x in a.value[1:]])
-                if a.value
+                cls([fa.value[0]] * 2 + [g(x) for x in fa.value[1:]])
+                if fa.value
                 else []
             )
+    return (EvilFunctor,)
 
 
+@app.cell
+def _(EvilFunctor, check_functor_law, pp):
     pp(check_functor_law(EvilFunctor([1, 2, 3, 4])))
-    return (EvilFunctor,)
+    return
 
 
 @app.cell(hide_code=True)
 def _(mo):
     mo.md(
-        """
-        ## Final definition of Functor
-
-        We can now draft the final definition of `Functor` with some utility functions.
+        r"""
+        ## Utility functions
 
-        ```Python
-            @classmethod
-            @abstractmethod
-            def fmap(cls, f: Callable[[A], B], a: "Functor[A]") -> "Functor[B]":
-                return NotImplementedError
+        ```python
+        @classmethod
+        def const(cls, fa: "Functor[A]", b: B) -> "Functor[B]":
+            return cls.fmap(lambda _: b, fa)
 
-            @classmethod
-            def const_fmap(cls, a: "Functor[A]", b: B) -> "Functor[B]":
-                return cls.fmap(lambda _: b, a)
+        @classmethod
+        def void(cls, fa: "Functor[A]") -> "Functor[None]":
+            return cls.const(fa, None)
 
-            @classmethod
-            def void(cls, a: "Functor[A]") -> "Functor[None]":
-                return cls.const_fmap(a, None)
+        @classmethod
+        def unzip(
+            cls, fab: "Functor[tuple[A, B]]"
+        ) -> tuple["Functor[A]", "Functor[B]"]:
+            return cls.fmap(lambda p: p[0], fab), cls.fmap(lambda p: p[1], fab)
         ```
+
+        - `const` replaces all values inside a functor with a constant `b`
+        - `void` is equivalent to `const(fa, None)`, transforming all values in a functor into `None`
+        - `unzip` is a generalization of the regular *unzip* on a list of pairs
         """
     )
     return
 
 
-@app.cell(hide_code=True)
-def _(A, ABC, B, Callable, Generic, abstractmethod, dataclass, mo):
-    @dataclass
-    class Functor(ABC, Generic[A]):
-        """
-        ### Doc: Functor
-
-        A generic interface for types that support mapping over their values.
-
-        **Methods:**
-
-        - `fmap(f: Callable[[A], B], a: Functor[A]) -> Functor[B]`
-          Abstract method to apply a function to all values inside a functor.
-
-        - `const_fmap(a: "Functor[A]", b: B) -> Functor[B]`
-          Replaces all values inside a functor with a constant `b`, preserving the original structure.
-
-        - `void(a: "Functor[A]") -> Functor[None]`
-          Equivalent to `const_fmap(a, None)`, transforming all values in a functor into `None`.
-        """
-
-        @classmethod
-        @abstractmethod
-        def fmap(cls, f: Callable[[A], B], a: "Functor[A]") -> "Functor[B]":
-            return NotImplementedError
+@app.cell
+def _(List, Maybe):
+    print(Maybe.const(Maybe(0), 1))
+    print(Maybe.const(Maybe(None), 1))
+    print(List.const(List([1, 2, 3, 4]), 1))
+    return
 
-        @classmethod
-        def const_fmap(cls, a: "Functor[A]", b: B) -> "Functor[B]":
-            return cls.fmap(lambda _: b, a)
 
-        @classmethod
-        def void(cls, a: "Functor[A]") -> "Functor[None]":
-            return cls.const_fmap(a, None)
+@app.cell
+def _(List, Maybe):
+    print(Maybe.void(Maybe(1)))
+    print(List.void(List([1, 2, 3])))
+    return
 
 
-    mo.md(Functor.__doc__)
-    return (Functor,)
+@app.cell
+def _(List, Maybe):
+    print(Maybe.unzip(Maybe(("Hello", "World"))))
+    print(List.unzip(List([("I", "love"), ("really", "λ")])))
+    return
 
 
 @app.cell(hide_code=True)
 def _(mo):
-    mo.md("""> Try with utility functions in the cell below""")
+    mo.md(
+        r"""
+        /// admonition
+        You can always override these utility functions with a more efficient implementation for specific instances.
+        ///
+        """
+    )
     return
 
 
 @app.cell
 def _(List, RoseTree, flist, pp, rosetree):
-    pp(RoseTree.const_fmap(rosetree, "λ"))
+    pp(RoseTree.const(rosetree, "λ"))
     pp(RoseTree.void(rosetree))
-    pp(List.const_fmap(flist, "λ"))
+    pp(List.const(flist, "λ"))
     pp(List.void(flist))
     return
 
 
 @app.cell(hide_code=True)
 def _(mo):
-    mo.md(
-        """
-        ## Functors for Non-Iterable Types
-
-        In the previous examples, we implemented functors for **iterables**, like `List` and `RoseTree`, which are inherently **iterable types**. This is a natural fit for functors, as iterables can be mapped over.
-
-        However, **functors are not limited to iterables**. There are cases where we want to apply the concept of functors to types that are not inherently iterable, such as types that represent optional values, computations, or other data structures.
-
-        ### The Maybe Functor
-
-        One example is the **`Maybe`** type from Haskell, which is used to represent computations that can either result in a value or no value (`Nothing`). 
-
-        We can define the `Maybe` functor as below:
-
-        ```python
-        @dataclass
-        class Maybe(Functor, Generic[A]):
-            value: None | A
-
-            @classmethod
-            def fmap(cls, f: Callable[[A], B], a: "Maybe[A]") -> "Maybe[B]":
-                return (
-                    cls(None) if a.value is None else cls(f(a.value))
-                )
-
-            def __repr__(self):
-                return "Nothing" if self.value is None else repr(self.value)
-        ```
-        """
-    )
+    mo.md("""# Formal implementation of Functor""")
     return
 
 
 @app.cell
-def _(A, B, Callable, Functor, Generic, dataclass):
+def _(ABC, B, Callable, abstractmethod, dataclass):
     @dataclass
-    class Maybe(Functor, Generic[A]):
-        value: None | A
-
+    class Functor[A](ABC):
         @classmethod
-        def fmap(cls, f: Callable[[A], B], a: "Maybe[A]") -> "Maybe[B]":
-            return cls(None) if a.value is None else cls(f(a.value))
-
-        def __repr__(self):
-            return "Nothing" if self.value is None else repr(self.value)
-    return (Maybe,)
-
-
-@app.cell(hide_code=True)
-def _(mo):
-    mo.md(
-        """
-        **`Maybe`** is a functor that can either hold a value or be `Nothing` (equivalent to `None` in Python). The `fmap` method applies a function to the value inside the functor, if it exists. If the value is `None` (representing `Nothing`), `fmap` simply returns `None`.
-
-        By using `Maybe` as a functor, we gain the ability to apply transformations (`fmap`) to potentially absent values, without having to explicitly handle the `None` case every time.
-
-        > Try using `Maybe` in the cell below.
-        """
-    )
-    return
+        @abstractmethod
+        def fmap(cls, g: Callable[[A], B], fa: "Functor[A]") -> "Functor[B]":
+            raise NotImplementedError("Subclasses must implement fmap")
 
+        @classmethod
+        def const(cls, fa: "Functor[A]", b: B) -> "Functor[B]":
+            return cls.fmap(lambda _: b, fa)
 
-@app.cell
-def _(Maybe, pp):
-    mint = Maybe(1)
-    mnone = Maybe(None)
+        @classmethod
+        def void(cls, fa: "Functor[A]") -> "Functor[None]":
+            return cls.const(fa, None)
 
-    pp(Maybe.fmap(lambda x: x + 1, mint))
-    pp(Maybe.fmap(lambda x: x + 1, mnone))
-    return mint, mnone
+        @classmethod
+        def unzip(
+            cls, fab: "Functor[tuple[A, B]]"
+        ) -> tuple["Functor[A]", "Functor[B]"]:
+            return cls.fmap(lambda p: p[0], fab), cls.fmap(lambda p: p[1], fab)
+    return (Functor,)
 
 
 @app.cell(hide_code=True)
@@ -815,7 +800,7 @@ def _(mo):
         Remember that we defined the `id` and `compose` function above as:
 
         ```Python
-        def id(x: Generic[A]) -> Generic[A]:
+        def id(x: A) -> A:
             return x
 
         def compose(f: Callable[[B], C], g: Callable[[A], B]) -> Callable[[A], C]:
@@ -887,20 +872,20 @@ def _(mo):
 
         Remember that a functor has two parts: it maps objects in one category to objects in another and morphisms in the first category to morphisms in the second. 
 
-        Functors in Python are from `Py` to `func`, where `func` is the subcategory of `Py` defined on just that functor's types. E.g. the RoseTree functor goes from `Py` to `RoseTree`, where `RoseTree` is the category containing only RoseTree types, that is, `RoseTree[T]` for any type `T`. The morphisms in `RoseTree` are functions defined on RoseTree types, that is, functions `Callable[[RoseTree[T]], RoseTree[U]]` for types `T`, `U`.
+        Functors in Python are from `Py` to `Func`, where `Func` is the subcategory of `Py` defined on just that functor's types. E.g. the RoseTree functor goes from `Py` to `RoseTree`, where `RoseTree` is the category containing only RoseTree types, that is, `RoseTree[T]` for any type `T`. The morphisms in `RoseTree` are functions defined on RoseTree types, that is, functions `Callable[[RoseTree[T]], RoseTree[U]]` for types `T`, `U`.
 
         Recall the definition of `Functor`:
 
         ```Python
         @dataclass
-        class Functor(ABC, Generic[A])
+        class Functor[A](ABC)
         ```
 
         And RoseTree: 
 
         ```Python
         @dataclass
-        class RoseTree(Functor, Generic[A])
+        class RoseTree[A](Functor)
         ```
 
         **Here's the key part:** the _type constructor_ `RoseTree` takes any type `T` to a new type, `RoseTree[T]`. Also, `fmap` restricted to `RoseTree` types takes a function `Callable[[A], B]` to a function `Callable[[RoseTree[A]], RoseTree[B]]`.
@@ -928,8 +913,13 @@ def _(mo):
 
         Once again there are a few axioms that functors have to obey. 
 
-        1. Given an identity morphism $id_A$ on an object $A$, $F ( id_A )$ must be the identity morphism on $F ( A )$, i.e.: ${\displaystyle F(\operatorname {id} _{A})=\operatorname {id} _{F(A)}}$
-        2. Functors must distribute over morphism composition, i.e. ${\displaystyle F(f\circ g)=F(f)\circ F(g)}$
+        1. Given an identity morphism $id_A$ on an object $A$, $F ( id_A )$ must be the identity morphism on $F ( A )$.:
+
+        $$F({id} _{A})={id} _{F(A)}$$
+
+        3. Functors must distribute over morphism composition.
+
+        $$F(f\circ g)=F(f)\circ F(g)$$
         """
     )
     return
@@ -939,22 +929,22 @@ def _(mo):
 def _(mo):
     mo.md(
         """
-        Remember that we defined the `fmap`, `id` and `compose` as 
+        Remember that we defined the `id` and `compose` as 
         ```python
-        fmap = lambda f, functor: functor.__class__.fmap(f, functor)  
         id = lambda x: x
         compose = lambda f, g: lambda x: f(g(x))
         ```
 
-        Let's prove that `fmap` is a functor.
+        We can define `fmap` as: 
 
-        First, let's define a `Category` for a specific `Functor`. We choose to define the `Category` for the `Wrapper` as `WrapperCategory` here for simplicity, but remember that `Wrapper` can be any `Functor`(i.e. `List`, `RoseTree`, `Maybe` and more):
-
-        **Notice that** in this case, we can actually view `fmap` as:
         ```python
-        fmap = lambda f, functor: functor.fmap(f, functor)  
+        fmap = lambda g, functor: functor.fmap(g, functor)  
         ```
 
+        Let's prove that `fmap` is a functor.
+
+        First, let's define a `Category` for a specific `Functor`. We choose to define the `Category` for the `Wrapper` as `WrapperCategory` here for simplicity, but remember that `Wrapper` can be any `Functor`(i.e. `List`, `RoseTree`, `Maybe` and more):
+
         We define `WrapperCategory` as:
 
         ```python
@@ -977,12 +967,12 @@ def compose(
 
         ```Python
         @dataclass
-        class Wrapper(Functor, Generic[A]):
+        class Wrapper[A](Functor):
             value: A
 
             @classmethod
-            def fmap(cls, f: Callable[[A], B], a: "Wrapper[A]") -> "Wrapper[B]":
-                return Wrapper(f(a.value))
+            def fmap(cls, g: Callable[[A], B], fa: "Wrapper[A]") -> "Wrapper[B]":
+                return Wrapper(g(fa.value))
         ```
         """
     )
@@ -1045,8 +1035,8 @@ def compose(
 
 
 @app.cell
-def _(WrapperCategory, fmap, id, pp, wrapper):
-    pp(fmap(id, wrapper) == WrapperCategory.id(wrapper))
+def _(WrapperCategory, id, pp, wrapper):
+    pp(wrapper.fmap(id, wrapper) == WrapperCategory.id(wrapper))
     return
 
 
@@ -1056,38 +1046,22 @@ def _(mo):
         """
         ## Length as a Functor
 
-        Remember that a functor is a transformation between two categories. It is not only limited to a functor from `Py` to `func`, but also includes transformations between other mathematical structures.
+        Remember that a functor is a transformation between two categories. It is not only limited to a functor from `Py` to `Func`, but also includes transformations between other mathematical structures.
 
         Let’s prove that **`length`** can be viewed as a functor. Specifically, we will demonstrate that `length` is a functor from the **category of list concatenation** to the **category of integer addition**.
 
         ### Category of List Concatenation
 
         First, let’s define the category of list concatenation:
-
-        ```python
-        @dataclass
-        class ListConcatenation(Generic[A]):
-            value: list[A]
-
-            @staticmethod
-            def id() -> "ListConcatenation[A]":
-                return ListConcatenation([])
-
-            @staticmethod
-            def compose(
-                this: "ListConcatenation[A]", other: "ListConcatenation[A]"
-            ) -> "ListConcatenation[a]":
-                return ListConcatenation(this.value + other.value)
-        ```
         """
     )
     return
 
 
 @app.cell
-def _(A, Generic, dataclass):
+def _(A, dataclass):
     @dataclass
-    class ListConcatenation(Generic[A]):
+    class ListConcatenation[A]:
         value: list[A]
 
         @staticmethod
@@ -1120,20 +1094,6 @@ def _(mo):
         ### Category of Integer Addition
 
         Now, let's define the category of integer addition:
-
-        ```python
-        @dataclass
-        class IntAddition:
-            value: int
-
-            @staticmethod
-            def id() -> "IntAddition":
-                return IntAddition(0)
-
-            @staticmethod
-            def compose(this: "IntAddition", other: "IntAddition") -> "IntAddition":
-                return IntAddition(this.value + other.value)
-        ```
         """
     )
     return
@@ -1202,18 +1162,20 @@ def _(mo):
 
         Now, let’s verify that `length` satisfies the two functor laws.
 
-        #### 1. **Identity Law**:
-        The identity law states that applying the functor to the identity element of one category should give the identity element of the other category.
+        **Identity Law**
 
-        ```python
-        > length(ListConcatenation.id()) == IntAddition.id()
-        True
-        ```
+        The identity law states that applying the functor to the identity element of one category should give the identity element of the other category.
         """
     )
     return
 
 
+@app.cell
+def _(IntAddition, ListConcatenation, length, pp):
+    pp(length(ListConcatenation.id()) == IntAddition.id())
+    return
+
+
 @app.cell(hide_code=True)
 def _(mo):
     mo.md("""This ensures that the length of an empty list (identity in the `ListConcatenation` category) is `0` (identity in the `IntAddition` category).""")
@@ -1224,31 +1186,16 @@ def _(mo):
 def _(mo):
     mo.md(
         """
-        #### 2. **Composition Law**:
-        The composition law states that the functor should preserve composition. Applying the functor to a composed element should be the same as composing the functor applied to the individual elements.
+        **Composition Law**
 
-        ```python
-        > lista = ListConcatenation([1, 2])
-        > listb = ListConcatenation([3, 4])
-        > length(ListConcatenation.compose(lista, listb)) == IntAddition.compose(
-        >     length(lista), length(listb)
-        > )
-        True
-        ```
+        The composition law states that the functor should preserve composition. Applying the functor to a composed element should be the same as composing the functor applied to the individual elements.
         """
     )
     return
 
 
-@app.cell(hide_code=True)
-def _(mo):
-    mo.md("""This ensures that the length of the concatenation of two lists is the same as the sum of the lengths of the individual lists.""")
-    return
-
-
 @app.cell
 def _(IntAddition, ListConcatenation, length, pp):
-    pp(length(ListConcatenation.id()) == IntAddition.id())
     lista = ListConcatenation([1, 2])
     listb = ListConcatenation([3, 4])
     pp(
@@ -1258,6 +1205,193 @@ def _(IntAddition, ListConcatenation, length, pp):
     return lista, listb
 
 
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md("""This ensures that the length of the concatenation of two lists is the same as the sum of the lengths of the individual lists.""")
+    return
+
+
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(
+        r"""
+        # Bifunctor
+
+        A `Bifunctor` is a type constructor that takes two type arguments and **is a functor in both arguments.** 
+
+        For example, think about `Either`'s usual `Functor` instance. It only allows you to fmap over the second type parameter: `right` values get mapped, `left` values stay as they are.
+
+        However, its `Bifunctor` instance allows you to map both halves of the sum.
+
+        There are three core methods for `Bifunctor`: 
+
+        - `bimap` allows mapping over both type arguments at once.
+        - `first` and `second` are also provided for mapping over only one type argument at a time.
+
+
+        The abstraction of `Bifunctor` is: 
+        """
+    )
+    return
+
+
+@app.cell
+def _(ABC, B, Callable, D, dataclass, f, id):
+    @dataclass
+    class Bifunctor[A, C](ABC):
+        @classmethod
+        def bimap(
+            cls, g: Callable[[A], B], h: Callable[[C], D], fa: "Bifunctor[A, C]"
+        ) -> "Bifunctor[B, D]":
+            return cls.first(f, cls.second(g, fa))
+
+        @classmethod
+        def first(
+            cls, g: Callable[[A], B], fa: "Bifunctor[A, C]"
+        ) -> "Bifunctor[B, C]":
+            return cls.bimap(g, id, fa)
+
+        @classmethod
+        def second(
+            cls, g: Callable[[B], C], fa: "Bifunctor[A, B]"
+        ) -> "Bifunctor[A, C]":
+            return cls.bimap(id, g, fa)
+    return (Bifunctor,)
+
+
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(
+        r"""
+        /// admonition | minimal implementation requirement
+        - `bimap` or both `first` and `second`
+        ///
+        """
+    )
+    return
+
+
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(r"""## Instances of Bifunctor""")
+    return
+
+
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(
+        r"""
+        ### The Either Bifunctor
+
+        For the `Either Bifunctor`, we allow it to map a function over the `left` value as well.
+
+        Notice that, the `Either Bifunctor`  still only contains the `left` value or the `right` value.
+        """
+    )
+    return
+
+
+@app.cell
+def _(B, Bifunctor, Callable, D, dataclass):
+    @dataclass
+    class BiEither[A, C](Bifunctor):
+        left: A = None
+        right: C = None
+
+        def __post_init__(self):
+            if (self.left is not None and self.right is not None) or (
+                self.left is None and self.right is None
+            ):
+                raise TypeError(
+                    "Provide either the value of the left or the value of the right."
+                )
+
+        @classmethod
+        def bimap(
+            cls, g: Callable[[A], B], h: Callable[[C], D], fa: "BiEither[A, C]"
+        ) -> "BiEither[B, D]":
+            if fa.left is not None:
+                return cls(left=g(fa.left))
+            return cls(right=h(fa.right))
+
+        def __repr__(self):
+            if self.left is not None:
+                return f"Left({self.left!r})"
+            return f"Right({self.right!r})"
+    return (BiEither,)
+
+
+@app.cell
+def _(BiEither):
+    print(BiEither.bimap(lambda x: x + 1, lambda x: x * 2, BiEither(left=1)))
+    print(BiEither.bimap(lambda x: x + 1, lambda x: x * 2, BiEither(right=2)))
+    print(BiEither.first(lambda x: x + 1, BiEither(left=1)))
+    print(BiEither.first(lambda x: x + 1, BiEither(right=2)))
+    print(BiEither.second(lambda x: x + 1, BiEither(left=1)))
+    print(BiEither.second(lambda x: x + 1, BiEither(right=2)))
+    return
+
+
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(
+        r"""
+        ### The 2d Tuple Bifunctor
+
+        For 2d tuples, we simply expect `bimap` to map 2 functions to the 2 elements in the tuple respectively.
+        """
+    )
+    return
+
+
+@app.cell
+def _(B, Bifunctor, Callable, D, dataclass):
+    @dataclass
+    class BiTuple[A, C](Bifunctor):
+        value: tuple[A, C]
+
+        @classmethod
+        def bimap(
+            cls, g: Callable[[A], B], h: Callable[[C], D], fa: "BiTuple[A, C]"
+        ) -> "BiTuple[B, D]":
+            return cls((g(fa.value[0]), h(fa.value[1])))
+    return (BiTuple,)
+
+
+@app.cell
+def _(BiTuple):
+    print(BiTuple.bimap(lambda x: x + 1, lambda x: x * 2, BiTuple((1, 2))))
+    print(BiTuple.first(lambda x: x + 1, BiTuple((1, 2))))
+    print(BiTuple.second(lambda x: x + 1, BiTuple((1, 2))))
+    return
+
+
+@app.cell(hide_code=True)
+def _(mo):
+    mo.md(
+        r"""
+        ## Bifunctor laws
+
+        The only law we need to follow is
+
+        ```python
+        bimap(id, id, fa) == id(fa)
+        ```
+
+        and then other laws are followed automatically.
+        """
+    )
+    return
+
+
+@app.cell
+def _(BiEither, BiTuple, id):
+    print(BiEither.bimap(id, id, BiEither(left=1)) == id(BiEither(left=1)))
+    print(BiEither.bimap(id, id, BiEither(right=1)) == id(BiEither(right=1)))
+    print(BiTuple.bimap(id, id, BiTuple((1, 2))) == id(BiTuple((1, 2))))
+    return
+
+
 @app.cell(hide_code=True)
 def _(mo):
     mo.md(
@@ -1265,17 +1399,17 @@ def _(mo):
         # Further reading
 
         - [The Trivial Monad](http://blog.sigfpe.com/2007/04/trivial-monad.html)
-        - [Haskellwiki. Category Theory](https://en.wikibooks.org/wiki/Haskell/Category_theory)
-        - [Haskellforall. The Category Design Pattern](https://www.haskellforall.com/2012/08/the-category-design-pattern.html)
-        - [Haskellforall. The Functor Design Pattern](https://www.haskellforall.com/2012/09/the-functor-design-pattern.html)
+        - [Haskellforall: The Category Design Pattern](https://www.haskellforall.com/2012/08/the-category-design-pattern.html)
+        - [Haskellforall: The Functor Design Pattern](https://www.haskellforall.com/2012/09/the-functor-design-pattern.html)
 
             /// attention | ATTENTION 
             The functor design pattern doesn't work at all if you aren't using categories in the first place. This is why you should structure your tools using the compositional category design pattern so that you can take advantage of functors to easily mix your tools together. 
             ///
 
-        - [Haskellwiki. Functor](https://wiki.haskell.org/index.php?title=Functor)
-        - [Haskellwiki. Typeclassopedia#Functor](https://wiki.haskell.org/index.php?title=Typeclassopedia#Functor)
-        - [Haskellwiki. Typeclassopedia#Category](https://wiki.haskell.org/index.php?title=Typeclassopedia#Category)
+        - [Haskellwiki: Functor](https://wiki.haskell.org/index.php?title=Functor)
+        - [Haskellwiki: Typeclassopedia#Functor](https://wiki.haskell.org/index.php?title=Typeclassopedia#Functor)
+        - [Haskellwiki: Typeclassopedia#Category](https://wiki.haskell.org/index.php?title=Typeclassopedia#Category)
+        - [Haskellwiki: Category Theory](https://en.wikibooks.org/wiki/Haskell/Category_theory)
         """
     )
     return
@@ -1296,9 +1430,9 @@ def _():
 @app.cell(hide_code=True)
 def _():
     from dataclasses import dataclass
-    from typing import Callable, Generic, TypeVar
+    from typing import Callable, TypeVar, Union
     from pprint import pp
-    return Callable, Generic, TypeVar, dataclass, pp
+    return Callable, TypeVar, Union, dataclass, pp
 
 
 @app.cell(hide_code=True)
@@ -1306,7 +1440,8 @@ def _(TypeVar):
     A = TypeVar("A")
     B = TypeVar("B")
     C = TypeVar("C")
-    return A, B, C
+    D = TypeVar("D")
+    return A, B, C, D
 
 
 if __name__ == "__main__":
diff --git a/functional_programming/06_applicatives.py b/functional_programming/06_applicatives.py
index c8028ac..ce10022 100644
--- a/functional_programming/06_applicatives.py
+++ b/functional_programming/06_applicatives.py
@@ -7,12 +7,12 @@
 
 import marimo
 
-__generated_with = "0.12.4"
+__generated_with = "0.12.9"
 app = marimo.App(app_title="Applicative programming with effects")
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         # Applicative programming with effects
@@ -26,24 +26,25 @@ def _(mo):
 
         In this notebook, you will learn:
 
-        1. How to view `applicative` as multi-functor.
+        1. How to view `Applicative` as multi-functor intuitively.
         2. How to use `lift` to simplify chaining application.
         3. How to bring *effects* to the functional pure world.
-        4. How to view `applicative` as lax monoidal functor.
+        4. How to view `Applicative` as a lax monoidal functor.
+        5. How to use `Alternative` to amalgamate multiple computations into a single computation.
 
         /// details | Notebook metadata
             type: info
 
-        version: 0.1.2 | last modified: 2025-04-07 | author: [métaboulie](https://github.com/metaboulie)<br/>
+        version: 0.1.3 | last modified: 2025-04-16 | author: [métaboulie](https://github.com/metaboulie)<br/>
+        reviewer: [Haleshot](https://github.com/Haleshot)
 
         ///
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         # The intuition: [Multifunctor](https://arxiv.org/pdf/2401.14286)
@@ -67,17 +68,16 @@ def _(mo):
         And we have to declare a special version of the functor class for each case.
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         ## Defining Multifunctor
 
         /// admonition
-        we use prefix `f` rather than `ap` to indicate *Applicative Functor* 
+        we use prefix `f` rather than `ap` to indicate *Applicative Functor*
         ///
 
         As a result, we may want to define a single `Multifunctor` such that:
@@ -111,11 +111,10 @@ def _(mo):
         ```
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         ## Pure, apply and lift
@@ -134,7 +133,7 @@ def _(mo):
             # or if we have a regular function `g`
             g: Callable[[A], B]
             # then we can have `fg` as
-            fg: Applicative[Callable[[A], B]] = pure(g) 
+            fg: Applicative[Callable[[A], B]] = pure(g)
             ```
 
         2. `apply`: applies a function inside an applicative functor to a value inside an applicative functor
@@ -154,11 +153,10 @@ def _(mo):
         ```
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         /// admonition | How to use *Applicative* in the manner of *Multifunctor*
@@ -174,7 +172,7 @@ def _(mo):
 
         ///
 
-        /// attention | You can suppress the chaining application of `apply` and `pure` as: 
+        /// attention | You can suppress the chaining application of `apply` and `pure` as:
 
         ```python
         apply(pure(g), fa) -> lift(g, fa)
@@ -185,11 +183,10 @@ def _(mo):
         ///
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         ## Abstracting applicatives
@@ -202,14 +199,14 @@ class Applicative[A](Functor, ABC):
             @classmethod
             @abstractmethod
             def pure(cls, a: A) -> "Applicative[A]":
-                return NotImplementedError
+                raise NotImplementedError("Subclasses must implement pure")
 
             @classmethod
             @abstractmethod
             def apply(
                 cls, fg: "Applicative[Callable[[A], B]]", fa: "Applicative[A]"
             ) -> "Applicative[B]":
-                return NotImplementedError
+                raise NotImplementedError("Subclasses must implement apply")
 
             @classmethod
             def lift(cls, f: Callable, *args: "Applicative") -> "Applicative":
@@ -228,17 +225,15 @@ def lift(cls, f: Callable, *args: "Applicative") -> "Applicative":
         ///
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(r"""# Instances, laws and utility functions""")
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         ## Applicative instances
@@ -249,16 +244,15 @@ def _(mo):
         - apply a function inside the computation context to a value inside the computational context
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
-        ### Wrapper
+        ### The Wrapper Applicative
 
-        - `pure` should simply *wrap* an object, in the sense that: 
+        - `pure` should simply *wrap* an object, in the sense that:
 
             ```haskell
             Wrapper.pure(1) => Wrapper(value=1)
@@ -269,7 +263,6 @@ def _(mo):
         The implementation is:
         """
     )
-    return
 
 
 @app.cell
@@ -291,27 +284,25 @@ def apply(
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(r"""> try with Wrapper below""")
-    return
 
 
 @app.cell
-def _(Wrapper):
+def _(Wrapper) -> None:
     Wrapper.lift(
         lambda a: lambda b: lambda c: a + b * c,
         Wrapper(1),
         Wrapper(2),
         Wrapper(3),
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
-        ### List
+        ### The List Applicative
 
         - `pure` should wrap the object in a list, in the sense that:
 
@@ -325,7 +316,6 @@ def _(mo):
         The implementation is:
         """
     )
-    return
 
 
 @app.cell
@@ -345,31 +335,28 @@ def apply(cls, fg: "List[Callable[[A], B]]", fa: "List[A]") -> "List[B]":
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(r"""> try with List below""")
-    return
 
 
 @app.cell
-def _(List):
+def _(List) -> None:
     List.apply(
         List([lambda a: a + 1, lambda a: a * 2]),
         List([1, 2]),
     )
-    return
 
 
 @app.cell
-def _(List):
+def _(List) -> None:
     List.lift(lambda a: lambda b: a + b, List([1, 2]), List([3, 4, 5]))
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
-        ### Maybe
+        ### The Maybe Applicative
 
         - `pure` should wrap the object in a Maybe, in the sense that:
 
@@ -385,7 +372,6 @@ def _(mo):
         The implementation is:
         """
     )
-    return
 
 
 @app.cell
@@ -413,33 +399,116 @@ def __repr__(self):
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(r"""> try with Maybe below""")
-    return
 
 
 @app.cell
-def _(Maybe):
+def _(Maybe) -> None:
     Maybe.lift(
         lambda a: lambda b: a + b,
         Maybe(1),
         Maybe(2),
     )
-    return
 
 
 @app.cell
-def _(Maybe):
+def _(Maybe) -> None:
     Maybe.lift(
         lambda a: lambda b: None,
         Maybe(1),
         Maybe(2),
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
+    mo.md(
+        r"""
+        ### The Either Applicative
+
+        - `pure` should wrap the object in `Right`, in the sense that:
+
+            ```haskell
+            Either.pure(1) => Right(1)
+            ```
+
+        - `apply` should apply a function that is either on Left or Right to a value that is either on Left or Right
+            - if the function is `Left`, simply returns the `Left` of the function
+            - else `fmap` the `Right` of the function to the value
+
+        The implementation is:
+        """
+    )
+
+
+@app.cell
+def _(Applicative, B, Callable, Union, dataclass):
+    @dataclass
+    class Either[A](Applicative):
+        left: A = None
+        right: A = None
+
+        def __post_init__(self):
+            if (self.left is not None and self.right is not None) or (
+                self.left is None and self.right is None
+            ):
+                msg = "Provide either the value of the left or the value of the right."
+                raise TypeError(
+                    msg
+                )
+
+        @classmethod
+        def pure(cls, a: A) -> "Either[A]":
+            return cls(right=a)
+
+        @classmethod
+        def apply(
+            cls, fg: "Either[Callable[[A], B]]", fa: "Either[A]"
+        ) -> "Either[B]":
+            if fg.left is not None:
+                return cls(left=fg.left)
+            return cls.fmap(fg.right, fa)
+
+        @classmethod
+        def fmap(
+            cls, g: Callable[[A], B], fa: "Either[A]"
+        ) -> Union["Either[A]", "Either[B]"]:
+            if fa.left is not None:
+                return cls(left=fa.left)
+            return cls(right=g(fa.right))
+
+        def __repr__(self):
+            if self.left is not None:
+                return f"Left({self.left!r})"
+            return f"Right({self.right!r})"
+    return (Either,)
+
+
+@app.cell(hide_code=True)
+def _(mo) -> None:
+    mo.md(r"""> try with `Either` below""")
+
+
+@app.cell
+def _(Either) -> None:
+    Either.apply(Either(left=TypeError("Parse Error")), Either(right=2))
+
+
+@app.cell
+def _(Either) -> None:
+    Either.apply(
+        Either(right=lambda x: x + 1), Either(left=TypeError("Parse Error"))
+    )
+
+
+@app.cell
+def _(Either) -> None:
+    Either.apply(Either(right=lambda x: x + 1), Either(right=1))
+
+
+@app.cell(hide_code=True)
+def _(mo) -> None:
     mo.md(
         r"""
         ## Collect the list of response with sequenceL
@@ -465,17 +534,15 @@ def sequenceL(cls, fas: list["Applicative[A]"]) -> "Applicative[list[A]]":
         Let's try `sequenceL` with the instances.
         """
     )
-    return
 
 
 @app.cell
-def _(Wrapper):
+def _(Wrapper) -> None:
     Wrapper.sequenceL([Wrapper(1), Wrapper(2), Wrapper(3)])
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         /// attention
@@ -483,29 +550,25 @@ def _(mo):
         ///
         """
     )
-    return
 
 
 @app.cell
-def _(Maybe):
+def _(Maybe) -> None:
     Maybe.sequenceL([Maybe(1), Maybe(2), Maybe(None), Maybe(3)])
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(r"""The result of `sequenceL` for `List Applicative`  is the Cartesian product of the input lists, yielding all possible ordered combinations of elements from each list.""")
-    return
 
 
 @app.cell
-def _(List):
+def _(List) -> None:
     List.sequenceL([List([1, 2]), List([3]), List([5, 6, 7])])
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         ## Applicative laws
@@ -549,7 +612,7 @@ def _(mo):
           ```
           This one is the trickiest law to gain intuition for. In some sense it is expressing a sort of associativity property of `apply`.
 
-        We can add 4 helper functions to `Applicative` to check whether an instance respects the laws or not: 
+        We can add 4 helper functions to `Applicative` to check whether an instance respects the laws or not:
 
         ```python
         @dataclass
@@ -588,7 +651,6 @@ def check_composition(
         > Try to validate applicative laws below
         """
     )
-    return
 
 
 @app.cell
@@ -600,7 +662,7 @@ def _():
 
 
 @app.cell
-def _(List, Wrapper):
+def _(List, Wrapper) -> None:
     print("Checking Wrapper")
     print(Wrapper.check_identity(Wrapper.pure(1)))
     print(Wrapper.check_homomorphism(1, lambda x: x + 1))
@@ -622,11 +684,10 @@ def _(List, Wrapper):
             List.pure(lambda x: x * 2), List.pure(lambda x: x + 0.1), List.pure(1)
         )
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         ## Utility functions
@@ -663,34 +724,32 @@ def revapp(
                 cls, fa: "Applicative[A]", fg: "Applicative[Callable[[A], [B]]]"
             ) -> "Applicative[B]":
                 '''
-                The first computation produces values which are provided 
-                as input to the function(s) produced by the second computation. 
+                The first computation produces values which are provided
+                as input to the function(s) produced by the second computation.
                 '''
                 return cls.lift(lambda a: lambda f: f(a), fa, fg)
         ```
 
         - `skip` sequences the effects of two Applicative computations, but **discards the result of the first**. For example, if `m1` and `m2` are instances of type `Maybe[Int]`, then `Maybe.skip(m1, m2)` is `Nothing` whenever either `m1` or `m2` is `Nothing`; but if not, it will have the same value as `m2`.
         - Likewise, `keep` sequences the effects of two computations, but **keeps only the result of the first**.
-        - `revapp` is similar to `apply`, but where the first computation produces value(s) which are provided as input to the function(s) produced by the second computation. 
+        - `revapp` is similar to `apply`, but where the first computation produces value(s) which are provided as input to the function(s) produced by the second computation.
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
-        /// admonition | exercise
+        /// admonition | Exercise
         Try to use utility functions with different instances
         ///
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         # Formal implementation of Applicative
@@ -698,7 +757,6 @@ def _(mo):
         Now, we can give the formal implementation of `Applicative`
         """
     )
-    return
 
 
 @app.cell
@@ -719,7 +777,8 @@ class Applicative[A](Functor, ABC):
         @abstractmethod
         def pure(cls, a: A) -> "Applicative[A]":
             """Lift a value into the Structure."""
-            return NotImplementedError
+            msg = "Subclasses must implement pure"
+            raise NotImplementedError(msg)
 
         @classmethod
         @abstractmethod
@@ -727,7 +786,8 @@ def apply(
             cls, fg: "Applicative[Callable[[A], B]]", fa: "Applicative[A]"
         ) -> "Applicative[B]":
             """Sequential application."""
-            return NotImplementedError
+            msg = "Subclasses must implement apply"
+            raise NotImplementedError(msg)
 
         @classmethod
         def lift(cls, f: Callable, *args: "Applicative") -> "Applicative":
@@ -757,7 +817,7 @@ def sequenceL(cls, fas: list["Applicative[A]"]) -> "Applicative[list[A]]":
                 return cls.pure([])
 
             return cls.apply(
-                cls.fmap(lambda v: lambda vs: [v] + vs, fas[0]),
+                cls.fmap(lambda v: lambda vs: [v, *vs], fas[0]),
                 cls.sequenceL(fas[1:]),
             )
 
@@ -792,21 +852,24 @@ def revapp(
             return cls.lift(lambda a: lambda f: f(a), fa, fg)
 
         @classmethod
-        def check_identity(cls, fa: "Applicative[A]"):
+        def check_identity(cls, fa: "Applicative[A]") -> bool:
             if cls.lift(id, fa) != fa:
-                raise ValueError("Instance violates identity law")
+                msg = "Instance violates identity law"
+                raise ValueError(msg)
             return True
 
         @classmethod
-        def check_homomorphism(cls, a: A, f: Callable[[A], B]):
+        def check_homomorphism(cls, a: A, f: Callable[[A], B]) -> bool:
             if cls.lift(f, cls.pure(a)) != cls.pure(f(a)):
-                raise ValueError("Instance violates homomorphism law")
+                msg = "Instance violates homomorphism law"
+                raise ValueError(msg)
             return True
 
         @classmethod
-        def check_interchange(cls, a: A, fg: "Applicative[Callable[[A], B]]"):
+        def check_interchange(cls, a: A, fg: "Applicative[Callable[[A], B]]") -> bool:
             if cls.apply(fg, cls.pure(a)) != cls.lift(lambda g: g(a), fg):
-                raise ValueError("Instance violates interchange law")
+                msg = "Instance violates interchange law"
+                raise ValueError(msg)
             return True
 
         @classmethod
@@ -815,15 +878,16 @@ def check_composition(
             fg: "Applicative[Callable[[B], C]]",
             fh: "Applicative[Callable[[A], B]]",
             fa: "Applicative[A]",
-        ):
+        ) -> bool:
             if cls.apply(fg, cls.apply(fh, fa)) != cls.lift(compose, fg, fh, fa):
-                raise ValueError("Instance violates composition law")
+                msg = "Instance violates composition law"
+                raise ValueError(msg)
             return True
     return (Applicative,)
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         # Effectful programming
@@ -833,11 +897,10 @@ def _(mo):
          The arguments are no longer just plain values but may also have effects, such as the possibility of failure, having many ways to succeed, or performing input/output actions. In this manner, applicative functors can also be viewed as abstracting the idea of **applying pure functions to effectful arguments**, with the precise form of effects that are permitted depending on the nature of the underlying functor.
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         ## The IO Applicative
@@ -846,7 +909,7 @@ def _(mo):
 
         As before, we first abstract how `pure` and `apply` should function.
 
-        - `pure` should wrap the object in an IO action, and make the object *callable* if it's not because we want to perform the action later: 
+        - `pure` should wrap the object in an IO action, and make the object *callable* if it's not because we want to perform the action later:
 
             ```haskell
             IO.pure(1) => IO(effect=lambda: 1)
@@ -858,7 +921,6 @@ def _(mo):
         The implementation is:
         """
     )
-    return
 
 
 @app.cell
@@ -881,34 +943,32 @@ def apply(cls, fg, fa):
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(r"""For example, a function that reads a given number of lines from the keyboard can be defined in applicative style as follows:""")
-    return
 
 
 @app.cell
 def _(IO):
     def get_chars(n: int = 3):
-        return IO.sequenceL(
-            [IO.pure(input(f"input the {i}th str")) for i in range(1, n + 1)]
-        )
+        return IO.sequenceL([
+            IO.pure(input(f"input the {i}th str")) for i in range(1, n + 1)
+        ])
     return (get_chars,)
 
 
 @app.cell
-def _():
+def _() -> None:
     # get_chars()()
     return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(r"""# From the perspective of category theory""")
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         ## Lax Monoidal Functor
@@ -916,7 +976,6 @@ def _(mo):
         An alternative, equivalent formulation of `Applicative` is given by
         """
     )
-    return
 
 
 @app.cell
@@ -938,10 +997,10 @@ def tensor(
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
-        Intuitively, this states that a *monoidal functor* is one which has some sort of "default shape" and which supports some sort of "combining" operation. 
+        Intuitively, this states that a *monoidal functor* is one which has some sort of "default shape" and which supports some sort of "combining" operation.
 
         - `unit` provides the identity element
         - `tensor` combines two contexts into a product context
@@ -949,14 +1008,13 @@ def _(mo):
         More technically, the idea is that `monoidal functor` preserves the "monoidal structure" given by the pairing constructor `(,)` and unit type `()`.
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
-        Furthermore, to deserve the name "monoidal", instances of Monoidal ought to satisfy the following laws, which seem much more straightforward than the traditional Applicative laws: 
+        Furthermore, to deserve the name "monoidal", instances of Monoidal ought to satisfy the following laws, which seem much more straightforward than the traditional Applicative laws:
 
         - Left identity
 
@@ -971,11 +1029,10 @@ def _(mo):
             `tensor(u, tensor(v, w)) ≅ tensor(tensor(u, v), w)`
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         /// admonition | ≅ indicates isomorphism
@@ -987,11 +1044,10 @@ def _(mo):
         ///
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         ## Mutual definability of Monoidal and Applicative
@@ -1009,11 +1065,10 @@ def _(mo):
         ```
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         ## Instance: ListMonoidal
@@ -1029,7 +1084,6 @@ def _(mo):
         The implementation is:
         """
     )
-    return
 
 
 @app.cell
@@ -1057,9 +1111,8 @@ def fmap(
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(r"""> try with `ListMonoidal` below""")
-    return
 
 
 @app.cell
@@ -1071,15 +1124,13 @@ def _(ListMonoidal):
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(r"""and we can prove that `tensor(fa, fb) = lift(lambda fa: lambda fb: (fa, fb), fa, fb)`:""")
-    return
 
 
 @app.cell
-def _(List, xs, ys):
+def _(List, xs, ys) -> None:
     List.lift(lambda fa: lambda fb: (fa, fb), List(xs.items), List(ys.items))
-    return
 
 
 @app.cell(hide_code=True)
@@ -1089,7 +1140,8 @@ class Functor[A](ABC):
         @classmethod
         @abstractmethod
         def fmap(cls, f: Callable[[A], B], a: "Functor[A]") -> "Functor[B]":
-            return NotImplementedError
+            msg = "Subclasses must implement fmap"
+            raise NotImplementedError(msg)
 
         @classmethod
         def const(cls, a: "Functor[A]", b: B) -> "Functor[B]":
@@ -1109,10 +1161,10 @@ def _():
 
 @app.cell(hide_code=True)
 def _():
-    from dataclasses import dataclass
     from abc import ABC, abstractmethod
-    from typing import TypeVar, Union
     from collections.abc import Callable
+    from dataclasses import dataclass
+    from typing import TypeVar, Union
     return ABC, Callable, TypeVar, Union, abstractmethod, dataclass
 
 
@@ -1131,7 +1183,309 @@ def _(TypeVar):
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
+    mo.md(
+        r"""
+        # From Applicative to Alternative
+
+        ## Abstracting Alternative
+
+        In our studies so far, we saw that both `Maybe` and `List` can represent computations with a varying number of results.
+
+        We use `Maybe` to indicate a computation can fail somehow and `List` for computations that can have many possible results. In both of these cases, one useful operation is amalgamating all possible results from multiple computations into a single computation.
+
+        `Alternative` formalizes computations that support:
+
+        - **Failure** (empty result)
+        - **Choice** (combination of results)
+        - **Repetition** (multiple results)
+
+        It extends `Applicative` with monoidal structure, where:
+
+        ```python
+        @dataclass
+        class Alternative[A](Applicative, ABC):
+            @classmethod
+            @abstractmethod
+            def empty(cls) -> "Alternative[A]":
+                '''Identity element for alternative computations'''
+
+            @classmethod
+            @abstractmethod
+            def alt(
+                cls, fa: "Alternative[A]", fb: "Alternative[A]"
+            ) -> "Alternative[A]":
+                '''Binary operation combining computations'''
+        ```
+
+        - `empty` is the identity element (e.g., `Maybe(None)`, `List([])`)
+        - `alt` is a combination operator (e.g., `Maybe` fallback, list concatenation)
+
+        `empty` and `alt` should satisfy the following **laws**:
+
+        ```python
+        # Left identity
+        alt(empty, fa) == fa
+        # Right identity
+        alt(fa, empty) == fa
+        # Associativity
+        alt(fa, alt(fb, fc)) == alt(alt(fa, fb), fc)
+        ```
+
+        /// admonition
+        Actually, `Alternative` is a *monoid* on `Applicative Functors`. We will talk about *monoid* and review these laws in the next notebook about `Monads`.
+        ///
+
+        /// attention | minimal implementation requirement
+        - `empty`
+        - `alt`
+        ///
+        """
+    )
+
+
+@app.cell(hide_code=True)
+def _(mo) -> None:
+    mo.md(
+        r"""
+        ## Instances of Alternative
+
+        ### The Maybe Alternative
+
+        - `empty`: the identity element of `Maybe` is `Maybe(None)`
+        - `alt`: return the first element if it's not `None`, else return the second element
+        """
+    )
+
+
+@app.cell
+def _(Alternative, Maybe, dataclass):
+    @dataclass
+    class AltMaybe[A](Maybe, Alternative):
+        @classmethod
+        def empty(cls) -> "AltMaybe[A]":
+            return cls(None)
+
+        @classmethod
+        def alt(cls, fa: "AltMaybe[A]", fb: "AltMaybe[A]") -> "AltMaybe[A]":
+            if fa.value is not None:
+                return cls(fa.value)
+            return cls(fb.value)
+
+        def __repr__(self):
+            return "Nothing" if self.value is None else f"Just({self.value!r})"
+    return (AltMaybe,)
+
+
+@app.cell
+def _(AltMaybe) -> None:
+    print(AltMaybe.empty())
+    print(AltMaybe.alt(AltMaybe(None), AltMaybe(1)))
+    print(AltMaybe.alt(AltMaybe(None), AltMaybe(None)))
+    print(AltMaybe.alt(AltMaybe(1), AltMaybe(None)))
+    print(AltMaybe.alt(AltMaybe(1), AltMaybe(2)))
+
+
+@app.cell
+def _(AltMaybe) -> None:
+    print(AltMaybe.check_left_identity(AltMaybe(1)))
+    print(AltMaybe.check_right_identity(AltMaybe(1)))
+    print(AltMaybe.check_associativity(AltMaybe(1), AltMaybe(2), AltMaybe(None)))
+
+
+@app.cell(hide_code=True)
+def _(mo) -> None:
+    mo.md(
+        r"""
+        ### The List Alternative
+
+        - `empty`: the identity element of `List` is `List([])`
+        - `alt`: return the concatenation of 2 input lists
+        """
+    )
+
+
+@app.cell
+def _(Alternative, List, dataclass):
+    @dataclass
+    class AltList[A](List, Alternative):
+        @classmethod
+        def empty(cls) -> "AltList[A]":
+            return cls([])
+
+        @classmethod
+        def alt(cls, fa: "AltList[A]", fb: "AltList[A]") -> "AltList[A]":
+            return cls(fa.value + fb.value)
+    return (AltList,)
+
+
+@app.cell
+def _(AltList) -> None:
+    print(AltList.empty())
+    print(AltList.alt(AltList([1, 2, 3]), AltList([4, 5])))
+
+
+@app.cell
+def _(AltList) -> None:
+    AltList([1])
+
+
+@app.cell
+def _(AltList) -> None:
+    AltList([1])
+
+
+@app.cell
+def _(AltList) -> None:
+    print(AltList.check_left_identity(AltList([1, 2, 3])))
+    print(AltList.check_right_identity(AltList([1, 2, 3])))
+    print(
+        AltList.check_associativity(
+            AltList([1, 2]), AltList([3, 4, 5]), AltList([6])
+        )
+    )
+
+
+@app.cell(hide_code=True)
+def _(mo) -> None:
+    mo.md(
+        r"""
+        ## some and many
+
+
+        /// admonition | This section mainly refers to
+
+        - https://stackoverflow.com/questions/7671009/some-and-many-functions-from-the-alternative-type-class/7681283#7681283
+
+        ///
+
+        First let's have a look at the implementation of `some` and `many`:
+
+        ```python
+        @classmethod
+        def some(cls, fa: "Alternative[A]") -> "Alternative[list[A]]":
+            # Short-circuit if input is empty
+            if fa == cls.empty():
+                return cls.empty()
+
+            return cls.apply(
+                cls.fmap(lambda a: lambda b: [a] + b, fa), cls.many(fa)
+            )
+
+        @classmethod
+        def many(cls, fa: "Alternative[A]") -> "Alternative[list[A]]":
+            # Directly return empty list if input is empty
+            if fa == cls.empty():
+                return cls.pure([])
+
+            return cls.alt(cls.some(fa), cls.pure([]))
+        ```
+
+        So `some f` runs `f` once, then *many* times, and conses the results. `many f` runs f *some* times, or *alternatively* just returns the empty list.
+
+        The idea is that they both run `f` as often as possible until it **fails**, collecting the results in a list. The difference is that `some f` immediately fails if `f` fails, while `many f` will still succeed and *return* the empty list in such a case. But what all this exactly means depends on how `alt` is defined.
+
+        Let's see what it does for the instances `AltMaybe` and `AltList`.
+        """
+    )
+
+
+@app.cell(hide_code=True)
+def _(mo) -> None:
+    mo.md(r"""For `AltMaybe`. `None` means failure, so some `None` fails as well and evaluates to `None` while many `None` succeeds and evaluates to `Just []`. Both `some (Just ())` and `many (Just ())` never return, because `Just ()` never fails.""")
+
+
+@app.cell
+def _(AltMaybe) -> None:
+    print(AltMaybe.some(AltMaybe.empty()))
+    print(AltMaybe.many(AltMaybe.empty()))
+
+
+@app.cell(hide_code=True)
+def _(mo) -> None:
+    mo.md(r"""For `AltList`, `[]` means failure, so `some []` evaluates to `[]` (no answers) while `many []` evaluates to `[[]]` (there's one answer and it is the empty list). Again `some [()]` and `many [()]` don't return.""")
+
+
+@app.cell
+def _(AltList) -> None:
+    print(AltList.some(AltList.empty()))
+    print(AltList.many(AltList.empty()))
+
+
+@app.cell(hide_code=True)
+def _(mo) -> None:
+    mo.md(r"""## Formal implementation of Alternative""")
+
+
+@app.cell
+def _(ABC, Applicative, abstractmethod, dataclass):
+    @dataclass
+    class Alternative[A](Applicative, ABC):
+        """A monoid on applicative functors."""
+
+        @classmethod
+        @abstractmethod
+        def empty(cls) -> "Alternative[A]":
+            msg = "Subclasses must implement empty"
+            raise NotImplementedError(msg)
+
+        @classmethod
+        @abstractmethod
+        def alt(
+            cls, fa: "Alternative[A]", fb: "Alternative[A]"
+        ) -> "Alternative[A]":
+            msg = "Subclasses must implement alt"
+            raise NotImplementedError(msg)
+
+        @classmethod
+        def some(cls, fa: "Alternative[A]") -> "Alternative[list[A]]":
+            # Short-circuit if input is empty
+            if fa == cls.empty():
+                return cls.empty()
+
+            return cls.apply(
+                cls.fmap(lambda a: lambda b: [a, *b], fa), cls.many(fa)
+            )
+
+        @classmethod
+        def many(cls, fa: "Alternative[A]") -> "Alternative[list[A]]":
+            # Directly return empty list if input is empty
+            if fa == cls.empty():
+                return cls.pure([])
+
+            return cls.alt(cls.some(fa), cls.pure([]))
+
+        @classmethod
+        def check_left_identity(cls, fa: "Alternative[A]") -> bool:
+            return cls.alt(cls.empty(), fa) == fa
+
+        @classmethod
+        def check_right_identity(cls, fa: "Alternative[A]") -> bool:
+            return cls.alt(fa, cls.empty()) == fa
+
+        @classmethod
+        def check_associativity(
+            cls, fa: "Alternative[A]", fb: "Alternative[A]", fc: "Alternative[A]"
+        ) -> bool:
+            return cls.alt(fa, cls.alt(fb, fc)) == cls.alt(cls.alt(fa, fb), fc)
+    return (Alternative,)
+
+
+@app.cell(hide_code=True)
+def _(mo) -> None:
+    mo.md(
+        r"""
+        /// admonition
+
+        We will explore more about `Alternative` in a future notebooks about [Monadic Parsing](https://www.cambridge.org/core/journals/journal-of-functional-programming/article/monadic-parsing-in-haskell/E557DFCCE00E0D4B6ED02F3FB0466093)
+
+        ///
+        """
+    )
+
+
+@app.cell(hide_code=True)
+def _(mo) -> None:
     mo.md(
         r"""
         # Further reading
@@ -1154,7 +1508,6 @@ def _(mo):
         - [Applicative Functors](https://bartoszmilewski.com/2017/02/06/applicative-functors/)
         """
     )
-    return
 
 
 if __name__ == "__main__":
diff --git a/functional_programming/CHANGELOG.md b/functional_programming/CHANGELOG.md
index 8f86c0e..4305c34 100644
--- a/functional_programming/CHANGELOG.md
+++ b/functional_programming/CHANGELOG.md
@@ -1,26 +1,90 @@
 # Changelog of the functional-programming course
 
+## 2025-04-16
+
+**applicatives.py**
+
+- replace `return NotImplementedError` with `raise NotImplementedError`
+
+- add `Either` applicative
+- Add `Alternative`
+
+## 2025-04-11
+
+**functors.py**
+
+- add `Bifunctor` section
+
+- replace `return NotImplementedError` with `raise NotImplementedError`
+
+## 2025-04-08
+
+**functors.py**
+
+- restructure the notebook
+- replace `f` in the function signatures with `g` to indicate regular functions and
+  distinguish from functors
+- move `Maybe` funtor to section `More Functor instances`
+
+- add `Either` functor
+
+- add `unzip` utility function for functors
+
 ## 2025-04-07
 
-* the `apply` method of `Maybe` *Applicative* should return `None` when `fg` or `fa` is `None`
-+ add `sequenceL` as a classmethod for `Applicative` and add examples for `Wrapper`, `Maybe`, `List`
-+ add description for utility functions of `Applicative`
-* refine the implementation of `IO` *Applicative*
-* reimplement `get_chars` with `IO.sequenceL`
-+ add an example to show that `ListMonoidal` is equivalent to `List` *Applicative*
+**applicatives.py**
+
+- the `apply` method of `Maybe` _Applicative_ should return `None` when `fg` or `fa` is
+  `None`
+
+- add `sequenceL` as a classmethod for `Applicative` and add examples for `Wrapper`,
+  `Maybe`, `List`
+- add description for utility functions of `Applicative`
+
+- refine the implementation of `IO` _Applicative_
+- reimplement `get_chars` with `IO.sequenceL`
+
+- add an example to show that `ListMonoidal` is equivalent to `List` _Applicative_
 
 ## 2025-04-06
 
-- remove `sequenceL` from `Applicative` because it should be a classmethod but can't be generically implemented
+**applicatives.py**
+
+- remove `sequenceL` from `Applicative` because it should be a classmethod but can't be
+  generically implemented
 
 ## 2025-04-02
 
-* `0.1.0` version of notebook `06_applicatives.py`
+**functors.py**
+
+- Migrate to `python3.13`
+
+    - Replace all occurrences of
+
+        ```python
+        class Functor(Generic[A])
+        ```
+
+        with
+
+        ```python
+        class Functor[A]
+        ```
+
+        for conciseness
+
+- Use `fa` in function signatures instead of `a` when `fa` is a _Functor_
+
+**applicatives.py**
+
+- `0.1.0` version of notebook `06_applicatives.py`
 
 ## 2025-03-16
 
-+ Use uppercased letters for `Generic` types, e.g. `A = TypeVar("A")`
-+ Refactor the `Functor` class, changing `fmap` and utility methods to `classmethod`
+**functors.py**
+
+- Use uppercased letters for `Generic` types, e.g. `A = TypeVar("A")`
+- Refactor the `Functor` class, changing `fmap` and utility methods to `classmethod`
 
     For example:
 
@@ -37,17 +101,24 @@
     Wrapper(value=2)
     ```
 
-+ Move the `check_functor_law` method from `Functor` class to a standard function
+- Move the `check_functor_law` method from `Functor` class to a standard function
+
 - Rename `ListWrapper` to `List` for simplicity
 - Remove the `Just` class
-+ Rewrite proofs
+
+- Rewrite proofs
 
 ## 2025-03-13
 
-* `0.1.0` version of notebook `05_functors`
+**functors.py**
 
-Thank [Akshay](https://github.com/akshayka) and [Haleshot](https://github.com/Haleshot) for reviewing
+- `0.1.0` version of notebook `05_functors`
+
+Thank [Akshay](https://github.com/akshayka) and [Haleshot](https://github.com/Haleshot)
+for reviewing
 
 ## 2025-03-11
 
-* Demo version of notebook `05_functors.py`
+**functors.py**
+
+- Demo version of notebook `05_functors.py`
diff --git a/functional_programming/README.md b/functional_programming/README.md
index 7a24789..f264dfd 100644
--- a/functional_programming/README.md
+++ b/functional_programming/README.md
@@ -1,61 +1,72 @@
 # Learn Functional Programming
 
-_🚧 This collection is a
-[work in progress](https://github.com/marimo-team/learn/issues/51)._
+_🚧 This collection is a [work in progress](https://github.com/marimo-team/learn/issues/51)._
 
 This series of marimo notebooks introduces the powerful paradigm of functional
-programming through Python. Taking inspiration from Haskell and Category Theory,
-we'll build a strong foundation in FP concepts that can transform how you
-approach software development.
+programming through Python. Taking inspiration from Haskell and Category
+Theory, we'll build a strong foundation in FP concepts that can transform how
+you approach software development.
 
 ## What You'll Learn
 
-**Using only Python's standard library**, we'll construct functional programming
-concepts from first principles.
+**Using only Python's standard library**, we'll construct functional
+programming concepts from first principles.
 
 Topics include:
 
--   Recursion and higher-order functions
--   Category theory fundamentals
--   Functors, applicatives, and monads
--   Composable abstractions for robust code
++ Currying and higher-order functions
++ Functors, Applicatives, and Monads
++ Category theory fundamentals
 
-## Timeline & Collaboration
+## Running Notebooks
 
-I'm currently studying functional programming and Haskell, estimating about 2
-months or even longer to complete this series. The structure may evolve as the
-project develops.
+### Locally
 
-If you're interested in collaborating or have questions, please reach out to me
-on Discord (@eugene.hs).
+To run a notebook locally, use
 
-**Running notebooks.** To run a notebook locally, use
-
-```bash
-uvx marimo edit <URL>
+```bash 
+uvx marimo edit <URL> 
 ```
 
 For example, run the `Functor` tutorial with
 
-```bash
+```bash 
 uvx marimo edit https://github.com/marimo-team/learn/blob/main/functional_programming/05_functors.py
 ```
 
-You can also open notebooks in our online playground by appending `marimo.app/`
-to a notebook's URL:
-[marimo.app/github.com/marimo-team/learn/blob/main/functional_programming/05_functors.py](https://marimo.app/https://github.com/marimo-team/learn/blob/main/functional_programming/05_functors.py).
+### On Our Online Playground
+
+You can also open notebooks in our online playground by appending `marimo.app/` to a notebook's URL like:
+
+https://marimo.app/https://github.com/marimo-team/learn/blob/main/functional_programming/05_functors.py
+
+### On Our Landing Page
+
+Open the notebooks in our landing page page [here](https://marimo-team.github.io/learn/functional_programming/05_functors.html)
 
-# Description of notebooks
+## Collaboration
+
+If you're interested in collaborating or have questions, please reach out to me
+on Discord (@eugene.hs).
+
+## Description of notebooks
 
 Check [here](https://github.com/marimo-team/learn/issues/51) for current series
-structure.
+structure. 
 
-| Notebook                                                                                                          | Description                                                                                                                                                                                            | References                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
-| ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| [05. Category and Functors](https://github.com/marimo-team/learn/blob/main/functional_programming/05_functors.py) | Learn why `len` is a _Functor_ from `list concatenation` to `integer addition`, how to _lift_ an ordinary function into a _computation context_, and how to write an _adapter_ between two categories. | - [The Trivial Monad](http://blog.sigfpe.com/2007/04/trivial-monad.html) <br> - [Haskellwiki. Category Theory](https://en.wikibooks.org/wiki/Haskell/Category_theory) <br> - [Haskellforall. The Category Design Pattern](https://www.haskellforall.com/2012/08/the-category-design-pattern.html) <br> - [Haskellforall. The Functor Design Pattern](https://www.haskellforall.com/2012/09/the-functor-design-pattern.html) <br> - [Haskellwiki. Functor](https://wiki.haskell.org/index.php?title=Functor) <br> - [Haskellwiki. Typeclassopedia#Functor](https://wiki.haskell.org/index.php?title=Typeclassopedia#Functor) <br> - [Haskellwiki. Typeclassopedia#Category](https://wiki.haskell.org/index.php?title=Typeclassopedia#Category) |
+| Notebook | Title | Key Concepts | Prerequisites |
+|----------|-------|--------------|---------------| 
+| [05. Functors](https://github.com/marimo-team/learn/blob/main/functional_programming/05_functors.py) | Category Theory and Functors | Category Theory, Functor, fmap, Bifunctor | Basic Python, Functions | 
+| [06. Applicatives](https://github.com/marimo-team/learn/blob/main/functional_programming/06_applicatives.py) | Applicative programming with effects | Applicative Functor, pure, apply, Effectful programming, Alternative | Functors |
 
 **Authors.**
 
 Thanks to all our notebook authors!
 
--   [métaboulie](https://github.com/metaboulie)
+- [métaboulie](https://github.com/metaboulie)
+
+**Reviewers.**
+
+Thanks to all our notebook reviews!
+
+- [Haleshot](https://github.com/Haleshot)


Reviews:
user: login: Haleshot
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-18T15:56:56Z
user: login: Haleshot
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-18T16:13:35Z
user: login: Haleshot
body: Nice changes.
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-18T16:13:54Z
user: login: Haleshot
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-18T16:19:14Z
user: login: Haleshot
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-18T16:19:58Z
user: login: Haleshot
body: Great changes on the whole!
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-04-18T17:01:22Z
user: login: Haleshot
body: LGTM! Thanks for great changes and for keeping this series going ❤️ 
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-20T14:40:49Z

Review comments:
diff_hunk: @@ -663,42 +724,39 @@ def revapp(
                 cls, fa: "Applicative[A]", fg: "Applicative[Callable[[A], [B]]]"
             ) -> "Applicative[B]":
                 '''
-                The first computation produces values which are provided 
-                as input to the function(s) produced by the second computation. 
+                The first computation produces values which are provided
+                as input to the function(s) produced by the second computation.
                 '''
                 return cls.lift(lambda a: lambda f: f(a), fa, fg)
         ```
 
         - `skip` sequences the effects of two Applicative computations, but **discards the result of the first**. For example, if `m1` and `m2` are instances of type `Maybe[Int]`, then `Maybe.skip(m1, m2)` is `Nothing` whenever either `m1` or `m2` is `Nothing`; but if not, it will have the same value as `m2`.
         - Likewise, `keep` sequences the effects of two computations, but **keeps only the result of the first**.
-        - `revapp` is similar to `apply`, but where the first computation produces value(s) which are provided as input to the function(s) produced by the second computation. 
+        - `revapp` is similar to `apply`, but where the first computation produces value(s) which are provided as input to the function(s) produced by the second computation.
         """
     )
-    return
 
 
 @app.cell(hide_code=True)
-def _(mo):
+def _(mo) -> None:
     mo.md(
         r"""
         /// admonition | exercise
path: functional_programming/06_applicatives.py
user: login: Haleshot
body: ```suggestion
        /// admonition | Exercise
```
created_at: 2025-04-18T15:56:56Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,61 +1,72 @@
 # Learn Functional Programming
 
-_🚧 This collection is a
-[work in progress](https://github.com/marimo-team/learn/issues/51)._
+_🚧 This collection is a [work in progress](https://github.com/marimo-team/learn/issues/51)._
 
 This series of marimo notebooks introduces the powerful paradigm of functional
-programming through Python. Taking inspiration from Haskell and Category Theory,
-we'll build a strong foundation in FP concepts that can transform how you
-approach software development.
+programming through Python. Taking inspiration from Haskell and Category
+Theory, we'll build a strong foundation in FP concepts that can transform how
+you approach software development.
 
 ## What You'll Learn
 
-**Using only Python's standard library**, we'll construct functional programming
-concepts from first principles.
+**Using only Python's standard library**, we'll construct functional
+programming concepts from first principles.
 
 Topics include:
 
--   Recursion and higher-order functions
--   Category theory fundamentals
--   Functors, applicatives, and monads
--   Composable abstractions for robust code
++ Currying and higher-order functions
++ Functors, Applicatives, and Monads
++ Category theory fundamentals
 
-## Timeline & Collaboration
+## Running Notebooks
 
-I'm currently studying functional programming and Haskell, estimating about 2
-months or even longer to complete this series. The structure may evolve as the
-project develops.
+### Locally
 
-If you're interested in collaborating or have questions, please reach out to me
-on Discord (@eugene.hs).
+To run a notebook locally, use
 
-**Running notebooks.** To run a notebook locally, use
-
-```bash
-uvx marimo edit <URL>
+```bash 
+uvx marimo edit <URL> 
 ```
 
 For example, run the `Functor` tutorial with
 
-```bash
+```bash 
 uvx marimo edit https://github.com/marimo-team/learn/blob/main/functional_programming/05_functors.py
 ```
 
-You can also open notebooks in our online playground by appending `marimo.app/`
-to a notebook's URL:
-[marimo.app/github.com/marimo-team/learn/blob/main/functional_programming/05_functors.py](https://marimo.app/https://github.com/marimo-team/learn/blob/main/functional_programming/05_functors.py).
+### On Our Online Playground
+
+You can also open notebooks in our online playground by appending `marimo.app/` to a notebook's URL like:
+
+https://marimo.app/https://github.com/marimo-team/learn/blob/main/functional_programming/05_functors.py
+
+### On Our Landing Page
+
+Open the notebooks in our landing page page [here](https://marimo-team.github.io/learn/functional_programming/05_functors.html)
+
+## Collaboration
+
+If you're interested in collaborating or have questions, please reach out to me
+on Discord (@eugene.hs).
 
 # Description of notebooks
path: functional_programming/README.md
user: login: Haleshot
body: ```suggestion
## Description of notebooks
```
created_at: 2025-04-18T16:13:34Z
author_association: CONTRIBUTOR
diff_hunk: @@ -543,202 +594,136 @@ def _(check_functor_law, flist, pp, rosetree, wrapper):
 
 @app.cell(hide_code=True)
 def _(mo):
-    mo.md(
-        """
-        And here is an `EvilFunctor`. We can verify it's not a valid `Functor`.
-
-        ```python
-        @dataclass
-        class EvilFunctor(Functor, Generic[A]):
-            value: list[A]
-
-            @classmethod
-            def fmap(cls, f: Callable[[A], B], a: "EvilFunctor[A]") -> "EvilFunctor[B]":
-                return (
-                    cls([a.value[0]] * 2 + list(map(f, a.value[1:])))
-                    if a.value
-                    else []
-                )
-        ```
-        """
-    )
+    mo.md("""And here is an `EvilFunctor`. We can verify it's not a valid `Functor`.""")
     return
 
 
 @app.cell
-def _(A, B, Callable, Functor, Generic, check_functor_law, dataclass, pp):
+def _(B, Callable, Functor, dataclass):
     @dataclass
-    class EvilFunctor(Functor, Generic[A]):
+    class EvilFunctor[A](Functor):
         value: list[A]
 
         @classmethod
         def fmap(
-            cls, f: Callable[[A], B], a: "EvilFunctor[A]"
+            cls, g: Callable[[A], B], fa: "EvilFunctor[A]"
         ) -> "EvilFunctor[B]":
             return (
-                cls([a.value[0]] * 2 + [f(x) for x in a.value[1:]])
-                if a.value
+                cls([fa.value[0]] * 2 + [g(x) for x in fa.value[1:]])
+                if fa.value
                 else []
             )
+    return (EvilFunctor,)
 
 
+@app.cell
+def _(EvilFunctor, check_functor_law, pp):
     pp(check_functor_law(EvilFunctor([1, 2, 3, 4])))
-    return (EvilFunctor,)
+    return
 
 
-@app.cell(hide_code=True)
path: functional_programming/05_functors.py
user: login: Haleshot
body: Any reason for unhiding this cell block?
created_at: 2025-04-18T16:19:14Z
author_association: CONTRIBUTOR
diff_hunk: @@ -543,202 +594,136 @@ def _(check_functor_law, flist, pp, rosetree, wrapper):
 
 @app.cell(hide_code=True)
 def _(mo):
-    mo.md(
-        """
-        And here is an `EvilFunctor`. We can verify it's not a valid `Functor`.
-
-        ```python
-        @dataclass
-        class EvilFunctor(Functor, Generic[A]):
-            value: list[A]
-
-            @classmethod
-            def fmap(cls, f: Callable[[A], B], a: "EvilFunctor[A]") -> "EvilFunctor[B]":
-                return (
-                    cls([a.value[0]] * 2 + list(map(f, a.value[1:])))
-                    if a.value
-                    else []
-                )
-        ```
-        """
-    )
+    mo.md("""And here is an `EvilFunctor`. We can verify it's not a valid `Functor`.""")
     return
 
 
 @app.cell
-def _(A, B, Callable, Functor, Generic, check_functor_law, dataclass, pp):
+def _(B, Callable, Functor, dataclass):
     @dataclass
-    class EvilFunctor(Functor, Generic[A]):
+    class EvilFunctor[A](Functor):
         value: list[A]
 
         @classmethod
         def fmap(
-            cls, f: Callable[[A], B], a: "EvilFunctor[A]"
+            cls, g: Callable[[A], B], fa: "EvilFunctor[A]"
         ) -> "EvilFunctor[B]":
             return (
-                cls([a.value[0]] * 2 + [f(x) for x in a.value[1:]])
-                if a.value
+                cls([fa.value[0]] * 2 + [g(x) for x in fa.value[1:]])
+                if fa.value
                 else []
             )
+    return (EvilFunctor,)
 
 
+@app.cell
+def _(EvilFunctor, check_functor_law, pp):
     pp(check_functor_law(EvilFunctor([1, 2, 3, 4])))
-    return (EvilFunctor,)
+    return
 
 
-@app.cell(hide_code=True)
+@app.cell
path: functional_programming/05_functors.py
user: login: Haleshot
body: ```suggestion
@app.cell(hide_code=True)
```
created_at: 2025-04-18T16:19:58Z
author_association: CONTRIBUTOR

PR comments:
user: login: Haleshot
created_at: 2025-04-11T07:17:30Z
body: @metaboulie Is this up for review or should I be waiting for more commits?
author_association: CONTRIBUTOR
user: login: ghost
created_at: 2025-04-11T07:40:16Z
body: @Haleshot There are some significant changes for `functors.py` in the current state, and the next few commits will be subtle. I can probably finish those commits this weekend and you can review this pr next week I suppose.
author_association: NONE
user: login: Haleshot
created_at: 2025-04-11T16:27:01Z
body: _Tracking: In relation to #51_ 
author_association: CONTRIBUTOR
user: login: ghost
created_at: 2025-04-16T14:37:49Z
body: @Haleshot This PR is stable and ready to be reviewed🥳
author_association: NONE
user: login: ghost
created_at: 2025-04-19T02:10:39Z
body: All suggestions committed, thanks for your review 
author_association: NONE