r/functionalprogramming • • Jul 01 '22

JavaScript The best resource to learn functional programming in JavaScript

15 Upvotes

Hi folks,

As the title suggest I'm looking for resources to learn functional programming in JavaScript. All suggestions are welcome - books, courses, etc.

r/functionalprogramming • • Apr 21 '21

JavaScript FP JavaScript in the wild?

10 Upvotes

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.

r/functionalprogramming • • Feb 26 '21

JavaScript Structural sharing with 7 lines of JavaScript.

Thumbnail
blog.klipse.tech
6 Upvotes

r/functionalprogramming • • Dec 19 '23

JavaScript Monads in JavaScript

23 Upvotes

r/functionalprogramming • • Jul 11 '20

JavaScript JavaScript Tagged Unions

13 Upvotes

Tagged Union implementation and some helper functions in JavaScript.

https://github.com/tariqqubti/js-tagged-union

A package to basically be able to do this:

import {Maybe, Run, Check, Http, Loading, Ok, Err} from '...';

// Each arm could be abstracted into its own function
const state = await Maybe(localStorage.getItem('userInfo')).match({ // null, undefined check
  Some: info => Run(() => JSON.parse(info)).match({ // parse json
    Ok: info => Check(info.id, x => /valid/.test(x)).match({ // run validation
      Pass: async id => (await Http(fetch(`/user/${id}`))).match({ // fetch
        Success: res => Ok(res.data), // res.status === 200
        NotFound: res => Err(Error(res.data)), // res.status === 404
        Err: err => Err(err), // timeout, disconnection, etc.
      }),
      Fail: () => Err(Error('Invalid stored user info')),
    })
    Err: () => Err(Error('Could not parse user info')),
  })
  None: () => Err(Error('Stored user info was not found'))
});

r/functionalprogramming • • Jun 22 '21

JavaScript Imperative vs Declarative programming in JavaScript

23 Upvotes

Hi everyone, I have tried describing the difference between imperative and declarative programming. It's not the first time that I have tried and I am hoping that I am able to communicate it in a clear way but I would appreciate the feedback of the community.

Please have a look at

the Medium post: https://medium.com/weekly-webtips/imperative-vs-declarative-programming-in-javascript-25511b90cdb7

and the YouTube video: https://www.youtube.com/watch?v=oFXOLbAX4Pw

r/functionalprogramming • • Mar 03 '20

JavaScript JavaScript Without Loops

Thumbnail
jrsinclair.com
23 Upvotes

r/functionalprogramming • • Jul 31 '19

JavaScript Recommendations for JavaScript functional programming

22 Upvotes

As the title states, what do you recommend? I am fairly new to programming overall, hence the JavaScript. I have also come across Ramda.js functional programming library. Any thoughts for a newbie?

r/functionalprogramming • • Oct 13 '20

JavaScript How do I write this JS function in a immutable way ?

3 Upvotes

How do I write this javascript function in a immutable fashion?
I mean without pushing values into a array, is there a way to do it all in one function?

is there a function for this in lodash or ramda ? how would you do it ?

getTexts: async (page, handlers) => {
		let texts = [];

		handlers.map(async (handler) => {
			const text = await page.$eval(handler, (e) => e.innerText);
			texts.push(text);
		});

		return texts;
	},

r/functionalprogramming • • Jun 26 '22

JavaScript Really good explanation of a monad in under 100 seconds

Thumbnail
youtube.com
125 Upvotes

r/functionalprogramming • • May 31 '20

JavaScript Please help me understand why you should use FP (in Javascript) instead of OOP as this example makes me wonder if FP is just an overcomplex neckbeard hype.

0 Upvotes

Hey Functional Programming community. A week ago I first watched a talk about Functional Programming in Javascript and learned a lot about it afterwards. But now, a week later, I'm so frustrated. Is it me, do I not understand FP good enough? Or is it just a neckbeard "im the real programmer" hype as it feels like now? Please help me understand the difference and why you would choose for the first approach. Thank you so much!

Okay; All I want is to display a button on a webpage.

The HTML:

<div id="app"></div>

Now we have to create a pure function that will create a HTMLButtonElement:

const newButton = _ => document.createElement("button");

