Skip to content

Instantly share code, notes, and snippets.

const streamMaker = (f) => {
const aux = x => [f(x), () => aux(x + 1)]
return () => aux(0)
}
const ones2 = streamMaker(x => x + 100)
const numberUntil = (s, predict) => {
const _ = { '@@functional/placeholder': true }
const isPlaceholder = (a = {}) => typeof a === 'object'
&& a['@@functional/placeholder'] === true
const fill = (cache = [], rest = []) => {
const emptyIndexs = cache.reduce((acc, x, index) => {
if (isPlaceholder(x)) {
acc.push(index)
// an enhanced version of ramda path
const isNil = x => x == undefined // eslint-disable-line
const path = (paths = [], obj) => paths.reduce((acc, current) => {
if (isNil(acc)) {
return acc
}
if (Array.isArray(acc) && (typeof current === 'object')) {
return acc.map(item => Object.keys(current).reduce((filtered, key) => {
@beizhedenglong
beizhedenglong / cond.js
Created May 6, 2019 03:07
Lisp inspired cond in JavaScript
const cond = (pairs = []) => (data) => {
for (let i = 0; i < pairs.length; i++) {
const [f, res] = pairs[i]
const isTrue = typeof f === 'function' ? f(data) : f
if (isTrue) {
return res
}
}
return undefined
}
const deconstructObserver = (...stores)=> Component => {
const merge = (acc, store) => {
return R.merge(acc, toJS(store))
}
const ObserbverComponent = observer(() => {
const store = R.reduce(merge, {})(stores)
return <Component {...store} ></Component>
})
return ObserbverComponent