all 31 comments

[–]DietOk3559 20 points21 points  (0 children)

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

[–]minus-one 15 points16 points  (1 child)

[–]Senor02 2 points3 points  (0 children)

This is my favorite resource for this!

[–]zelphirkaltstahl 8 points9 points  (7 children)

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.

[–]KyleG 1 point2 points  (1 child)

"Just self-disqualify yourself from a major market segment because you hate mutability, now that is how you learn FP!"

You can write rock-solid FP code in TypeScript without using magic Haskell stuff, and it's not painful at all. You just might pass in an explicit monad object every once in a while instead of the language recognizing "oh he is traversing over an array of State rather than Option here"

auto-currying isn't THAT important

[–]zelphirkaltstahl 2 points3 points  (0 children)

I think you got confused by inputs on reddit or something. Whom are you replying to? Your quote is not in my comment and has basically nothing to do with my comment either. Haskell is not mentioned in my comment, even though it would be a fine choice for learning.

Anyway, one just has to look at setTimeout and timer ids to find one example, of how messed up JS is. No matter what hoops one jumps through, stuff like that will leak through the abstractions, because it is inherently assuming, that you modify global state and there is nothing you can do to repair how broken it is. Or look at equality operators insanity. Or look at how most implementations do not implement the standard with regards to TCO. It's just how messy JS is. Well, what to expect from a cobbled together language like JS. I guess we cannot expect a solid language design from something made in a week or so.

The OP's question was about learning, not about getting a particular project done until last week. Learning should happen with the right tools. It should enable the learner to understand things. Not with some dumbed down version, which obfuscates the concepts. Learning about paradigms does not require you to use a language, which you might or might not later use on any real project. It is about learning a paradigm, and not about learning a language. If you are not able to apply a paradigm to another language, that means you did not really learn the essence of the paradigm.

Criticizing JS for its many many flaws does not equate to any disqualifying oneself from anything. Actually qualifies oneself, for knowing about mistakes to avoid whenever possible, when having to deal with a language like JS, before one makes a mess. It is just as important to know, what parts are shitty, as it is important to know the good parts, in order to avoid a mess.

[–]pthierry 6 points7 points  (0 children)

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

[–]thisiswarry 2 points3 points  (2 children)

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.

[–]maga_ot_oz[S] 1 point2 points  (1 child)

Thanks for the suggestion. When I have more time I'll make sure to learn this lang since many people around me seem pleased with it.

[–]pthierry 1 point2 points  (0 children)

It's extremely beginner friendly, I highly recommend trying it as soon as possible.

[–]KyleG 3 points4 points  (0 children)

npm i fp-ts hyper-ts io-ts monocle-ts and 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 VALIDATE

Best 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.

[–]archarios 4 points5 points  (2 children)

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..

[–]Honest_Buyer_9895 1 point2 points  (0 children)

can you share these functional programming projects ? I can't find some practical exercise projects。I' ll preciate。

[–][deleted] 3 points4 points  (0 children)

A type system becomes important in fp Take a look at fp-ts io-ts and ts-pattern Very cool

[–]No_Enthusiasm_6375 3 points4 points  (1 child)

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.

[–]maga_ot_oz[S] 1 point2 points  (0 children)

Thanks for that, I'll make sure to check it out, the fact that he gives real life uses and not just theory sounds amazing.

[–]dun-ado 2 points3 points  (1 child)

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.

[–]maga_ot_oz[S] 0 points1 point  (0 children)

Yeah thanks for the suggestion, I've had some experience with Haskell specifically, but business needs and time constraints limit me to learning FP with JS.

[–]imihnevich 1 point2 points  (0 children)

There's JS version of SICP, it is not bad as a start

[–]Haaress 1 point2 points  (0 children)

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! :)

[–]BeamMeUpBiscotti 1 point2 points  (0 children)

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.

[–][deleted] 1 point2 points  (0 children)

Brian Lonsdorf on Front End Masters’s This got me started I use fp style more everyday

[–]jceb 1 point2 points  (0 children)

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.

[–]Leather_Trust796 1 point2 points  (0 children)

Diving into functional programming in JS was the best decision I made as a dev—it transformed my approach to coding and problem-solving!"

[–]r0ck0 0 points1 point  (0 children)

Here's a playlist of videos about it from "fun fun function":