But, we also would like to have a label on our button right? So we need a textNode and append this to our button. Two different functions in Functional Programming:

const newTextNode = text => document.createTextNode(text);
const append = (child, target) => { target.appendChild(child); return target };

Now we need an other function to combine all these functions to create some function inception just to create our fucking button and have it in the right order as well:

const button = label => append(newTextNode(label), newButton());

Finally we can create our button and append it to the body:

const myButton = button("Click me!");
document.body.append(myButton);

To have an end result of this pile of shit:

const newButton = _ => document.createElement("button");
const newTextNode = text => document.createTextNode(text);
const append = (child, target) => { target.appendChild(child); return target };
const button = label => append(newTextNode(label), newButton());

const myButton = button("Click me!");
document.body.append(myButton);

This seems to me like it's overly complex. Especially when we have this super simple, human understandable OOP version:

class Button {
    constructor(label) {
        const button = document.createElement("button");
        const btnLabel = document.createTextNode(label);
        
        button.appendChild(btnLabel);
        return button;
}

const myButtonOOP = new Button("Click Me!");
document.body.append(myButtonOOP);

Please help me understand why one would prefer the first, the FP approach, over the latter, the OOP approach. Especially when we would like to add an, for example, callback to the button. In the OOP version all we have to do is alter the constructor making the callback optional for reverse compatibility:

constructor(label, callback = false)

And we have to add the event Listener if a callback is present:

if(callback) {
    button.addEventListener("click", callback);
}

If we would like to do the same, super simple change, to the Functional approach. We have to create this function inception that's almost unreadable. I'll probably write it completely wrong as it's too complex to come up with:

const listen = (target, callback) => target.addEventListener("click", callback);
const button = (label, callback = false) => listen(append(newTextNode(label), newButton(), callback);

It just doesn't make sense to me. The latter is so disgustingly unreadable?

I get that the pure functions are an amazing concept that make a lot of sense. But at what cost?

r/functionalprogramming • • Aug 05 '20

JavaScript Steph - Ramda Style JS

12 Upvotes

I made this to enable ramda style development by default.

Any thoughts?

https://github.com/ronyhe/steph

r/functionalprogramming • • Oct 12 '20

JavaScript JS FP newbie question : What is fp-ts library used for ?

18 Upvotes

Hello,

I am a JS developer and started to replace all my foreach loop with map/reduce/filter... and I noticed my code looked much cleaner and readable. I learned some days ago this kind of programming is know as "functionnal programming".

I started to read some tutorials / blog post about it and learned a lot. (ramda / rxjs / curryfication / closure / unarity / composition / immutability / pure functions etc...)

I was feeling confident that I could start trying to start a new project with a lot more of FP concepts. But then I discovered the library "fp-ts" and I got the feeling that I have much more to learn.

What is a functor ? Monad ? monoid ? all thoses keywords were very rarely mentionned in the articles I read.

I don't understand how this library differ from ramda ?

r/functionalprogramming • • Oct 07 '20

JavaScript New functional programming library in JavaScript @7urtle/lambda

23 Upvotes

Hi everyone, I have made a new library for functional programming in JavaScript: 7urtle/lambda, and I have made a website with learning articles and API documentation: https://www.7urtle.com/. I am trying to reach out to you as professionals to provide feedback on the projects to improve the library. Especially when it comes to the learning articles on https://www.7urtle.com/learn-functional-programming-in-javascript I would appreciate help with validation of the functional programming principles and the way how I implemented them.

r/functionalprogramming • • Jul 17 '21

JavaScript Do you use curried functions and partial application in your own JavaScript code?

17 Upvotes

I have been exclusively using curried functions in my JavaScript code for a while and I could never go back. I just like how it makes everything more elegant. What is your own experience? My blog post on the topic: https://betterprogramming.pub/5-easy-steps-to-master-currying-and-higher-order-functions-in-javascript-85e2a7e2c268 and a video: https://www.youtube.com/watch?v=T-qDFYq0IvA

r/functionalprogramming • • Sep 22 '21

JavaScript I implemented the Fibonacci Sequence in pure lambda calculus within JavaScript!! No arithmetic operators, no assignment, no numbers and no loops... just functions :)

Thumbnail
github.com
33 Upvotes

r/functionalprogramming • • Dec 09 '20

JavaScript Purely functional memoization in JS

12 Upvotes

Purely functional memoization in JS based on the idea of turning functions into infinite data structures. All that is needed are non-strictness and sharing. Here is an example of infinite [Int]

r/functionalprogramming • • May 08 '21

JavaScript How to write better JavaScript using plumbing techniques

Thumbnail
piotrjaworski.medium.com
16 Upvotes

r/functionalprogramming • • Oct 11 '21

JavaScript Clio: a functional, multi-threaded programming language that compiles to JavaScript

25 Upvotes

I've been working on a functional programming language in the past few years and I'd like to share it with you, would be nice to have some feedback on it! The language is called "Clio" and you can find it here: https://github.com/clio-lang/clio or here: https://clio-lang.org

It has a minimal and noise-free syntax, a minimal type system, and also a gradual type checking system. It has a few innovations, for example, remote functions and built-in support for clustering and making distributed systems. It compiles to JavaScript, it's super fast [1], and it brings multi-threading to the browser.

Let me know what you think, any feedback is appreciated. I'm looking forward to hearing out your opinions so I can improve my language!

[1] https://pouyae.medium.com/clio-extremely-fast-multi-threaded-code-on-the-browser-e78b4ad77220

r/functionalprogramming • • Dec 24 '21

JavaScript Why Do We Need Transpilation Into JavaScript?

Thumbnail
typeable.io
20 Upvotes

r/functionalprogramming • • Oct 26 '22

JavaScript What if the team assumes my functional JavaScript is slow?

Thumbnail
jrsinclair.com
20 Upvotes

r/functionalprogramming • • Sep 15 '22

JavaScript Library to purify randomness in JavaScript?

10 Upvotes

Math.random() like Date.now() are impure functions. Is there a library that seeds a random function with an internal state so that random operations applied to an event-sourced reduction plays out exactly the same? All functions would have to be fed by the seeded generator. Obviously, randomness is perceived and not actual in this case.

const id = guid();
const random = generator(id);
const i = random(1, 10);
const cards = shuffle(deck, random);

The benefit of having a closed-over function feed all random operations is that if the players in a card game make the same choices the programmatic reduction will follow the same path and result in the same outcome. It makes writing tests straightforward. It offers the possibility or running a pure simulation.

If found this one but it does not work as I suggest: https://github.com/Risto-Stevcev/pure-random#readme

r/functionalprogramming • • Aug 19 '21

JavaScript Pure Functions in JavaScript In Under 60 seconds

Thumbnail
youtube.com
17 Upvotes

r/functionalprogramming • • Sep 17 '22

JavaScript Functional Programming and Naturality in Javascript: Conjunctions

Thumbnail
medium.com
9 Upvotes

r/functionalprogramming • • Dec 18 '24

JavaScript Frameworkless, tacit, functional javascript community

20 Upvotes

3 years ago I created a community for programmers/web developers who don't feel aligned with the state of the web piling frameworks over frameworks to produce websites. It's tiring that all "javascript" discussion is about implementation details of NextJS/webpack/React/Angular/Vue, as if they were the platforms we are developing against and not just libraries with oversized scopes.
Since then I've developed my fully functional/procedural web server, with flat compositions and tacit combinators, and it inspired people in the group, so we started having go-live competitions (next deadline for going live dec 27!), reading and peer review livestream sessions, but even more activity discussing solutions from first principles is what could really amalgamate our cohesion and enhance our performance.
If you're also seeking an outlet to talk about optimal solutions in practice, in the abstract, or even in pseudocode, for routing, server-side rendering, AST parsing/serialization, event delegation, persistence/IO, object traversal algorithms, function composition, god forbid "category theory", etc., then you are warmly invited to join fellow curious minds leading the functional-procedural zeitgeist in our discord/matrix community:
https://discord.gg/GvSxsZ3d35
https://matrix.to/#/!ipeUUPpfQbqxqMxDZD:matrix.org?via=matrix.org&via=t2bot.io
Let us know what you're working on, or wish to, for guaranteed feedback!

Hope to see you there!