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
let pointer = Promise.resolve(); | |
let addQuestions = (pointer, questions) => questions.reduce((pointer, question) => pointer.then(question), pointer); | |
//add Initial Questions | |
pointer = addQuestions(pointer, questions); //move pointer | |
// some time later | |
pointer = addQuestions(pointer, moreQuestions); //move pointer again |
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
let compose = (f, g) => x => f(g(x)); | |
let wrap = value => () => value; | |
let lenses = { | |
over : (lens, fn, obj) => lens.setter(fn)(obj), | |
view : (lens, obj) => lens.getter(obj), | |
set : (lens, value, obj) => lenses.over(lens, wrap(value), obj), | |
basicCompose : (lensA, lensB) => ({ | |
getter : compose(lensB.getter, lensA.getter), | |
setter : fn => obj => lensA.setter(() => lensB.setter(fn)(lensA.getter(obj)))(obj) | |
}), |