This file contains hidden or 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
interface BoxA<T> { | |
a: T; | |
} | |
interface BoxB<T> { | |
b: T; | |
} | |
type BoxerA<T> = (a: T) => BoxA<T>; |
This file contains hidden or 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
@function enum($keys) { | |
$index-map: (); | |
$running-index: 1; | |
@each $k in $keys { | |
@if type-of($k) == list { | |
// NOTE: We do _not_ check if this value is greater than prior values. | |
// This is intentional. | |
$running-index: nth($k, 2); | |
$k: nth($k, 1); | |
} |
This file contains hidden or 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
export default function(WrappedComponent) { | |
const mixinProps = (WrappedComponent.mixins || []) | |
.filter((mixin) => mixin.props) | |
.map((mixin) => mixin.props); | |
const allProps = mixinProps.concat(WrappedComponent.props); | |
const mergedProps = allProps.reduce((merged, props) => Object.assign(merged, props), {}); | |
return { | |
props: mergedProps, | |
render(createElement) { |
This file contains hidden or 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
function fizzbuzz(max) { | |
for (let i = 1; i <= max; ++i) | |
console.log(i, `${!(i % 3) ? 'fizz' : ''}${!(i % 5) ? 'buzz' : ''}` || '.'); | |
} | |
function fizzbuzz(max) { | |
for (let i = 1; i <= max; ++i) | |
console.log(i, ((!(i % 3) ? 'fizz' : '') + (!(i % 5) ? 'buzz' : '')) || '.'); | |
} |
This file contains hidden or 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
function repeatUntil({ interval, repeat, until }) { | |
// let callTime; | |
let isCanceled = false; | |
function cancel() { | |
isCanceled = true; | |
} | |
function conditionallyCancel() { | |
if (until()) { |
This file contains hidden or 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 PLACEHOLDER_ERROR = Symbol('placeholderError'); | |
function deferred() { | |
const d = { | |
settled: false, resolved: false, rejected: false, | |
reason: null, resolution: null, | |
}; | |
d.promise = new Promise((res, rej) => { | |
d.resolve = (r) => { | |
d.settled = true; |
This file contains hidden or 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
function handleSomeThing(ctx) { | |
return compose( | |
stepA(optionsA), | |
stepB(optionsB), | |
stepC(optionsC), | |
)(pctx => pctx.resultFoo)({ ctx }); | |
} | |
// Or somewhat more mysterious looking... | |
const handleSomeThing = compose( |
This file contains hidden or 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 processFoo = compose( | |
stepA(optionsA), | |
stepB(optionsB), | |
stepC(optionsC) | |
)(res => res); | |
async function handleSomeThing(ctx) { | |
// Create a pctx with the original ctx and whatever else we want. | |
// NOTE: in this case, we're trying to not pollute the original ctx, | |
// which might be something like a Koa Context. |
This file contains hidden or 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 processFoo = | |
stepA(optionsA)( | |
stepB(optionsB)( | |
stepC(optionsC)( | |
// A SACRIFICE TO THE PYRAMID OF DOOM | |
// On a more serious note, since each step function requires | |
// a next function, we need to pass in a "return" function which | |
// doesn't expect a next function to complete the chain. | |
// If we didn't do this, stepC would return a function expecting a next | |
// function... passing that function an object doesn't cause an error, |
This file contains hidden or 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
function stepA(options) { | |
return (next) => async (pctx) => { | |
// Do stuff, allowing any errors to reject this promise, | |
// passing them back to previous steps. | |
const result = await doSomething(pctx.foo); | |
const nextPctx = { ...pctx, bar: result }; | |
try { | |
// NOTE: Technically, you could further process the result | |
// before returning it. |
NewerOlder