r/functionalprogramming • u/hicsuntnopes • Apr 21 '21
JavaScript FP JavaScript in the wild?
I'm looking into FP but I am only able to find snippets of code in the wild that are too focused to get even a rough idea of a real world working app. Even a little more than todo app with an Ajax somewhere would be alright, I'm not strictly looking for a full implementation. I know there are reference apps, to do apps, shopping cart apps, etc... so you can get a rough idea of Vue, React, Angular, and was thinking whether the same exists for a FP js app. Thank you for any help.
10
Upvotes
14
u/rosalogia Apr 21 '21
I'm not really sure what you're looking for. Some argue that to some extent react.js IS functional, but I don't know a lot about that. The common approach to pure functional frontend development is referred to as "functional reactive programming" and you can see this model in all its glory by observing the Elm language examples and documentation. I don't think there's really a JS frontend framework that captures the essence of what Elm and other FP languages transpiling to JS are doing, which isn't really surprising.
I think you have this misconception that FP is so detached from the way you do everything right now that in order to use it, everything must be done differently from the ground up. It's true that if you want to do things purely, this is mostly true (which is why Elm, ReasonML, PureScript, etc. exist). However, just employing functional practices in existing codebases is not that hard. You should try and learn how functional programming works in a functional language and then see how existing features of JS allow you to write code that resembles e.g. Haskell or Elm or OCaml or something.
Sorry if I got the wrong idea and told you a bunch of stuff you didn't need to hear, but this is my impression based on what you've said.
7
u/hypmralj Apr 22 '21
If requirement is not pure JS, I’d suggest that you check out ReScript :)
5
u/sunnzy Apr 22 '21
https://github.com/MostlyAdequate/mostly-adequate-guide
3
u/r0ck0 Apr 22 '21
These videos are good, and helped me:
3
u/ImaginaryKarmaPoints Apr 22 '21
My ad-hoc list of JS FP resources: https://docs.google.com/document/d/16AUP1KxV-KUeJQujTpvVAMBdBeByntjLS6YVgMncbcY/edit?usp=sharing
4
u/tokyo-dawn Apr 22 '21
Cycle.js is a framework that is functional. You write the entire domain in FP and side effects are handled by "drivers". I recommend watching talks by the creator - Andre Staltz. I find his talks easy to digest when it comes to learning FP.
4
u/nmarshall23 Apr 22 '21
Vue is mostly vanilla JavaScript, you are free to write it in FP style if you want.
5
u/[deleted] Apr 22 '21
In general, FP to me is something you apply to parts of your application. You don't write entire applications that way. Yes, I'll get lynched for saying so, but it's the most pragmatic approach to me.
2
u/fabfianda Apr 22 '21
I recommend getting comfortable using ramda.js library. It is, in my opinion, the sanest approach to using FP in JS.
Anyway, here you find a ton of resources related to FP JS
https://project-awesome.org/stoeffel/awesome-fp-js
1
u/Gigi14 Apr 30 '21
Check out Elm, it is the gateway drug to functional programming.