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 filter(func, arr) { | |
return arr.reduce(function(memo, item) { | |
return func(item) ? memo.concat(item) : memo.slice() | |
}, []) | |
} |
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
// Based on http://adit.io/posts/2013-06-10-three-useful-monads.html | |
import map from 'ramda/src/map' | |
import compose from 'ramda/src/compose' | |
import curry from 'ramda/src/curry' | |
import multiply from 'ramda/src/multiply' | |
const chain = curry((fn, m) => m.chain(fn)) | |
const read = m => m.read() |
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
import compose from 'ramda/src/compose' | |
import curry from 'ramda/src/curry' | |
import map from 'ramda/src/map' | |
import always from 'ramda/src/always' | |
const chain = curry((fn, m) => m.chain(fn)) | |
function IO(run) { | |
const map = fn => IO(compose(fn, run)) | |
const chain = fn => IO(() => map(fn).run().run()) |
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
// I use flat map for a couple cases. I hope demonstrates | |
// a practical use case for flatMapping. | |
// IO is a way to capture a flow that is dependent on some side-effect. | |
// grabbing from and writing to a global (yuck!) for instance also logging to a console. | |
// We want to control these side effects. So if I have a flow that does multiple | |
// side-effects, chain is the way to go to compose them together and not run them | |
// until I call run on that IO. | |
const { IO, compose, curry, constant, map, chain } = crocks |
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
// A common use for chaining Maybes is deep pulls on objects | |
// where there is uncertainty | |
const { curry, Maybe, option } = crocks | |
const data = { | |
happy: { joy: true } | |
} | |
// propMaybe : String -> Object -> Maybe |
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 isFunction = require('../predicates/isFunction') | |
const isType = require('../internal/isType') | |
const _inspect = require('../internal/inspect') | |
const compose = require('../helpers/compose') | |
const identity = require('../combinators/identity') | |
const constant = require('../combinators/constant') |
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 { Pred, mconcat, isArray, not, isEmpty, safe } = require('crocks') | |
const pred = | |
mconcat(Pred, [ not(isEmpty), isArray ]) | |
// maybeArray : a -> Maybe [] | |
const maybeArray = | |
safe(pred) | |
console.log(maybeArray([ 1, 2 ])) // Just [ 1, 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 { | |
Either, coalesce, compose, | |
constant, identity, ifElse, | |
isString, map | |
} = require('crocks') | |
const { Left, Right } = Either | |
// onlyStrings : a -> Either Number String | |
const onlyStrings = |
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 { | |
curry, isNumber, pipeS, prop, safeLift, Star | |
} = require('../crocks') | |
const add = curry( | |
(x, y) => x + y | |
) | |
const pull = | |
x => Star(prop(x)) |
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 { validateUser } = require('../data/users') | |
const { | |
compose, curry, objOf | |
} = require('crocks') | |
module.exports = ({ config, express, jwt, knex }) => { | |
const { jwtSecret } = config | |
const router = express.Router() |
OlderNewer