Recommended listening during read: https://open.spotify.com/track/1vBb916w3u10h8U87QJ1GN
We can convert any indexable data structure into its function form to achieve laziness. Formally, there’s an isomorphism from any Representable Functor to Reader. Gist is here: https://gist.github.com/DrBoolean/9b951c1c2cb225be9c289b0a2239132f
I boldly use words like curry (functions that take 1 arg at a time), isomorphism (a lossless transformation to/from), and functor (a type with a map method)
Recommended listening during read:
Pure functional data structures allow us to focus on the composition of complex, effectful workflows through reasoning and interchangeable instances. We can stub functions to return these types, get the composition right, then circle back to implement the functions. Also, traverse kicks ass.
To get a feel for algebraic structures see https://github.com/fantasyland/fantasy-land.
It’s no secret that I enjoy functional programming. Writing code this way typically involves two steps:
Besides the reuse, simplicity, etc, one reason I enjoy this approach is that it enables me to focus on…
Recommended listening during read: spotify:track:3bCmDqflFBHijgJfvtqev5
Lenses are pretty useful to dig deep into data structures and make changes in a pure functional way. Immutable.js and lenses are a great fit because they provide us with a universal api for working with built in and immutable data structures. We can also convert between built in and Immutable.js structures with isos which makes library interop easier.
I’m going to be assuming some knowledge of ramda, which implies understanding the basics of currying and composition. If you’re not familiar, you may want to first read http://fr.umio.us/why-ramda/
Here’s the import section for this post…
The tl;dr is that we can take functions that are concrete in their output, combine them with concat, and contramap over their input. This allows us to do cool things like combine filter predicates and sort comparisons while providing flexibility on their arguments. I ran out of acceptable blog post space, but it also is wonderfully useful when transducing.
I expect you already know what a monoid is before reading this. If not, checkout https://www.youtube.com/watch?v=JZSoPZUoR58 to get a feel for monoids as well as transducers which I’ll touch on toward the end of this post. …
Here are some simple functions to use in our tests. Two are named and curried, one is anonymous.