This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# *light* functional programming in bash | |
IFS=$'\n' | |
# not really fp, but including it anyway - get over it | |
for_each() { | |
local fn=$1 | |
shift |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios'); // npm i axios | |
async function *asyncForEach (fn, arr) { | |
for (let prop of arr) { | |
yield await fn(prop); | |
} | |
} | |
const results = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const identity = x => x; | |
function Just (v) { | |
return { map, chain, ap }; | |
function map (fn) { | |
return Just(fn(v)) | |
} | |
function chain (fn) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* A custom implementation of Promises */ | |
class SyntheticPromise { | |
constructor(executor) { | |
this.chain = []; | |
this.handleException = () => {}; | |
this.onResolve = this.onResolve.bind(this); | |
this.onReject = this.onReject.bind(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const init = (db) => { | |
db.actions = {}; | |
db.store = {}; | |
db.register = (name, fn) => { | |
db.actions[name] = fn; | |
return db; | |
} | |
db.dispatch = (opt) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* auxillary helpers */ | |
const setPermissions = (r, w, x) => ({ | |
read: r || false, | |
write: w || false, | |
execute: x || false, | |
}); | |
const permissionsEnum = { | |
read: "r", | |
write: "w", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestController { | |
constructor(dataSource) { | |
this.data = dataSource; | |
} | |
dispatch(obj) { | |
switch(obj.method) { | |
case "GET": | |
return this.handleGet(obj.query); | |
case "DELETE": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// curried generator | |
const renderStringInterval = value => function*(num) { | |
yield setInterval(() => console.log(value), num); | |
}; | |
renderStringInterval('test')(3000).next(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BinaryHeap { | |
constructor(fn) { | |
this.scoreFunction = fn; | |
this.data = []; | |
} | |
push(el) { | |
this.data.push(el); | |
this.bubbleUp(this.data.length - 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// usage of Revealing Constructor / Module Pattern here enables instance versus business logic discretion | |
const Logger = (function () { | |
/* Internal Methods and Properties */ | |
// standard color dict for extended options | |
const _colorDict = { | |
reset : "\x1b[0m", | |
bright : "\x1b[1m", | |
dim : "\x1b[2m", |