Skip to content

Instantly share code, notes, and snippets.

Avatar

Vale the Violet Mote ValeTheVioletMote

View GitHub Profile
@ValeTheVioletMote
ValeTheVioletMote / mfp.js
Created Jan 10, 2020
Minor FP & Railway
View mfp.js
const _nudef = x => typeof x == 'undefined' || x == null || x == undefined;
const coalesce = (...vals) => vals.find((v,i)=>_nudef(v) == false || i==vals.length);
const u_pipe = (...fns) => (x) => fns.reduce((prev, func) => func(prev), x);
const None = Object.freeze({monad_name: "None", is: function is_none(x) {return x==this;}});
const build_monad = monad_name => {
var mon = (monad_name => {
return val => {
// Unpack if a packed monad
if(typeof val == "function" && val.monad_name == monad_name){
return val();