/solutions
directory before attempting the recipes yourself. The forest comes before the machete.
- Download repo
git clone git@github.com:manuscriptmastr/fp-workshop.git
cd fp-workshop
- Install Node 14 (this package uses modules)
nvm install 14
nvm use 14
- Install package dependencies
npm install
# Run test suite
npm run test
# Run only contents of playground.js
npm run playground
playground.js
is just a blank "notepad" for you can follow along the workshop or jot down ideas/experiments. You can execute it with npm run playground
.
To practice a recipe, navigate to {recipe}/index.test.js
and replace the line import {recipe} from '../solutions/{recipe}'
with import {recipe} from '.'
Run npm run test
and tests should fail. Define your recipe in {recipe}/index.js
until all tests pass!
If you get stumped, you can always refer to solutions/{recipe}.js
. But who does that help 🤷♂️?
- Ramda is an auto-curried utility library
- Sanctuary is another FP utility library (stricter than Ramda) that includes containers like
Maybe
andEither
- Assert is a super chill testing library built into Node.js
- AVA is a highly explicit and concurrent testing framework
- Nock is a sweet library for mocking highly specific HTTP responses
- What's with comments like
add :: Number -> Number -> Number
?- This is a style of writing type signatures widely adopted in the functional programming community. Don't worry if it looks bizarre now — we'll see this syntax many, many times!
- An example or test is incorrect.
- Submit an issue so we can keep this workbook up to date for posterity!
- How do I slowly build my containers without having all these failing tests?
- In
ava.config.js
, uncomment all but the container method(s) you're testing. For instance, if you're trying to makeIdentity
pass the Functor tests, you will leave only!*.map*
commented out. Restartnpm run test
and it will pick up only tests that callSomeContainer.map(...)
.
- In
- Books
- Professor Frisby's Mostly Adequate Guide to Functional Programming covers a generous amount of FP theory, like containers, category theory, and natural transformations
- JavaScript Allongé is basically the dictionary of functional recipes
- Libraries
- Fantasy Land is the official JS spec for FP libraries. Fun fact: the name of the spec was coined during a GitHub debate on whether
Promise
s should follow the definition of a Monad (such as theTask
container). Because the finalPromise
spec was a compromise between category theory and imperative flow,Promise
s cannot be cancelled unlike aTask
. - Fluture is a Fantasy Land compliant implementation of the
Task
orFuture
container. - Haxl is an open source Haskell library that Facebook uses to process some 1 million post requests for spam... per second. To simplify spam definitions, the team took advantage of FP's natural cacheability and parallelism to hide concurrency logic from the developer writing a spam rule. They wrote a paper on the container type that inspired this framework.
- Fantasy Land is the official JS spec for FP libraries. Fun fact: the name of the spec was coined during a GitHub debate on whether
- Talks
- Hey Underscore, You're Doing it Wrong! shows off how currying and composition can drastically reduce boilerplate (and bugs) while increasing reusability
- 2016 React Rally — "Oh Composable World!" experiments with FP and ReactJS
- Classroom Coding with Professor Frisby is an almost adorable video series based on Mostly Adequate Guide
- JavaScript and Our Obsession with Speed offers insights on the JS performance vs. maintainability discussion around declarative code
- A Million Ways to Fold in JS explores looping alternatives via recursion, reduction, folding, and catamorphisms