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 eq = (a) => (b) => a === b; | |
const everyItemEquala = compose( | |
apply(all), | |
juxt([compose(equals, head), identity]) | |
); | |
const everyItemEqualb = compose( | |
equals(1), | |
length, |
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 juxtMerge = (fnList) => compose( | |
mergeAll, | |
juxt(fnList) | |
); | |
// given an object, a foreignKey (name), and a lookup object | |
// containing data keyed to the foreignKey, | |
// return the data of the lookup, or a fallback value | |
const propOfPropOr = (fallback, foreignKey, lookup) => (item) => propOr( | |
fallback, |
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
// accepts an argument object and a data object. | |
// first returns the value at lookupName in the data object | |
// and then applies the value of that back onto the data object | |
// treating it as meta data about the data object, eg | |
// lookWIthin( | |
// { lookupName: 'currPage', endOfPath: ['position'] }, | |
// { currPage: 'page!', page!: {position: 55} } | |
// ) => 55 | |
const lookWithin = ({ lookupName, endOfPath = [] }) => 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 dot = (f, g) => a => f(g(a)); | |
const cmp = reduce(dot, identity); | |
const cmp2 = reduce(o, identity); | |
[ | |
compose( | |
sum, | |
range(2), |
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 formula = | |
{'+': [ | |
2, 2, 3, | |
{'-': [ | |
5, | |
{'+': [ | |
2, {'var': 'base-val'}, {var: 'base'}, | |
{'+': [ | |
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
// permitted actions for state changes | |
const eventActions = { | |
write: (path, val = null) => assocPath(path, val), | |
erase: (path) => dissocPath(path), | |
}; | |
const noop = () => () => {}; | |
// run a legitmate action on a state object | |
const eventToState = ({ type, path, val }, stateObj, actions) => propOr( |
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 data = [ | |
{ label: 'first', val: 'gold-like' }, | |
{ label: 'second', val: 'silver-esque' }, | |
{ label: 'third', val: 'bronz-ish' }, | |
]; | |
const propLen = (propName) => compose( | |
length, | |
propOr('', propName) | |
); |
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 assocPth = ([head, ...rest], value, obj) => Array.isArray(obj) | |
? [].concat( | |
obj.slice(0, head), | |
[rest.length | |
? assocPth(rest, value, obj[head]) | |
: value], | |
obj.slice(head + 1)) | |
: Object.assign({}, | |
obj, | |
{[head]: rest.length |
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 S = f => g => x => f (x) (g (x)); | |
const S2 = f => g => h => x => f (g (x)) (h (x)); | |
// create a list based on a list of numbers that won't | |
// contain a zero, where the result is a list of products | |
// of the list without the number at the position of a given member | |
// eg [5,2,1,4,3] => [24, 60, 120, 30, 40] | |
// the key is that the computed product of the list and | |
// then divided by a given member, is equivalent to |
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 strongOrPlain = (bool, str) => bool | |
? `<strong>${str}</strong>` | |
: str; | |
const RangeItemComp = ({header, start, end, highlighted}) => `<li>${ | |
strongOrPlain( | |
highlighted, | |
`${header}: ${start} - ${end}` | |
)}</li>`; |