Re:Show HN: Koda, a typesafe functional toolkit for Python
by zestyping on Monday February 07, 2022 @04:27PM
(#30251452)
I was pretty puzzled by the method name "map" in the examples. Why would you call it "map" when there are no arrays or lists involved?
[ Parent
| on HN ]
Re:Show HN: Koda, a typesafe functional toolkit for Python
by CodeAndCuffs on Monday February 07, 2022 @04:42PM
(#30251701)
x.map(f) doesnt mean "apply function f to each element in this list that we called x"
x.map(f) means "apply the function f to the value within x, where x is a container of some sort"
[].map(f) would do nothing, because there is nothing to pull out.
['adam', 'bill'].map(f) takes 'adam' out of the array, applies f to it, and puts it back in the array, then does the same with 'bill'.
Just(5).map(f) takes 5 out of the Maybe, applies f to it, and puts it back in
nothing.map(f) returns nothing.
So we can map functions to values in Arrays, map functions to values in Maybes and even map functions to values in Eithers. Each time the function doesnt care that the value is in a Maybe or an Array or an Either.
Re:Show HN: Koda, a typesafe functional toolkit for Python
by growlfrench on Monday February 07, 2022 @06:42PM
(#30253125)
Brian Lonsdorf has a fun course where he explains these things:
https://egghead.io/courses/professor-frisby-introduces-compo...
Re:Show HN: Koda, a typesafe functional toolkit for Python
by RyEgswuCsn on Monday February 07, 2022 @04:30PM
(#30251505)
Because of the mathematical "map" [0] perhaps?
Re:Show HN: Koda, a typesafe functional toolkit for Python
by r-zip on Tuesday February 08, 2022 @10:28AM
(#30259517)
Because the Result and Maybe types in the examples are functors: https://en.wikipedia.org/wiki/Functor_(functional_programmin...
Re:Show HN: Koda, a typesafe functional toolkit for Python
by cheriot on Monday February 07, 2022 @04:34PM
(#30251559)
Are you thinking about Maybe.map in particular? It's the same name because it does the same thing: run this function on the value inside if there is one. It's a Functor :)
Re:Show HN: Koda, a typesafe functional toolkit for Python
by dragonwriter on Monday February 07, 2022 @04:42PM
(#30251698)
A Maybe is effectively isomorphic to an immutable list whose cardinality can only be zero or one.
Re:Show HN: Koda, a typesafe functional toolkit for Python
by bobbylarrybobby on Monday February 07, 2022 @06:36PM
(#30253066)
The only requirement for something to be mappable is that it be iterable