Published
Edited
Mar 23, 2021
1 fork
Importers
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
running(R.add, {a: 100, b: 200})(list)
Insert cell
Insert cell
Insert cell
Insert cell
runningTotal = running(R.add, {a: 0, b: 0})
Insert cell
Insert cell
runningTotal(list)
Insert cell
Insert cell
Insert cell
runningProduct = running(R.multiply, {a: 1, b: 1})
Insert cell
runningProduct(list)
Insert cell
Insert cell
Insert cell
running(R.add, {a: 0, c: 0}, { subPropertyName: "nest" })(nested)
Insert cell
Insert cell
Insert cell
binop(R.add, {a: 3, b: 5, c: 7}, {a: 13, b: 17, x: 19})
Insert cell
Insert cell
binop(R.subtract, {a: 3, b: 5, c: 7}, {a: 13, b: 17, x: 19})
Insert cell
Insert cell
Insert cell
applyfn(R.add, "a", {a: 3, b: 5, c: 7}, {a: 13, b: 17, x: 19})
Insert cell
Insert cell
applyfn(R.add, "c", {a: 3, b: 5, c: 7}, {a: 13, b: 17, x: 19})
Insert cell
Insert cell
applyfn(R.add, "x", {a: 3, b: 5, c: 7}, {a: 13, b: 17, x: 19})
Insert cell
Insert cell
applyfn(R.add, "g", {a: 3, b: 5, c: 7}, {a: 13, b: 17, x: 19})
Insert cell
Insert cell
Insert cell
running = (fn, init, {subPropertyName} = {}) =>
R.map(
item => {

const operand = subPropertyName ? item[subPropertyName] : item

const result = ({
...operand,
init,
exit: binop(fn, init, operand),
total: init, // deprecated
})

const objectToReturn = subPropertyName
? ({ ...item, [subPropertyName]: result })
: result

init = result.exit

return objectToReturn
}
)
Insert cell
binop = (fn, one, two) =>
R.reduce(
(acc, key) => ({
...acc,
...applyfn(fn, key, one, two)
}),
{}
)(R.keys(one))
Insert cell
applyfn = (fn = R.add, key, one, two) =>
one?.[key] !== undefined && two?.[key] !== undefined
? ({ [key]: fn(one[key], two[key]) })
: {}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more