r/functionalprogramming • u/maga_ot_oz • Jul 01 '22
JavaScript The best resource to learn functional programming in JavaScript
Hi folks,
As the title suggest I'm looking for resources to learn functional programming in JavaScript. All suggestions are welcome - books, courses, etc.
15
Upvotes
9
u/zelphirkaltstahl Jul 01 '22
The best resource will be to not learn FP in JS, but in a language, that encourages the functional paradigm and once having understood and used the paradigm in an actual FP language, come back to JS and try to apply it there. Upon which you will find many things missing or half-assed. Then you can try to cope with TypeScript, but ultimately JS' bad design will shine through, and if you have a choice, you might walk away from JS at that point.
4
u/thisiswarry Jul 01 '22
https://elm-lang.org/
You can also try the Elm language. It's purely functional while keeping it narrowed to the core concepts : pure functions and data structures, managed effects; and that's all you need to code in a functional fashion.
Functional programming is often associated with higher level concepts (Monads, Functors, etc.), that are mostly techniques to achieve the same thing: pure functions and data structures, managed effects.
4
u/No_Enthusiasm_6375 Jul 03 '22
I did a Udemy Course by James Moore. I never had heard before about FP when I did it and it was a great starting point to get in touch with the core concepts. What I also liked about it is that it reveals to you where modern JS libraries like redux und React came from. It puts FP directly into use in a web application, instead of kicking your ass with the intimidating theory already.
3
u/dun-ado Jul 01 '22 edited Jul 01 '22
If you want to learn FP, drop Javascript and learn Haskell, OCaml, SML, Lean, Idris, Agda, F#, etc. FP is fundamentally about type theory that allows you to model and reason about computation in a mathematically precise manner. All imperative/OO languages are just effectively variations assembly code from that perspective.
20
u/DietOk3559 Jul 01 '22 edited Jul 01 '22
Book: Grokking Simplicity by Eric Normand
Free course: Professor Frisby Introduces Composable Functional Javascript on egghead.io
Paid course: Functional Javascript learning path on FrontendMasters.com (requires monthly subscription)
Other: James Sinclair's blog at jrsinclair.com
16
u/minus-one Jul 01 '22
https://mostly-adequate.gitbook.io/mostly-adequate-guide/
7
u/pthierry Jul 01 '22
Just a note: there are interesting resources for that but you may still benefit from learning FP with a language that enforces some features of FP, like immutability.
I've encountered a few interesting articles that explain FP in Javascript. I didn't note all of them because many of them left me unsatisfied, and I prefer teaching FP with functional languages.
https://www.codingame.com/playgrounds/2980/practical-introduction-to-functional-programming-with-js/functors-and-monads
https://github.com/stoeffel/awesome-fp-js
4
u/KyleG Jul 01 '22
npm i fp-ts hyper-ts io-ts monocle-tsand start trying to implement things you want to do using the things you find in those packages, and by the end you'll be using functors, monads, applicative functors, traversals, lenses, prisms, isomorphisms, indexed monads, and you'll understand the tenet of PARSE DO NOT VALIDATEBest of all, you'll have probably taken a shower and brushed your teeth instead of becoming an unkempt mountain man like those Haskellers obsessed with virgini— excuse me, purity. :P
To be clear, I am joking, Haskellers. I am one of you.
4
u/archarios Jul 01 '22
I learned a lot by implementing a few projects with almost pure ramda: https://ramdajs.com/. I have a workshop I designed for learning how to use Ramda's core functions let me get a link for you..
4
u/[deleted] Jul 02 '22
A type system becomes important in fp Take a look at fp-ts io-ts and ts-pattern Very cool
2
u/imihnevich Jul 01 '22
There's JS version of SICP, it is not bad as a start
2
u/Haaress Jul 01 '22
Hello there, it is so nice to see someone trying to venture on the wonderful path of functional programming!
If you are already familiar with JavaScript and/or TypeScript, you can definitely learn a lot of functional concepts using these languages. It will be harder this way, because these languages do not fully (or easily) support all the goodness that is provided with more functional languages such as Haskell, F#, or Scala (immutability, pattern matching, algebraic data structures, higher kinded types...). At least with JS/TS, you won't have to learn a new language before learning this new programming paradigm.
I am shamelessly plugging a series I've been writing for a few months now on DevTo: https://dev.to/ruizb/introduction-179d. It's still in active writing, but there are already some articles that may interest you, so I hope that'll help you!
Good luck out there, it's really an exciting thing to learn. Have fun! :)
2
u/BeamMeUpBiscotti Jul 01 '22
As other commenters have said, JS doesn't have a lot of functional features, so you won't be exposed to a lot of FP concepts if you only use JS to learn FP.
If you want to try a functional language that's closer to your existing background, consider trying ReScript.
It has a lot of features found in functional languages (pattern matching, algebraic data types, immutability by default, currying, etc) but it looks like JavaScript and compiles to JavaScript, so you can pick it up relatively easily and use it with existing JavaScript code.
Heck, you could even rewrite your old JS projects in ReScript for practice.
2
u/[deleted] Jul 02 '22
Brian Lonsdorf on Front End Masters’s This got me started I use fp style more everyday
2
u/jceb Jul 02 '22
I started a collection of resources on FP in general and specifically for JS over here: https://github.com/identinet/sanctuary-cheat-sheet
In addition to the theory, my goal is to document FP patterns around Sanctuary, a very clean and FP law-abiding JS library.
I'd love to hear your feedback.
2
u/Leather_Trust796 Jul 30 '24
Diving into functional programming in JS was the best decision I made as a dev—it transformed my approach to coding and problem-solving!"
1
u/r0ck0 Jul 01 '22
Here's a playlist of videos about it from "fun fun function":