- Functions
- First class
const getServerStuff = callback => ajaxCall(json => callback(json));
copied from Mostly Adequate Guide - Pure functions (referential transparency)
A pure function is a function that, given the same input, will always return the same output and does not have any observable side effect. Subtle example of an impure function:
let minimum = 21; const checkAge = age => age >= minimum;
- Side effects (not bad, but should be contained)
Impure functions can be made pure by wrapping them in a function (thunk):
() => Math.random()
"Dependency injection" - Partial application and currying (also mention closures?) Partial application allows "configuration" Currying helps to compose n-ary functions and may force different order of arguments
- Compose and pipe
- Total/partial functions (nice bridge to
Maybe
/Option
andEither
/Result
) - Point-free style (tacit programming) Subjective
- Hindley-Milner type signatures
- First class
- Declarative vs imperative? Expressive code (see chapter 8.1 in FP for sceptics)
- In declarative code there's fewer variables, often only at the edges of the program; data and behavior are separated
- Explain:
map()
(alsomap2()
?)of()
(a.k.a.return()
)flatMap()
(a.k.a.chain()
(?) orbind()
)apply()
(Promise.all()
is maybe a tiny bit similar?): apply a (curried) function wrapped in a monad to arguments wrapped in a monad See: https://youtu.be/d2yLsBn_Lz0?si=VBXWuNY3V0sj_5m8&t=2544 and https://ramdajs.com/docs/#apreduce()
(a.k.a.fold()
)?traverse()
?- Functor:
map()
, Applicative:of()
andapply()
, Monad:of()
andflatMap()
- Algebraic Structures (implemented by Type classes), probably also tell about types of polymorphism?
Ord
,Eq
- Functor
Array
Maybe
/Option
Either
/Result
IO
Task
- Monad
- Applicative
- Algebraic Data Types
- Sum types
- Product types
- Replace "declarative" with "expressive". And mention some advantages of FP aren't exclusive to FP.
-
<blockquote cite="https://www.thebehavioralscientist.com/glossary/familiarity-bias#:~:text=unfamiliar%20options%20may%20be%20perceived%20as%20more%20difficult%20to%20process%2C%20which%20can%20make%20them%20less%20appealing" class="font-serif italic"> …unfamiliar options may be perceived as more difficult to process, which can make them less appealing. </blockquote>
- Stratified Design
- Onion Architecture
- Use https://sli.dev/guide/syntax#shiki-magic-move
- Use https://sli.dev/guide/syntax#monaco-runner
- Rename to something like "Functional Programming in JavaScript"?
- Fix line numbers (maybe use a transformer or else use CSS?)
- Fix linting (seems TS is needed for a lot of rules)
- Make sure
"editor.bracketPairColorization.enabled": true,
is enabled in VSCode - Make sure GitHub Copilot is disabled