Skip to content

Instantly share code, notes, and snippets.

View ValeTheVioletMote's full-sized avatar

Vale the Violet Mote ValeTheVioletMote

View GitHub Profile
@ValeTheVioletMote
ValeTheVioletMote / mfp.js
Created January 10, 2020 20:24
Minor FP & Railway
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();