Skip to content

Instantly share code, notes, and snippets.

View jperasmus's full-sized avatar
🔥
Too blessed to be stressed

JP Erasmus jperasmus

🔥
Too blessed to be stressed
View GitHub Profile
@jperasmus
jperasmus / machine.js
Created January 26, 2022 08:03
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@jperasmus
jperasmus / compose.js
Last active June 30, 2022 07:48
"compose" function that handles both sync and async functions
// Async compose
const compose = (…functions) => input => functions.reduceRight((chain, func) => chain.then(func), Promise.resolve(input));
// Functions fn1, fn2, fn3 can be standard synchronous functions or return a Promise
compose(fn3, fn2, fn1)(input).then(result => console.log(`Do with the ${result} as you please`))