Skip to content

Commit 8e72f65

Browse files
chore: fix the notes links
1 parent 678373d commit 8e72f65

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

posts/2025-10-23-A-BIT-MORE-CONTRAMAP.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
A bit more contramap
22
---
33

4-
The goal of this post is to take a closer look at contramap without going into the formal world of Contravariant
5-
Functors [^1]. We’ll keep things grounded in real code and focus on how this small helper can make everyday work
4+
The goal of this post is to take a closer look at `contramap` without going into the formal world of Contravariant
5+
Functors [^1]. We’ll keep things grounded in real code and focus on how this small helper can make everyday work
66
easier to reason about.
77

8-
Imagine you’re traveling abroad. You’ve got your phone charger, the wall has its socket, and the only problem is
9-
that the plug doesn’t fit. Luckily, you packed a power adapter. It doesn’t change your charger or the wall. It
10-
simply helps one connect to the other.
8+
Imagine you’re traveling abroad. You’ve got your phone charger, the wall has its socket, and the only problem is
9+
that the plug doesn’t fit. Luckily, you packed a power adapter. It doesn’t change your charger or the wall. It
10+
simply helps one connect to the other.
1111

12-
That is the same idea behind contramap. It sits in the middle of two shapes that don’t naturally match and helps
13-
them work together without changing anything on either side. If you come from an OOP background, it might remind
12+
That is the same idea behind `contramap`. It sits in the middle of two shapes that don’t naturally match and helps
13+
them work together without changing anything on either side. If you come from an OOP background, it might remind
1414
you of the Open/Closed Principle, where you extend behavior without modifying what already works.
1515

16-
To see this in practice, let’s revisit the earlier post about composing sorting rules [^4]. This time we’ll focus
17-
on the contramap step and set aside the details about Ord. In this setup, the socket is an Ord<string> that knows
18-
how to compare strings, while your plug is a Category, which is clearly not a string. contramap becomes the adapter
16+
To see this in practice, let’s revisit the earlier post about composing sorting rules [^2]. This time we’ll focus
17+
on the `contramap` step and set aside the details about Ord. In this setup, the socket is an Ord<string> that knows
18+
how to compare strings, while your plug is a Category, which is clearly not a string. `contramap` becomes the adapter
1919
that allows the two to connect perfectly.
2020

2121
```ts
@@ -31,7 +31,7 @@ const ordCategoriesAlphabetically: Ord.Ord<Category> = pipe(
3131
The adapter here is the function that turns a `Category` into a `string`. That string is not random; it follows the
3232
rules of the domain. Once the adapter is in place, much like a power adapter, the `Categories` can now be ordered
3333
alphabetically without changing the original `Ord<string>`. The same pattern shows up in other modules. The `Predicate`
34-
module [^5] is a good example because it helps you model rules, filters, and guards that capture your business logic.
34+
module [^3] is a good example because it helps you model rules, filters, and guards that capture your business logic.
3535
These tiny pieces feel simple, but they can be used to build complex logic.
3636

3737
Let us turn that into requirements and code.
@@ -131,17 +131,13 @@ const isReviewInactive: P.Predicate<Review> = pipe(
131131

132132
Conclusion
133133

134-
contramap works like that universal adapter you carry when you travel. It bridges shapes that don’t naturally fit,
135-
keeping what already works untouched. The trick is simple but powerful: instead of changing your logic, you adapt
136-
the data to match it. Once you start thinking this way, composition stops being an abstract principle and becomes
134+
`contramap` works like that universal adapter you carry when you travel. It bridges shapes that don’t naturally fit,
135+
keeping what already works untouched. The trick is simple but powerful: instead of changing your logic, you adapt
136+
the data to match it. Once you start thinking this way, composition stops being an abstract principle and becomes
137137
a habit. You spend less time rewriting and more time connecting the pieces that are already there.
138138

139139
[^1]: https://blog.ploeh.dk/2021/09/02/contravariant-functors/
140140

141-
[^2]: https://gcanti.github.io/fp-ts
141+
[^2]: https://github.com/vidalvasconcelos/vidalvasconcelos/blob/main/posts/2025-10-10-COMPOSE-SORTING-RULES.md
142142

143-
[^3]: https://gcanti.github.io/fp-ts/modules/Option.ts.html
144-
145-
[^4]: 2025-10-10-COMPOSE-SORTING-RULES.md
146-
147-
[^5]: https://gcanti.github.io/fp-ts/modules/Predicate.ts.html
143+
[^3]: https://gcanti.github.io/fp-ts/modules/Predicate.ts.html

0 commit comments

Comments
 (0)