├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .gitattributes ├── .gitignore ├── .travis.yml ├── BOOKMARKLET.md ├── CHANGELOG.md ├── CONTRIBUTING.md ├── DOCUMENTATION.md ├── LICENSE.txt ├── Makefile ├── README.md ├── bower.json ├── dist ├── ramda.js └── ramda.min.js ├── lib ├── bench │ ├── concat.bench.js │ ├── curry.bench.js │ ├── each.bench.js │ ├── either.bench.js │ ├── filter-where.bench.js │ ├── filter.bench.js │ ├── find-where.bench.js │ ├── find.bench.js │ ├── findIndex-where.bench.js │ ├── findIndex.bench.js │ ├── includes.bench.js │ ├── indexof.bench.js │ ├── map.bench.js │ ├── maxWith.bench.js │ ├── propEq.bench.js │ ├── reduce.bench.js │ └── uniq.bench.js └── sauce │ ├── android.js │ ├── apple.js │ ├── browsers.js │ ├── conf.js │ ├── ie8-shim.js │ ├── ios.js │ ├── linux.js │ ├── mocharun.js │ ├── server.js │ └── windows.js ├── package.json ├── repl ├── rollup.config.js ├── scripts ├── BOOKMARKLET.tmpl.md ├── benchRunner ├── bookmarklet ├── bookmarklet.tmpl.js ├── doc-blob ├── partialBuild.js ├── prepublish └── transpile │ ├── esm-to-cjs.js │ └── wrap-constructor-pattern.js ├── source ├── F.js ├── T.js ├── __.js ├── add.js ├── addIndex.js ├── adjust.js ├── all.js ├── allPass.js ├── always.js ├── and.js ├── any.js ├── anyPass.js ├── ap.js ├── aperture.js ├── append.js ├── apply.js ├── applySpec.js ├── applyTo.js ├── ascend.js ├── assoc.js ├── assocPath.js ├── binary.js ├── bind.js ├── both.js ├── call.js ├── chain.js ├── clamp.js ├── clone.js ├── comparator.js ├── complement.js ├── compose.js ├── composeK.js ├── composeP.js ├── composeWith.js ├── concat.js ├── cond.js ├── construct.js ├── constructN.js ├── contains.js ├── converge.js ├── countBy.js ├── curry.js ├── curryN.js ├── dec.js ├── defaultTo.js ├── descend.js ├── difference.js ├── differenceWith.js ├── dissoc.js ├── dissocPath.js ├── divide.js ├── drop.js ├── dropLast.js ├── dropLastWhile.js ├── dropRepeats.js ├── dropRepeatsWith.js ├── dropWhile.js ├── either.js ├── empty.js ├── endsWith.js ├── eqBy.js ├── eqProps.js ├── equals.js ├── evolve.js ├── filter.js ├── find.js ├── findIndex.js ├── findLast.js ├── findLastIndex.js ├── flatten.js ├── flip.js ├── forEach.js ├── forEachObjIndexed.js ├── fromPairs.js ├── groupBy.js ├── groupWith.js ├── gt.js ├── gte.js ├── has.js ├── hasIn.js ├── hasPath.js ├── head.js ├── identical.js ├── identity.js ├── ifElse.js ├── inc.js ├── includes.js ├── index.js ├── indexBy.js ├── indexOf.js ├── init.js ├── innerJoin.js ├── insert.js ├── insertAll.js ├── internal │ ├── _Set.js │ ├── _aperture.js │ ├── _arity.js │ ├── _arrayFromIterator.js │ ├── _assertPromise.js │ ├── _checkForMethod.js │ ├── _clone.js │ ├── _cloneRegExp.js │ ├── _complement.js │ ├── _concat.js │ ├── _createPartialApplicator.js │ ├── _curry1.js │ ├── _curry2.js │ ├── _curry3.js │ ├── _curryN.js │ ├── _dispatchable.js │ ├── _dropLast.js │ ├── _dropLastWhile.js │ ├── _equals.js │ ├── _filter.js │ ├── _flatCat.js │ ├── _forceReduced.js │ ├── _functionName.js │ ├── _functionsWith.js │ ├── _has.js │ ├── _identity.js │ ├── _includes.js │ ├── _includesWith.js │ ├── _indexOf.js │ ├── _isArguments.js │ ├── _isArray.js │ ├── _isArrayLike.js │ ├── _isFunction.js │ ├── _isInteger.js │ ├── _isNumber.js │ ├── _isObject.js │ ├── _isPlaceholder.js │ ├── _isRegExp.js │ ├── _isString.js │ ├── _isTransformer.js │ ├── _makeFlat.js │ ├── _map.js │ ├── _objectAssign.js │ ├── _objectIs.js │ ├── _of.js │ ├── _pipe.js │ ├── _pipeP.js │ ├── _quote.js │ ├── _reduce.js │ ├── _reduced.js │ ├── _stepCat.js │ ├── _toISOString.js │ ├── _toString.js │ ├── _xall.js │ ├── _xany.js │ ├── _xaperture.js │ ├── _xchain.js │ ├── _xdrop.js │ ├── _xdropLast.js │ ├── _xdropLastWhile.js │ ├── _xdropRepeatsWith.js │ ├── _xdropWhile.js │ ├── _xfBase.js │ ├── _xfilter.js │ ├── _xfind.js │ ├── _xfindIndex.js │ ├── _xfindLast.js │ ├── _xfindLastIndex.js │ ├── _xmap.js │ ├── _xreduceBy.js │ ├── _xtake.js │ ├── _xtakeWhile.js │ ├── _xtap.js │ └── _xwrap.js ├── intersection.js ├── intersperse.js ├── into.js ├── invert.js ├── invertObj.js ├── invoker.js ├── is.js ├── isEmpty.js ├── isNil.js ├── join.js ├── juxt.js ├── keys.js ├── keysIn.js ├── last.js ├── lastIndexOf.js ├── length.js ├── lens.js ├── lensIndex.js ├── lensPath.js ├── lensProp.js ├── lift.js ├── liftN.js ├── lt.js ├── lte.js ├── map.js ├── mapAccum.js ├── mapAccumRight.js ├── mapObjIndexed.js ├── match.js ├── mathMod.js ├── max.js ├── maxBy.js ├── mean.js ├── median.js ├── memoize.js ├── memoizeWith.js ├── merge.js ├── mergeAll.js ├── mergeDeepLeft.js ├── mergeDeepRight.js ├── mergeDeepWith.js ├── mergeDeepWithKey.js ├── mergeLeft.js ├── mergeRight.js ├── mergeWith.js ├── mergeWithKey.js ├── min.js ├── minBy.js ├── modulo.js ├── multiply.js ├── nAry.js ├── negate.js ├── none.js ├── not.js ├── nth.js ├── nthArg.js ├── o.js ├── objOf.js ├── of.js ├── omit.js ├── once.js ├── or.js ├── otherwise.js ├── over.js ├── pair.js ├── partial.js ├── partialRight.js ├── partition.js ├── path.js ├── pathEq.js ├── pathOr.js ├── pathSatisfies.js ├── pick.js ├── pickAll.js ├── pickBy.js ├── pipe.js ├── pipeK.js ├── pipeP.js ├── pipeWith.js ├── pluck.js ├── prepend.js ├── product.js ├── project.js ├── prop.js ├── propEq.js ├── propIs.js ├── propOr.js ├── propSatisfies.js ├── props.js ├── range.js ├── reduce.js ├── reduceBy.js ├── reduceRight.js ├── reduceWhile.js ├── reduced.js ├── reject.js ├── remove.js ├── repeat.js ├── replace.js ├── reverse.js ├── scan.js ├── sequence.js ├── set.js ├── slice.js ├── sort.js ├── sortBy.js ├── sortWith.js ├── split.js ├── splitAt.js ├── splitEvery.js ├── splitWhen.js ├── startsWith.js ├── subtract.js ├── sum.js ├── symmetricDifference.js ├── symmetricDifferenceWith.js ├── tail.js ├── take.js ├── takeLast.js ├── takeLastWhile.js ├── takeWhile.js ├── tap.js ├── test.js ├── then.js ├── thunkify.js ├── times.js ├── toLower.js ├── toPairs.js ├── toPairsIn.js ├── toString.js ├── toUpper.js ├── transduce.js ├── transpose.js ├── traverse.js ├── trim.js ├── tryCatch.js ├── type.js ├── unapply.js ├── unary.js ├── uncurryN.js ├── unfold.js ├── union.js ├── unionWith.js ├── uniq.js ├── uniqBy.js ├── uniqWith.js ├── unless.js ├── unnest.js ├── until.js ├── update.js ├── useWith.js ├── values.js ├── valuesIn.js ├── view.js ├── when.js ├── where.js ├── whereEq.js ├── without.js ├── xprod.js ├── zip.js ├── zipObj.js └── zipWith.js ├── test ├── F.js ├── T.js ├── add.js ├── addIndex.js ├── adjust.js ├── all.js ├── allPass.js ├── always.js ├── and.js ├── any.js ├── anyPass.js ├── ap.js ├── aperture.js ├── append.js ├── apply.js ├── applySpec.js ├── applyTo.js ├── ascend.js ├── assoc.js ├── assocPath.js ├── binary.js ├── bind.js ├── both.js ├── call.js ├── chain.js ├── clamp.js ├── clone.js ├── comparator.js ├── complement.js ├── compose.js ├── composeK.js ├── composeP.js ├── composeWith.js ├── concat.js ├── cond.js ├── construct.js ├── constructN.js ├── converge.js ├── countBy.js ├── curry.js ├── curryN.js ├── dec.js ├── defaultTo.js ├── descend.js ├── difference.js ├── differenceWith.js ├── dissoc.js ├── dissocPath.js ├── divide.js ├── drop.js ├── dropLast.js ├── dropLastWhile.js ├── dropRepeats.js ├── dropRepeatsWith.js ├── dropWhile.js ├── either.js ├── empty.js ├── endsWith.js ├── eqBy.js ├── eqProps.js ├── equals.js ├── evolve.js ├── filter.js ├── find.js ├── findIndex.js ├── findLast.js ├── findLastIndex.js ├── flatten.js ├── flip.js ├── forEach.js ├── forEachObjIndexed.js ├── fromPairs.js ├── groupBy.js ├── groupWith.js ├── gt.js ├── gte.js ├── has.js ├── hasIn.js ├── hasPath.js ├── head.js ├── helpers │ ├── listXf.js │ └── test.examplesRunner.js ├── identical.js ├── identity.js ├── ifElse.js ├── inc.js ├── includes.js ├── index.js ├── indexBy.js ├── indexOf.js ├── init.js ├── innerJoin.js ├── insert.js ├── insertAll.js ├── internal │ ├── _curry2.js │ ├── _curry3.js │ └── _isArrayLike.js ├── intersection.js ├── intersperse.js ├── into.js ├── invariants.js ├── invert.js ├── invertObj.js ├── invoker.js ├── is.js ├── isEmpty.js ├── isNil.js ├── join.js ├── juxt.js ├── keys.js ├── keysIn.js ├── last.js ├── lastIndexOf.js ├── length.js ├── lensIndex.js ├── lensPath.js ├── lensProp.js ├── lenses.js ├── lift.js ├── liftN.js ├── lt.js ├── lte.js ├── map.js ├── mapAccum.js ├── mapAccumRight.js ├── mapObjIndexed.js ├── match.js ├── mathMod.js ├── max.js ├── maxBy.js ├── mean.js ├── median.js ├── memoize.js ├── memoizeWith.js ├── merge.js ├── mergeAll.js ├── mergeDeepLeft.js ├── mergeDeepRight.js ├── mergeDeepWith.js ├── mergeDeepWithKey.js ├── mergeLeft.js ├── mergeRight.js ├── mergeWith.js ├── mergeWithKey.js ├── min.js ├── minBy.js ├── modulo.js ├── multiply.js ├── nAry.js ├── negate.js ├── none.js ├── not.js ├── nth.js ├── nthArg.js ├── o.js ├── objOf.js ├── of.js ├── omit.js ├── once.js ├── or.js ├── otherwise.js ├── pair.js ├── partial.js ├── partialRight.js ├── partition.js ├── path.js ├── pathEq.js ├── pathOr.js ├── pathSatisfies.js ├── pick.js ├── pickAll.js ├── pickBy.js ├── pipe.js ├── pipeK.js ├── pipeP.js ├── pipeWith.js ├── pluck.js ├── prepend.js ├── product.js ├── project.js ├── prop.js ├── propEq.js ├── propIs.js ├── propOr.js ├── propSatisfies.js ├── props.js ├── range.js ├── reduce.js ├── reduceBy.js ├── reduceRight.js ├── reduceWhile.js ├── reduced.js ├── reject.js ├── remove.js ├── repeat.js ├── replace.js ├── reverse.js ├── scan.js ├── sequence.js ├── shared │ ├── Id.js │ ├── Maybe.js │ ├── eq.js │ └── funcN.js ├── slice.js ├── sort.js ├── sortBy.js ├── sortWith.js ├── split.js ├── splitAt.js ├── splitEvery.js ├── splitWhen.js ├── startsWith.js ├── subtract.js ├── sum.js ├── symmetricDifference.js ├── symmetricDifferenceWith.js ├── tail.js ├── take.js ├── takeLast.js ├── takeLastWhile.js ├── takeWhile.js ├── tap.js ├── test.js ├── then.js ├── thunkify.js ├── times.js ├── toLower.js ├── toPairs.js ├── toPairsIn.js ├── toString.js ├── toUpper.js ├── transduce.js ├── transpose.js ├── traverse.js ├── trim.js ├── tryCatch.js ├── type.js ├── unapply.js ├── unary.js ├── uncurryN.js ├── unfold.js ├── union.js ├── unionWith.js ├── uniq.js ├── uniqBy.js ├── uniqWith.js ├── unless.js ├── unnest.js ├── until.js ├── update.js ├── useWith.js ├── values.js ├── valuesIn.js ├── when.js ├── where.js ├── whereEq.js ├── without.js ├── xprod.js ├── zip.js ├── zipObj.js └── zipWith.js └── testem.json /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "cjs": { 4 | "plugins": [ 5 | "annotate-pure-calls", 6 | "./scripts/transpile/esm-to-cjs", 7 | "./scripts/transpile/wrap-constructor-pattern" 8 | ] 9 | }, 10 | "es": { 11 | "plugins": [ 12 | "annotate-pure-calls", 13 | ["import-export-rename", {"^(.+?)(?:\\.m?js)?$": "$1.js"}], 14 | "./scripts/transpile/wrap-constructor-pattern" 15 | ] 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.js] 12 | indent_style = space 13 | indent_size = 2 14 | max_line_length = 100 15 | 16 | [*.json] 17 | indent_style = space 18 | indent_size = 2 19 | 20 | [*.md] 21 | # Two trailing spaces => newline in GitHub-flavored markdown 22 | trim_trailing_whitespace = false 23 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | **/*.min.js 2 | test/index.html 3 | test/bundle.js 4 | es/** 5 | src/** 6 | dist/** 7 | lib/test/** 8 | node_modules/** 9 | bower_components/** 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js text eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /es 2 | /src 3 | /lib/bench/report/ 4 | /lib/docs/public/ 5 | /node_modules/ 6 | /npm-debug.log 7 | /lib/test/bundle.js 8 | /tmp 9 | /bower_components/ 10 | /dist/gh-pages/ 11 | /tmp-test-bundle.js 12 | /coverage/ 13 | .idea/* 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - 8 5 | - 10 6 | before_script: 7 | - npm run lint 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | See the [upgrade guides][1]. 4 | 5 | 6 | [1]: https://github.com/ramda/ramda/issues?q=label%3A%22upgrade+guide%22 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | XYZ = node_modules/.bin/xyz --repo git@github.com:ramda/ramda.git --script scripts/prepublish 2 | 3 | 4 | dist/ramda.js: 5 | npm run build:umd 6 | 7 | dist/ramda.min.js: 8 | npm run build:umd:min 9 | 10 | 11 | .PHONY: clean 12 | clean: 13 | rm -f -- dist/ramda.js 14 | 15 | 16 | .PHONY: lint 17 | lint: 18 | 19 | 20 | .PHONY: release-major release-minor release-patch 21 | release-major release-minor release-patch: 22 | @$(XYZ) --increment $(@:release-%=%) 23 | 24 | 25 | .PHONY: setup 26 | setup: 27 | npm install 28 | 29 | 30 | .PHONY: test 31 | test: dist/ramda.js 32 | npm test 33 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ramda", 3 | "main": "dist/ramda.js", 4 | "homepage": "https://github.com/ramda/ramda", 5 | "authors": [ 6 | "(Scott Sauyet )", 7 | "(Michael Hurley )", 8 | "(David Chambers )" 9 | ], 10 | "description": "A practical functional library for Javascript programmers.", 11 | "moduleType": [ 12 | "amd", 13 | "globals", 14 | "node" 15 | ], 16 | "keywords": [ 17 | "functional" 18 | ], 19 | "license": "MIT", 20 | "ignore": [ 21 | "**/.*", 22 | "node_modules", 23 | "bower_components", 24 | "source", 25 | "es", 26 | "test", 27 | "tests", 28 | "examples", 29 | "logo" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /lib/bench/concat.bench.js: -------------------------------------------------------------------------------- 1 | var concat = require('../..').concat; 2 | 3 | var s1 = [8, 2, 85, 2, 34, 3, 23]; 4 | var s2 = [247, 57, 8, 0, 6, 5, 46, 54, 643]; 5 | var concatS1 = concat(s1); 6 | 7 | module.exports = { 8 | name: 'concat', 9 | tests: { 10 | 'concat(s1, s2)': function() { 11 | concat(s1, s2); 12 | }, 13 | 'concat(s1)(s2)': function() { 14 | concat(s1)(s2); 15 | }, 16 | 'concatS1(s2)': function() { 17 | concatS1(s2); 18 | }, 19 | 'native concat': function() { 20 | s1.concat(s2); 21 | } 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /lib/bench/curry.bench.js: -------------------------------------------------------------------------------- 1 | var curry = require('../..').curry; 2 | 3 | function mult(x, y) { return x * y; } 4 | var mult4 = curry(mult)(4); 5 | function manmult(x) { 6 | return function(y) { 7 | return x * y; 8 | }; 9 | } 10 | var manual = manmult(4); 11 | 12 | module.exports = { 13 | name: 'curry', 14 | tests: { 15 | 'mult4(100)': function() { 16 | mult4(100); 17 | }, 18 | 'manual(100)': function() { 19 | manual(100); 20 | } 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /lib/bench/each.bench.js: -------------------------------------------------------------------------------- 1 | var forEach = require('../..').forEach; 2 | 3 | var nums = [8, 2, 85, 2, 34, 3, 23, 247, 57, 8, 0, 6, 5, 46, 54, 643]; 4 | 5 | module.exports = { 6 | name: 'forEach', 7 | tests: { 8 | 'forEach(x2, nums)': function() { 9 | var result = []; 10 | forEach(function(x) { result.push(x); }, nums); 11 | }, 12 | 'forEach(x2)(nums)': function() { 13 | var result = []; 14 | forEach(function(x) { result.push(x); })(nums); 15 | }, 16 | 'native forEach': function() { 17 | var result = []; 18 | nums.forEach(function(x) { result.push(x); }); 19 | } 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /lib/bench/either.bench.js: -------------------------------------------------------------------------------- 1 | var R = require('../..'); 2 | 3 | var gt10 = x => x > 10; 4 | var even = x => x % 2 === 0; 5 | 6 | module.exports = { 7 | name: 'either', 8 | tests: { 9 | 'either(gt10, even)(101)': function() { 10 | R.either(gt10, even)(101); 11 | }, 12 | 'either(gt10)(even)(101)': function() { 13 | R.either(gt10)(even)(101); 14 | }, 15 | 'either(gt10, even)(8)': function() { 16 | R.either(gt10, even)(8); 17 | }, 18 | 'either(gt10)(even)(8)': function() { 19 | R.either(gt10)(even)(8); 20 | }, 21 | 'native gt10(101) || even(101)': function() { 22 | gt10(101) || even(101); 23 | }, 24 | 'native gt10(8) || even(8)': function() { 25 | gt10(8) || even(8); 26 | } 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /lib/bench/filter.bench.js: -------------------------------------------------------------------------------- 1 | var filter = require('../..').filter; 2 | 3 | var nums = [8, 2, 85, 2, 34, 3, 23, 247, 57, 8, 0, 6, 5, 46, 54, 643]; 4 | function isEven(x) { return x % 2 === 0; } 5 | var filterEven = filter(isEven); 6 | 7 | module.exports = { 8 | name: 'filter', 9 | tests: { 10 | 'filter(isEven, nums)': function() { 11 | filter(isEven, nums); 12 | }, 13 | 'filter(isEven)(nums)': function() { 14 | filter(isEven)(nums); 15 | }, 16 | 'filterEven(nums)': function() { 17 | filterEven(nums); 18 | }, 19 | 'native filter': function() { 20 | nums.filter(isEven); 21 | } 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /lib/bench/find.bench.js: -------------------------------------------------------------------------------- 1 | var find = require('../..').find; 2 | 3 | var nums = [8, 2, 85, 2, 34, 3, 23, 247, 57, 8, 0, 6, 5, 46, 54, 643]; 4 | function isZero(x) { return x === 0; } 5 | var findZero = find(isZero); 6 | 7 | module.exports = { 8 | name: 'find', 9 | tests: { 10 | 'find(isZero, nums)': function() { 11 | find(isZero, nums); 12 | }, 13 | 'find(isZero)(nums)': function() { 14 | find(isZero)(nums); 15 | }, 16 | 'findZero(nums)': function() { 17 | findZero(nums); 18 | }, 19 | 'native find': function() { 20 | nums.find(isZero); 21 | } 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /lib/bench/findIndex.bench.js: -------------------------------------------------------------------------------- 1 | var findIndex = require('../..').findIndex; 2 | 3 | var nums = [8, 2, 85, 2, 34, 3, 23, 247, 57, 8, 0, 6, 5, 46, 54, 643]; 4 | function isZero(x) { return x === 0; } 5 | var findIndexZero = findIndex(isZero); 6 | 7 | module.exports = { 8 | name: 'findIndex', 9 | tests: { 10 | 'findIndex(isZero, nums)': function() { 11 | findIndex(isZero, nums); 12 | }, 13 | 'findIndex(isZero)(nums)': function() { 14 | findIndex(isZero)(nums); 15 | }, 16 | 'findIndexZero(nums)': function() { 17 | findIndexZero(nums); 18 | }, 19 | 'native findIndex': function() { 20 | nums.findIndex(isZero); 21 | } 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /lib/bench/includes.bench.js: -------------------------------------------------------------------------------- 1 | var includes = require('../..').includes; 2 | 3 | var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''); 4 | 5 | function randomLowerAlpha() { 6 | return String.fromCharCode(97 + (Math.random() * 26) >>> 0); 7 | } 8 | 9 | function nativeIncludes(x, xs) { 10 | return xs.includes(x); 11 | } 12 | 13 | module.exports = { 14 | name: 'includes', 15 | tests: { 16 | 'includes(c, cs)': function() { 17 | return includes(randomLowerAlpha(), alphabet); 18 | }, 19 | 'native includes': function() { 20 | return nativeIncludes(randomLowerAlpha(), alphabet); 21 | } 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /lib/bench/indexof.bench.js: -------------------------------------------------------------------------------- 1 | var indexOf = require('../..').indexOf; 2 | 3 | var nums = [8, 2, 85, 2, 34, 3, 23, 247, 57, 8, 0, 6, 5, 46, 54, 643]; 4 | var idxOf23 = indexOf(23); 5 | 6 | module.exports = { 7 | name: 'indexOf', 8 | tests: { 9 | 'indexOf(sq, nums)': function() { 10 | indexOf(23, nums); 11 | }, 12 | 'indexOf(sq)(nums)': function() { 13 | indexOf(23)(nums); 14 | }, 15 | 'idxOf23(nums)': function() { 16 | idxOf23(nums); 17 | }, 18 | 'native indexOf': function() { 19 | nums.indexOf(23); 20 | } 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /lib/bench/map.bench.js: -------------------------------------------------------------------------------- 1 | var map = require('../..').map; 2 | 3 | var nums = [8, 2, 85, 2, 34, 3, 23, 247, 57, 8, 0, 6, 5, 46, 54, 643]; 4 | function sq(x) { return x * x; } 5 | var mapSq = map(sq); 6 | 7 | module.exports = { 8 | name: 'map', 9 | tests: { 10 | 'map(sq, nums)': function() { 11 | map(sq, nums); 12 | }, 13 | 'map(sq)(nums)': function() { 14 | map(sq)(nums); 15 | }, 16 | 'mapSq(nums)': function() { 17 | mapSq(nums); 18 | }, 19 | 'native map': function() { 20 | nums.map(sq); 21 | } 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /lib/bench/maxWith.bench.js: -------------------------------------------------------------------------------- 1 | var R = require('../..'); 2 | var maxBy = R.maxBy; 3 | var computer = R.prop('val'); 4 | var maxVal = maxBy(computer); 5 | var vals = R.map(function(n) { return {key: n * 5, val: String.fromCharCode(n * 5)}; }, R.range(1, 100)); 6 | 7 | module.exports = { 8 | name: 'maxBy', 9 | tests: { 10 | 'maxBy(computer, nums)': function() { 11 | maxBy(computer, vals); 12 | }, 13 | 'maxBy(computer)(vals)': function() { 14 | maxBy(computer)(vals); 15 | }, 16 | 'maxVal(vals)': function() { 17 | maxVal(vals); 18 | } 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /lib/bench/propEq.bench.js: -------------------------------------------------------------------------------- 1 | var propEq = require('../..').propEq; 2 | 3 | module.exports = { 4 | name: 'propEq', 5 | tests: { 6 | 'propEq("value", [1, 2, 3], {value: [1, 2, 3]})': function() { 7 | propEq('value', [1, 2, 3], {value: [1, 2, 3]}); 8 | } 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /lib/bench/reduce.bench.js: -------------------------------------------------------------------------------- 1 | var reduce = require('../..').reduce; 2 | var nums = [8, 2, 85, 2, 34, 3, 23, 247, 57, 8, 0, 6, 5, 46, 54, 643]; 3 | function add(acc, x) { return acc + x; } 4 | var reduceAdd = reduce(add, 0); 5 | 6 | module.exports = { 7 | name: 'reduce', 8 | tests: { 9 | 'reduce(add, 0, nums)': function() { 10 | reduce(add, 0, nums); 11 | }, 12 | 'reduce(add, 0)(nums)': function() { 13 | reduce(add, 0)(nums); 14 | }, 15 | 'reduceAdd(nums)': function() { 16 | reduceAdd(nums); 17 | }, 18 | 'native reduce': function() { 19 | nums.reduce(add, 0); 20 | } 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /lib/sauce/android.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | { 3 | browserName: 'android', 4 | version: '4.4', 5 | deviceName: 'Android', 6 | 'device-orientation': 'portrait', 7 | platform: 'Linux' 8 | }, 9 | { 10 | browserName: 'android', 11 | version: '4.3', 12 | deviceName: 'Android', 13 | 'device-orientation': 'portrait', 14 | platform: 'Linux' 15 | }, 16 | { 17 | browserName: 'android', 18 | version: '4.2', 19 | deviceName: 'Android', 20 | 'device-orientation': 'portrait', 21 | platform: 'Linux' 22 | }, 23 | { 24 | browserName: 'android', 25 | version: '4.1', 26 | deviceName: 'Android', 27 | 'device-orientation': 'portrait', 28 | platform: 'Linux' 29 | }, 30 | { 31 | browserName: 'android', 32 | version: '4.0', 33 | deviceName: 'Android', 34 | 'device-orientation': 'portrait', 35 | platform: 'Linux' 36 | } 37 | ]; 38 | -------------------------------------------------------------------------------- /lib/sauce/apple.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | { 3 | browserName: 'safari', 4 | version: '5', 5 | platform: 'OS X 10.6' 6 | }, 7 | { 8 | browserName: 'safari', 9 | version: '6', 10 | platform: 'OS X 10.8' 11 | }, 12 | { 13 | browserName: 'safari', 14 | version: '7', 15 | platform: 'OS X 10.9' 16 | }, 17 | { 18 | browserName: 'safari', 19 | version: '8', 20 | platform: 'OS X 10.10' 21 | } 22 | ]; 23 | -------------------------------------------------------------------------------- /lib/sauce/browsers.js: -------------------------------------------------------------------------------- 1 | var windows = require('./windows'); 2 | var apple = require('./apple'); 3 | var linux = require('./linux'); 4 | var android = require('./android'); 5 | var ios = require('./ios'); 6 | 7 | module.exports = windows.concat(apple, android, ios, linux); 8 | -------------------------------------------------------------------------------- /lib/sauce/conf.js: -------------------------------------------------------------------------------- 1 | var envvar = require('envvar'); 2 | var browsers = require('./browsers'); 3 | module.exports = { 4 | all: { 5 | options: { 6 | urls: ['localhost:3210/test/index.html'], 7 | build: envvar.number('CI_BUILD_NUMBER', 0), 8 | testname: 'Ramda Sauce Unit Test', 9 | browsers: browsers 10 | } 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /lib/sauce/ios.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | { 3 | browserName: 'ipad', 4 | version: '8.1', 5 | 'device-orientation': 'portrait', 6 | platform: 'OS X 10.9' 7 | }, 8 | { 9 | browserName: 'ipad', 10 | version: '4.3', 11 | 'device-orientation': 'portrait', 12 | platform: 'OS X 10.6' 13 | } 14 | ]; 15 | -------------------------------------------------------------------------------- /lib/sauce/linux.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | { 3 | browserName: 'firefox', 4 | version: '33', 5 | platform: 'Linux' 6 | }, 7 | { 8 | browserName: 'chrome', 9 | version: '38', 10 | platform: 'Linux' 11 | } 12 | ]; 13 | -------------------------------------------------------------------------------- /lib/sauce/server.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | server: { 3 | options: { 4 | hostname: 'localhost', 5 | port: 3210, 6 | base: '.' 7 | } 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /lib/sauce/windows.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | { 3 | browserName: 'internet explorer', 4 | version: '11', 5 | platform: 'Windows 8.1' 6 | }, 7 | { 8 | browserName: 'internet explorer', 9 | version: '10', 10 | platform: 'Windows 8' 11 | }, 12 | { 13 | browserName: 'internet explorer', 14 | version: '9', 15 | platform: 'Windows 7' 16 | }, 17 | { 18 | browserName: 'internet explorer', 19 | version: '8', 20 | platform: 'Windows 7' 21 | }, 22 | { 23 | browserName: 'internet explorer', 24 | version: '7', 25 | platform: 'XP' 26 | }, 27 | { 28 | browserName: 'chrome', 29 | version: '38', 30 | platform: 'Windows 8.1' 31 | }, 32 | { 33 | browserName: 'firefox', 34 | version: '33', 35 | platform: 'Windows 8.1' 36 | } 37 | ]; 38 | -------------------------------------------------------------------------------- /repl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | const repl = require('repl'); 6 | 7 | process.env.BABEL_ENV = 'cjs'; 8 | require('babel-register'); 9 | 10 | const R = require('./source'); 11 | 12 | const r = repl.start(); 13 | 14 | Object.assign(r.context, {R}, R); 15 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | var uglify = require('rollup-plugin-terser').terser; 2 | var pkg = require('./package.json'); 3 | 4 | var banner = '// Ramda v' + pkg.version + '\n' 5 | + '// https://github.com/ramda/ramda\n' 6 | + '// (c) 2013-' + new Date().getFullYear() + ' Scott Sauyet, Michael Hurley, and David Chambers\n' 7 | + '// Ramda may be freely distributed under the MIT license.\n'; 8 | 9 | var input = 'source/index.js'; 10 | 11 | var config = { 12 | input: input, 13 | output: { 14 | format: 'umd', 15 | name: 'R', 16 | exports: 'named' 17 | }, 18 | banner: banner, 19 | plugins: [] 20 | }; 21 | 22 | if (process.env.NODE_ENV === 'production') { 23 | config.plugins.push( 24 | uglify({ 25 | compress: { 26 | pure_getters: true, 27 | unsafe: true, 28 | unsafe_comps: true, 29 | warnings: false 30 | } 31 | }) 32 | ); 33 | } 34 | 35 | module.exports = config; 36 | -------------------------------------------------------------------------------- /scripts/BOOKMARKLET.tmpl.md: -------------------------------------------------------------------------------- 1 | # Ramda Bookmarklet 2 | 3 | Use this bookmarklet to load Ramda on any website. To "install": 4 | 5 | 1. Create a new bookmark in your bookmarks bar (what it points to doesn't 6 | matter, any page) 7 | 8 | 2. Edit the new bookmark and replace the `URL` with the following: 9 | 10 | ```javascript 11 | javascript:{{{bookmarklet}}} 12 | ``` 13 | -------------------------------------------------------------------------------- /scripts/doc-blob: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var fs = require('fs'); 4 | var YAML = require('js-yaml'); 5 | 6 | var DOC_FILE = 'doc.yaml'; 7 | var DATA_FILE = 'docs/data.json'; 8 | 9 | var text = fs.readFileSync(DOC_FILE, 'utf-8'); 10 | var docs = YAML.safeLoad(text); 11 | var data = JSON.stringify(docs, null, 4); 12 | 13 | fs.writeFileSync(DATA_FILE, data, 'utf-8'); 14 | -------------------------------------------------------------------------------- /source/F.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** 4 | * A function that always returns `false`. Any passed in parameters are ignored. 5 | * 6 | * @func 7 | * @memberOf R 8 | * @since v0.9.0 9 | * @category Function 10 | * @sig * -> Boolean 11 | * @param {*} 12 | * @return {Boolean} 13 | * @see R.T 14 | * @example 15 | * 16 | * R.F(); //=> false 17 | */ 18 | var F = function() {return false;}; 19 | export default F; 20 | -------------------------------------------------------------------------------- /source/T.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** 4 | * A function that always returns `true`. Any passed in parameters are ignored. 5 | * 6 | * @func 7 | * @memberOf R 8 | * @since v0.9.0 9 | * @category Function 10 | * @sig * -> Boolean 11 | * @param {*} 12 | * @return {Boolean} 13 | * @see R.F 14 | * @example 15 | * 16 | * R.T(); //=> true 17 | */ 18 | var T = function() {return true;}; 19 | export default T; 20 | -------------------------------------------------------------------------------- /source/__.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A special placeholder value used to specify "gaps" within curried functions, 3 | * allowing partial application of any combination of arguments, regardless of 4 | * their positions. 5 | * 6 | * If `g` is a curried ternary function and `_` is `R.__`, the following are 7 | * equivalent: 8 | * 9 | * - `g(1, 2, 3)` 10 | * - `g(_, 2, 3)(1)` 11 | * - `g(_, _, 3)(1)(2)` 12 | * - `g(_, _, 3)(1, 2)` 13 | * - `g(_, 2, _)(1, 3)` 14 | * - `g(_, 2)(1)(3)` 15 | * - `g(_, 2)(1, 3)` 16 | * - `g(_, 2)(_, 3)(1)` 17 | * 18 | * @name __ 19 | * @constant 20 | * @memberOf R 21 | * @since v0.6.0 22 | * @category Function 23 | * @example 24 | * 25 | * const greet = R.replace('{name}', R.__, 'Hello, {name}!'); 26 | * greet('Alice'); //=> 'Hello, Alice!' 27 | */ 28 | export default {'@@functional/placeholder': true}; 29 | -------------------------------------------------------------------------------- /source/add.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Adds two values. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.1.0 10 | * @category Math 11 | * @sig Number -> Number -> Number 12 | * @param {Number} a 13 | * @param {Number} b 14 | * @return {Number} 15 | * @see R.subtract 16 | * @example 17 | * 18 | * R.add(2, 3); //=> 5 19 | * R.add(7)(10); //=> 17 20 | */ 21 | var add = _curry2(function add(a, b) { 22 | return Number(a) + Number(b); 23 | }); 24 | export default add; 25 | -------------------------------------------------------------------------------- /source/always.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | 3 | 4 | /** 5 | * Returns a function that always returns the given value. Note that for 6 | * non-primitives the value returned is a reference to the original value. 7 | * 8 | * This function is known as `const`, `constant`, or `K` (for K combinator) in 9 | * other languages and libraries. 10 | * 11 | * @func 12 | * @memberOf R 13 | * @since v0.1.0 14 | * @category Function 15 | * @sig a -> (* -> a) 16 | * @param {*} val The value to wrap in a function 17 | * @return {Function} A Function :: * -> val. 18 | * @example 19 | * 20 | * const t = R.always('Tee'); 21 | * t(); //=> 'Tee' 22 | */ 23 | var always = _curry1(function always(val) { 24 | return function() { 25 | return val; 26 | }; 27 | }); 28 | export default always; 29 | -------------------------------------------------------------------------------- /source/and.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Returns `true` if both arguments are `true`; `false` otherwise. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.1.0 10 | * @category Logic 11 | * @sig a -> b -> a | b 12 | * @param {Any} a 13 | * @param {Any} b 14 | * @return {Any} the first argument if it is falsy, otherwise the second argument. 15 | * @see R.both 16 | * @example 17 | * 18 | * R.and(true, true); //=> true 19 | * R.and(true, false); //=> false 20 | * R.and(false, true); //=> false 21 | * R.and(false, false); //=> false 22 | */ 23 | var and = _curry2(function and(a, b) { 24 | return a && b; 25 | }); 26 | export default and; 27 | -------------------------------------------------------------------------------- /source/append.js: -------------------------------------------------------------------------------- 1 | import _concat from './internal/_concat'; 2 | import _curry2 from './internal/_curry2'; 3 | 4 | 5 | /** 6 | * Returns a new list containing the contents of the given list, followed by 7 | * the given element. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.1.0 12 | * @category List 13 | * @sig a -> [a] -> [a] 14 | * @param {*} el The element to add to the end of the new list. 15 | * @param {Array} list The list of elements to add a new item to. 16 | * list. 17 | * @return {Array} A new list containing the elements of the old list followed by `el`. 18 | * @see R.prepend 19 | * @example 20 | * 21 | * R.append('tests', ['write', 'more']); //=> ['write', 'more', 'tests'] 22 | * R.append('tests', []); //=> ['tests'] 23 | * R.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']] 24 | */ 25 | var append = _curry2(function append(el, list) { 26 | return _concat(list, [el]); 27 | }); 28 | export default append; 29 | -------------------------------------------------------------------------------- /source/apply.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Applies function `fn` to the argument list `args`. This is useful for 6 | * creating a fixed-arity function from a variadic function. `fn` should be a 7 | * bound function if context is significant. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.7.0 12 | * @category Function 13 | * @sig (*... -> a) -> [*] -> a 14 | * @param {Function} fn The function which will be called with `args` 15 | * @param {Array} args The arguments to call `fn` with 16 | * @return {*} result The result, equivalent to `fn(...args)` 17 | * @see R.call, R.unapply 18 | * @example 19 | * 20 | * const nums = [1, 2, 3, -99, 42, 6, 7]; 21 | * R.apply(Math.max, nums); //=> 42 22 | * @symb R.apply(f, [a, b, c]) = f(a, b, c) 23 | */ 24 | var apply = _curry2(function apply(fn, args) { 25 | return fn.apply(this, args); 26 | }); 27 | export default apply; 28 | -------------------------------------------------------------------------------- /source/applyTo.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | /** 4 | * Takes a value and applies a function to it. 5 | * 6 | * This function is also known as the `thrush` combinator. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.25.0 11 | * @category Function 12 | * @sig a -> (a -> b) -> b 13 | * @param {*} x The value 14 | * @param {Function} f The function to apply 15 | * @return {*} The result of applying `f` to `x` 16 | * @example 17 | * 18 | * const t42 = R.applyTo(42); 19 | * t42(R.identity); //=> 42 20 | * t42(R.add(1)); //=> 43 21 | */ 22 | var applyTo = _curry2(function applyTo(x, f) { return f(x); }); 23 | export default applyTo; 24 | -------------------------------------------------------------------------------- /source/clone.js: -------------------------------------------------------------------------------- 1 | import _clone from './internal/_clone'; 2 | import _curry1 from './internal/_curry1'; 3 | 4 | 5 | /** 6 | * Creates a deep copy of the value which may contain (nested) `Array`s and 7 | * `Object`s, `Number`s, `String`s, `Boolean`s and `Date`s. `Function`s are 8 | * assigned by reference rather than copied 9 | * 10 | * Dispatches to a `clone` method if present. 11 | * 12 | * @func 13 | * @memberOf R 14 | * @since v0.1.0 15 | * @category Object 16 | * @sig {*} -> {*} 17 | * @param {*} value The object or array to clone 18 | * @return {*} A deeply cloned copy of `val` 19 | * @example 20 | * 21 | * const objects = [{}, {}, {}]; 22 | * const objectsClone = R.clone(objects); 23 | * objects === objectsClone; //=> false 24 | * objects[0] === objectsClone[0]; //=> false 25 | */ 26 | var clone = _curry1(function clone(value) { 27 | return value != null && typeof value.clone === 'function' ? 28 | value.clone() : 29 | _clone(value, [], [], true); 30 | }); 31 | export default clone; 32 | -------------------------------------------------------------------------------- /source/complement.js: -------------------------------------------------------------------------------- 1 | import lift from './lift'; 2 | import not from './not'; 3 | 4 | 5 | /** 6 | * Takes a function `f` and returns a function `g` such that if called with the same arguments 7 | * when `f` returns a "truthy" value, `g` returns `false` and when `f` returns a "falsy" value `g` returns `true`. 8 | * 9 | * `R.complement` may be applied to any functor 10 | * 11 | * @func 12 | * @memberOf R 13 | * @since v0.12.0 14 | * @category Logic 15 | * @sig (*... -> *) -> (*... -> Boolean) 16 | * @param {Function} f 17 | * @return {Function} 18 | * @see R.not 19 | * @example 20 | * 21 | * const isNotNil = R.complement(R.isNil); 22 | * isNil(null); //=> true 23 | * isNotNil(null); //=> false 24 | * isNil(7); //=> false 25 | * isNotNil(7); //=> true 26 | */ 27 | var complement = lift(not); 28 | export default complement; 29 | -------------------------------------------------------------------------------- /source/dec.js: -------------------------------------------------------------------------------- 1 | import add from './add'; 2 | 3 | 4 | /** 5 | * Decrements its argument. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.9.0 10 | * @category Math 11 | * @sig Number -> Number 12 | * @param {Number} n 13 | * @return {Number} n - 1 14 | * @see R.inc 15 | * @example 16 | * 17 | * R.dec(42); //=> 41 18 | */ 19 | var dec = add(-1); 20 | export default dec; 21 | -------------------------------------------------------------------------------- /source/dissoc.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Returns a new object that does not contain a `prop` property. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.10.0 10 | * @category Object 11 | * @sig String -> {k: v} -> {k: v} 12 | * @param {String} prop The name of the property to dissociate 13 | * @param {Object} obj The object to clone 14 | * @return {Object} A new object equivalent to the original but without the specified property 15 | * @see R.assoc, R.omit 16 | * @example 17 | * 18 | * R.dissoc('b', {a: 1, b: 2, c: 3}); //=> {a: 1, c: 3} 19 | */ 20 | var dissoc = _curry2(function dissoc(prop, obj) { 21 | var result = {}; 22 | for (var p in obj) { 23 | result[p] = obj[p]; 24 | } 25 | delete result[prop]; 26 | return result; 27 | }); 28 | export default dissoc; 29 | -------------------------------------------------------------------------------- /source/divide.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Divides two numbers. Equivalent to `a / b`. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.1.0 10 | * @category Math 11 | * @sig Number -> Number -> Number 12 | * @param {Number} a The first value. 13 | * @param {Number} b The second value. 14 | * @return {Number} The result of `a / b`. 15 | * @see R.multiply 16 | * @example 17 | * 18 | * R.divide(71, 100); //=> 0.71 19 | * 20 | * const half = R.divide(R.__, 2); 21 | * half(42); //=> 21 22 | * 23 | * const reciprocal = R.divide(1); 24 | * reciprocal(4); //=> 0.25 25 | */ 26 | var divide = _curry2(function divide(a, b) { return a / b; }); 27 | export default divide; 28 | -------------------------------------------------------------------------------- /source/endsWith.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | import equals from './equals'; 3 | import takeLast from './takeLast'; 4 | 5 | /** 6 | * Checks if a list ends with the provided sublist. 7 | * 8 | * Similarly, checks if a string ends with the provided substring. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.24.0 13 | * @category List 14 | * @sig [a] -> [a] -> Boolean 15 | * @sig String -> String -> Boolean 16 | * @param {*} suffix 17 | * @param {*} list 18 | * @return {Boolean} 19 | * @see R.startsWith 20 | * @example 21 | * 22 | * R.endsWith('c', 'abc') //=> true 23 | * R.endsWith('b', 'abc') //=> false 24 | * R.endsWith(['c'], ['a', 'b', 'c']) //=> true 25 | * R.endsWith(['b'], ['a', 'b', 'c']) //=> false 26 | */ 27 | var endsWith = _curry2(function(suffix, list) { 28 | return equals(takeLast(suffix.length, list), suffix); 29 | }); 30 | export default endsWith; 31 | -------------------------------------------------------------------------------- /source/eqBy.js: -------------------------------------------------------------------------------- 1 | import _curry3 from './internal/_curry3'; 2 | import equals from './equals'; 3 | 4 | 5 | /** 6 | * Takes a function and two values in its domain and returns `true` if the 7 | * values map to the same value in the codomain; `false` otherwise. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.18.0 12 | * @category Relation 13 | * @sig (a -> b) -> a -> a -> Boolean 14 | * @param {Function} f 15 | * @param {*} x 16 | * @param {*} y 17 | * @return {Boolean} 18 | * @example 19 | * 20 | * R.eqBy(Math.abs, 5, -5); //=> true 21 | */ 22 | var eqBy = _curry3(function eqBy(f, x, y) { 23 | return equals(f(x), f(y)); 24 | }); 25 | export default eqBy; 26 | -------------------------------------------------------------------------------- /source/eqProps.js: -------------------------------------------------------------------------------- 1 | import _curry3 from './internal/_curry3'; 2 | import equals from './equals'; 3 | 4 | 5 | /** 6 | * Reports whether two objects have the same value, in [`R.equals`](#equals) 7 | * terms, for the specified property. Useful as a curried predicate. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.1.0 12 | * @category Object 13 | * @sig k -> {k: v} -> {k: v} -> Boolean 14 | * @param {String} prop The name of the property to compare 15 | * @param {Object} obj1 16 | * @param {Object} obj2 17 | * @return {Boolean} 18 | * 19 | * @example 20 | * 21 | * const o1 = { a: 1, b: 2, c: 3, d: 4 }; 22 | * const o2 = { a: 10, b: 20, c: 3, d: 40 }; 23 | * R.eqProps('a', o1, o2); //=> false 24 | * R.eqProps('c', o1, o2); //=> true 25 | */ 26 | var eqProps = _curry3(function eqProps(prop, obj1, obj2) { 27 | return equals(obj1[prop], obj2[prop]); 28 | }); 29 | export default eqProps; 30 | -------------------------------------------------------------------------------- /source/equals.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | import _equals from './internal/_equals'; 3 | 4 | 5 | /** 6 | * Returns `true` if its arguments are equivalent, `false` otherwise. Handles 7 | * cyclical data structures. 8 | * 9 | * Dispatches symmetrically to the `equals` methods of both arguments, if 10 | * present. 11 | * 12 | * @func 13 | * @memberOf R 14 | * @since v0.15.0 15 | * @category Relation 16 | * @sig a -> b -> Boolean 17 | * @param {*} a 18 | * @param {*} b 19 | * @return {Boolean} 20 | * @example 21 | * 22 | * R.equals(1, 1); //=> true 23 | * R.equals(1, '1'); //=> false 24 | * R.equals([1, 2, 3], [1, 2, 3]); //=> true 25 | * 26 | * const a = {}; a.v = a; 27 | * const b = {}; b.v = b; 28 | * R.equals(a, b); //=> true 29 | */ 30 | var equals = _curry2(function equals(a, b) { 31 | return _equals(a, b, [], []); 32 | }); 33 | export default equals; 34 | -------------------------------------------------------------------------------- /source/flatten.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import _makeFlat from './internal/_makeFlat'; 3 | 4 | 5 | /** 6 | * Returns a new list by pulling every item out of it (and all its sub-arrays) 7 | * and putting them in a new array, depth-first. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.1.0 12 | * @category List 13 | * @sig [a] -> [b] 14 | * @param {Array} list The array to consider. 15 | * @return {Array} The flattened list. 16 | * @see R.unnest 17 | * @example 18 | * 19 | * R.flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]); 20 | * //=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] 21 | */ 22 | var flatten = _curry1(_makeFlat(true)); 23 | export default flatten; 24 | -------------------------------------------------------------------------------- /source/fromPairs.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | 3 | 4 | /** 5 | * Creates a new object from a list key-value pairs. If a key appears in 6 | * multiple pairs, the rightmost pair is included in the object. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.3.0 11 | * @category List 12 | * @sig [[k,v]] -> {k: v} 13 | * @param {Array} pairs An array of two-element arrays that will be the keys and values of the output object. 14 | * @return {Object} The object made by pairing up `keys` and `values`. 15 | * @see R.toPairs, R.pair 16 | * @example 17 | * 18 | * R.fromPairs([['a', 1], ['b', 2], ['c', 3]]); //=> {a: 1, b: 2, c: 3} 19 | */ 20 | var fromPairs = _curry1(function fromPairs(pairs) { 21 | var result = {}; 22 | var idx = 0; 23 | while (idx < pairs.length) { 24 | result[pairs[idx][0]] = pairs[idx][1]; 25 | idx += 1; 26 | } 27 | return result; 28 | }); 29 | export default fromPairs; 30 | -------------------------------------------------------------------------------- /source/gt.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Returns `true` if the first argument is greater than the second; `false` 6 | * otherwise. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.1.0 11 | * @category Relation 12 | * @sig Ord a => a -> a -> Boolean 13 | * @param {*} a 14 | * @param {*} b 15 | * @return {Boolean} 16 | * @see R.lt 17 | * @example 18 | * 19 | * R.gt(2, 1); //=> true 20 | * R.gt(2, 2); //=> false 21 | * R.gt(2, 3); //=> false 22 | * R.gt('a', 'z'); //=> false 23 | * R.gt('z', 'a'); //=> true 24 | */ 25 | var gt = _curry2(function gt(a, b) { return a > b; }); 26 | export default gt; 27 | -------------------------------------------------------------------------------- /source/gte.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Returns `true` if the first argument is greater than or equal to the second; 6 | * `false` otherwise. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.1.0 11 | * @category Relation 12 | * @sig Ord a => a -> a -> Boolean 13 | * @param {Number} a 14 | * @param {Number} b 15 | * @return {Boolean} 16 | * @see R.lte 17 | * @example 18 | * 19 | * R.gte(2, 1); //=> true 20 | * R.gte(2, 2); //=> true 21 | * R.gte(2, 3); //=> false 22 | * R.gte('a', 'z'); //=> false 23 | * R.gte('z', 'a'); //=> true 24 | */ 25 | var gte = _curry2(function gte(a, b) { return a >= b; }); 26 | export default gte; 27 | -------------------------------------------------------------------------------- /source/hasIn.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Returns whether or not an object or its prototype chain has a property with 6 | * the specified name 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.7.0 11 | * @category Object 12 | * @sig s -> {s: x} -> Boolean 13 | * @param {String} prop The name of the property to check for. 14 | * @param {Object} obj The object to query. 15 | * @return {Boolean} Whether the property exists. 16 | * @example 17 | * 18 | * function Rectangle(width, height) { 19 | * this.width = width; 20 | * this.height = height; 21 | * } 22 | * Rectangle.prototype.area = function() { 23 | * return this.width * this.height; 24 | * }; 25 | * 26 | * const square = new Rectangle(2, 2); 27 | * R.hasIn('width', square); //=> true 28 | * R.hasIn('area', square); //=> true 29 | */ 30 | var hasIn = _curry2(function hasIn(prop, obj) { 31 | return prop in obj; 32 | }); 33 | export default hasIn; 34 | -------------------------------------------------------------------------------- /source/head.js: -------------------------------------------------------------------------------- 1 | import nth from './nth'; 2 | 3 | 4 | /** 5 | * Returns the first element of the given list or string. In some libraries 6 | * this function is named `first`. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.1.0 11 | * @category List 12 | * @sig [a] -> a | Undefined 13 | * @sig String -> String 14 | * @param {Array|String} list 15 | * @return {*} 16 | * @see R.tail, R.init, R.last 17 | * @example 18 | * 19 | * R.head(['fi', 'fo', 'fum']); //=> 'fi' 20 | * R.head([]); //=> undefined 21 | * 22 | * R.head('abc'); //=> 'a' 23 | * R.head(''); //=> '' 24 | */ 25 | var head = nth(0); 26 | export default head; 27 | -------------------------------------------------------------------------------- /source/identical.js: -------------------------------------------------------------------------------- 1 | import _objectIs from './internal/_objectIs'; 2 | import _curry2 from './internal/_curry2'; 3 | 4 | 5 | /** 6 | * Returns true if its arguments are identical, false otherwise. Values are 7 | * identical if they reference the same memory. `NaN` is identical to `NaN`; 8 | * `0` and `-0` are not identical. 9 | * 10 | * Note this is merely a curried version of ES6 `Object.is`. 11 | * 12 | * @func 13 | * @memberOf R 14 | * @since v0.15.0 15 | * @category Relation 16 | * @sig a -> a -> Boolean 17 | * @param {*} a 18 | * @param {*} b 19 | * @return {Boolean} 20 | * @example 21 | * 22 | * const o = {}; 23 | * R.identical(o, o); //=> true 24 | * R.identical(1, 1); //=> true 25 | * R.identical(1, '1'); //=> false 26 | * R.identical([], []); //=> false 27 | * R.identical(0, -0); //=> false 28 | * R.identical(NaN, NaN); //=> true 29 | */ 30 | var identical = _curry2(_objectIs); 31 | export default identical; 32 | -------------------------------------------------------------------------------- /source/identity.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import _identity from './internal/_identity'; 3 | 4 | 5 | /** 6 | * A function that does nothing but return the parameter supplied to it. Good 7 | * as a default or placeholder function. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.1.0 12 | * @category Function 13 | * @sig a -> a 14 | * @param {*} x The value to return. 15 | * @return {*} The input value, `x`. 16 | * @example 17 | * 18 | * R.identity(1); //=> 1 19 | * 20 | * const obj = {}; 21 | * R.identity(obj) === obj; //=> true 22 | * @symb R.identity(a) = a 23 | */ 24 | var identity = _curry1(_identity); 25 | export default identity; 26 | -------------------------------------------------------------------------------- /source/inc.js: -------------------------------------------------------------------------------- 1 | import add from './add'; 2 | 3 | 4 | /** 5 | * Increments its argument. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.9.0 10 | * @category Math 11 | * @sig Number -> Number 12 | * @param {Number} n 13 | * @return {Number} n + 1 14 | * @see R.dec 15 | * @example 16 | * 17 | * R.inc(42); //=> 43 18 | */ 19 | var inc = add(1); 20 | export default inc; 21 | -------------------------------------------------------------------------------- /source/includes.js: -------------------------------------------------------------------------------- 1 | import _includes from './internal/_includes'; 2 | import _curry2 from './internal/_curry2'; 3 | 4 | /** 5 | * Returns `true` if the specified value is equal, in [`R.equals`](#equals) 6 | * terms, to at least one element of the given list; `false` otherwise. 7 | * Works also with strings. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.1.0 12 | * @category List 13 | * @sig a -> [a] -> Boolean 14 | * @param {Object} a The item to compare against. 15 | * @param {Array} list The array to consider. 16 | * @return {Boolean} `true` if an equivalent item is in the list, `false` otherwise. 17 | * @see R.any 18 | * @example 19 | * 20 | * R.includes(3, [1, 2, 3]); //=> true 21 | * R.includes(4, [1, 2, 3]); //=> false 22 | * R.includes({ name: 'Fred' }, [{ name: 'Fred' }]); //=> true 23 | * R.includes([42], [[42]]); //=> true 24 | * R.includes('ba', 'banana'); //=>true 25 | */ 26 | var includes = _curry2(_includes); 27 | export default includes; 28 | -------------------------------------------------------------------------------- /source/indexOf.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | import _indexOf from './internal/_indexOf'; 3 | import _isArray from './internal/_isArray'; 4 | 5 | 6 | /** 7 | * Returns the position of the first occurrence of an item in an array, or -1 8 | * if the item is not included in the array. [`R.equals`](#equals) is used to 9 | * determine equality. 10 | * 11 | * @func 12 | * @memberOf R 13 | * @since v0.1.0 14 | * @category List 15 | * @sig a -> [a] -> Number 16 | * @param {*} target The item to find. 17 | * @param {Array} xs The array to search in. 18 | * @return {Number} the index of the target, or -1 if the target is not found. 19 | * @see R.lastIndexOf 20 | * @example 21 | * 22 | * R.indexOf(3, [1,2,3,4]); //=> 2 23 | * R.indexOf(10, [1,2,3,4]); //=> -1 24 | */ 25 | var indexOf = _curry2(function indexOf(target, xs) { 26 | return typeof xs.indexOf === 'function' && !_isArray(xs) ? 27 | xs.indexOf(target) : 28 | _indexOf(xs, target, 0); 29 | }); 30 | export default indexOf; 31 | -------------------------------------------------------------------------------- /source/init.js: -------------------------------------------------------------------------------- 1 | import slice from './slice'; 2 | 3 | 4 | /** 5 | * Returns all but the last element of the given list or string. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.9.0 10 | * @category List 11 | * @sig [a] -> [a] 12 | * @sig String -> String 13 | * @param {*} list 14 | * @return {*} 15 | * @see R.last, R.head, R.tail 16 | * @example 17 | * 18 | * R.init([1, 2, 3]); //=> [1, 2] 19 | * R.init([1, 2]); //=> [1] 20 | * R.init([1]); //=> [] 21 | * R.init([]); //=> [] 22 | * 23 | * R.init('abc'); //=> 'ab' 24 | * R.init('ab'); //=> 'a' 25 | * R.init('a'); //=> '' 26 | * R.init(''); //=> '' 27 | */ 28 | var init = slice(0, -1); 29 | export default init; 30 | -------------------------------------------------------------------------------- /source/internal/_aperture.js: -------------------------------------------------------------------------------- 1 | export default function _aperture(n, list) { 2 | var idx = 0; 3 | var limit = list.length - (n - 1); 4 | var acc = new Array(limit >= 0 ? limit : 0); 5 | while (idx < limit) { 6 | acc[idx] = Array.prototype.slice.call(list, idx, idx + n); 7 | idx += 1; 8 | } 9 | return acc; 10 | } 11 | -------------------------------------------------------------------------------- /source/internal/_arrayFromIterator.js: -------------------------------------------------------------------------------- 1 | export default function _arrayFromIterator(iter) { 2 | var list = []; 3 | var next; 4 | while (!(next = iter.next()).done) { 5 | list.push(next.value); 6 | } 7 | return list; 8 | } 9 | -------------------------------------------------------------------------------- /source/internal/_assertPromise.js: -------------------------------------------------------------------------------- 1 | import _isFunction from './_isFunction'; 2 | import _toString from './_toString'; 3 | 4 | export default function _assertPromise(name, p) { 5 | if (p == null || !_isFunction(p.then)) { 6 | throw new TypeError('`' + name + '` expected a Promise, received ' + _toString(p, [])); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /source/internal/_checkForMethod.js: -------------------------------------------------------------------------------- 1 | import _isArray from './_isArray'; 2 | 3 | 4 | /** 5 | * This checks whether a function has a [methodname] function. If it isn't an 6 | * array it will execute that function otherwise it will default to the ramda 7 | * implementation. 8 | * 9 | * @private 10 | * @param {Function} fn ramda implemtation 11 | * @param {String} methodname property to check for a custom implementation 12 | * @return {Object} Whatever the return value of the method is. 13 | */ 14 | export default function _checkForMethod(methodname, fn) { 15 | return function() { 16 | var length = arguments.length; 17 | if (length === 0) { 18 | return fn(); 19 | } 20 | var obj = arguments[length - 1]; 21 | return (_isArray(obj) || typeof obj[methodname] !== 'function') ? 22 | fn.apply(this, arguments) : 23 | obj[methodname].apply(obj, Array.prototype.slice.call(arguments, 0, length - 1)); 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /source/internal/_cloneRegExp.js: -------------------------------------------------------------------------------- 1 | export default function _cloneRegExp(pattern) { 2 | return new RegExp(pattern.source, (pattern.global ? 'g' : '') + 3 | (pattern.ignoreCase ? 'i' : '') + 4 | (pattern.multiline ? 'm' : '') + 5 | (pattern.sticky ? 'y' : '') + 6 | (pattern.unicode ? 'u' : '')); 7 | } 8 | -------------------------------------------------------------------------------- /source/internal/_complement.js: -------------------------------------------------------------------------------- 1 | export default function _complement(f) { 2 | return function() { 3 | return !f.apply(this, arguments); 4 | }; 5 | } 6 | -------------------------------------------------------------------------------- /source/internal/_concat.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Private `concat` function to merge two array-like objects. 3 | * 4 | * @private 5 | * @param {Array|Arguments} [set1=[]] An array-like object. 6 | * @param {Array|Arguments} [set2=[]] An array-like object. 7 | * @return {Array} A new, merged array. 8 | * @example 9 | * 10 | * _concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3] 11 | */ 12 | export default function _concat(set1, set2) { 13 | set1 = set1 || []; 14 | set2 = set2 || []; 15 | var idx; 16 | var len1 = set1.length; 17 | var len2 = set2.length; 18 | var result = []; 19 | 20 | idx = 0; 21 | while (idx < len1) { 22 | result[result.length] = set1[idx]; 23 | idx += 1; 24 | } 25 | idx = 0; 26 | while (idx < len2) { 27 | result[result.length] = set2[idx]; 28 | idx += 1; 29 | } 30 | return result; 31 | } 32 | -------------------------------------------------------------------------------- /source/internal/_createPartialApplicator.js: -------------------------------------------------------------------------------- 1 | import _arity from './_arity'; 2 | import _curry2 from './_curry2'; 3 | 4 | 5 | export default function _createPartialApplicator(concat) { 6 | return _curry2(function(fn, args) { 7 | return _arity(Math.max(0, fn.length - args.length), function() { 8 | return fn.apply(this, concat(args, arguments)); 9 | }); 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /source/internal/_curry1.js: -------------------------------------------------------------------------------- 1 | import _isPlaceholder from './_isPlaceholder'; 2 | 3 | 4 | /** 5 | * Optimized internal one-arity curry function. 6 | * 7 | * @private 8 | * @category Function 9 | * @param {Function} fn The function to curry. 10 | * @return {Function} The curried function. 11 | */ 12 | export default function _curry1(fn) { 13 | return function f1(a) { 14 | if (arguments.length === 0 || _isPlaceholder(a)) { 15 | return f1; 16 | } else { 17 | return fn.apply(this, arguments); 18 | } 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /source/internal/_curry2.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './_curry1'; 2 | import _isPlaceholder from './_isPlaceholder'; 3 | 4 | 5 | /** 6 | * Optimized internal two-arity curry function. 7 | * 8 | * @private 9 | * @category Function 10 | * @param {Function} fn The function to curry. 11 | * @return {Function} The curried function. 12 | */ 13 | export default function _curry2(fn) { 14 | return function f2(a, b) { 15 | switch (arguments.length) { 16 | case 0: 17 | return f2; 18 | case 1: 19 | return _isPlaceholder(a) ? f2 20 | : _curry1(function(_b) { return fn(a, _b); }); 21 | default: 22 | return _isPlaceholder(a) && _isPlaceholder(b) ? f2 23 | : _isPlaceholder(a) ? _curry1(function(_a) { return fn(_a, b); }) 24 | : _isPlaceholder(b) ? _curry1(function(_b) { return fn(a, _b); }) 25 | : fn(a, b); 26 | } 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /source/internal/_dropLast.js: -------------------------------------------------------------------------------- 1 | import take from '../take'; 2 | 3 | export default function dropLast(n, xs) { 4 | return take(n < xs.length ? xs.length - n : 0, xs); 5 | } 6 | -------------------------------------------------------------------------------- /source/internal/_dropLastWhile.js: -------------------------------------------------------------------------------- 1 | import slice from '../slice'; 2 | 3 | export default function dropLastWhile(pred, xs) { 4 | var idx = xs.length - 1; 5 | while (idx >= 0 && pred(xs[idx])) { 6 | idx -= 1; 7 | } 8 | return slice(0, idx + 1, xs); 9 | } 10 | -------------------------------------------------------------------------------- /source/internal/_filter.js: -------------------------------------------------------------------------------- 1 | export default function _filter(fn, list) { 2 | var idx = 0; 3 | var len = list.length; 4 | var result = []; 5 | 6 | while (idx < len) { 7 | if (fn(list[idx])) { 8 | result[result.length] = list[idx]; 9 | } 10 | idx += 1; 11 | } 12 | return result; 13 | } 14 | -------------------------------------------------------------------------------- /source/internal/_forceReduced.js: -------------------------------------------------------------------------------- 1 | export default function _forceReduced(x) { 2 | return { 3 | '@@transducer/value': x, 4 | '@@transducer/reduced': true 5 | }; 6 | } 7 | -------------------------------------------------------------------------------- /source/internal/_functionName.js: -------------------------------------------------------------------------------- 1 | export default function _functionName(f) { 2 | // String(x => x) evaluates to "x => x", so the pattern may not match. 3 | var match = String(f).match(/^function (\w*)/); 4 | return match == null ? '' : match[1]; 5 | } 6 | -------------------------------------------------------------------------------- /source/internal/_functionsWith.js: -------------------------------------------------------------------------------- 1 | import _filter from './_filter'; 2 | 3 | 4 | /** 5 | * @private 6 | * @param {Function} fn The strategy for extracting function names from an object 7 | * @return {Function} A function that takes an object and returns an array of function names. 8 | */ 9 | export default function _functionsWith(fn) { 10 | return function(obj) { 11 | return _filter(function(key) { return typeof obj[key] === 'function'; }, fn(obj)); 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /source/internal/_has.js: -------------------------------------------------------------------------------- 1 | export default function _has(prop, obj) { 2 | return Object.prototype.hasOwnProperty.call(obj, prop); 3 | } 4 | -------------------------------------------------------------------------------- /source/internal/_identity.js: -------------------------------------------------------------------------------- 1 | export default function _identity(x) { return x; } 2 | -------------------------------------------------------------------------------- /source/internal/_includes.js: -------------------------------------------------------------------------------- 1 | import _indexOf from './_indexOf'; 2 | 3 | 4 | export default function _includes(a, list) { 5 | return _indexOf(list, a, 0) >= 0; 6 | } 7 | -------------------------------------------------------------------------------- /source/internal/_includesWith.js: -------------------------------------------------------------------------------- 1 | export default function _includesWith(pred, x, list) { 2 | var idx = 0; 3 | var len = list.length; 4 | 5 | while (idx < len) { 6 | if (pred(x, list[idx])) { 7 | return true; 8 | } 9 | idx += 1; 10 | } 11 | return false; 12 | } 13 | -------------------------------------------------------------------------------- /source/internal/_isArguments.js: -------------------------------------------------------------------------------- 1 | import _has from './_has'; 2 | 3 | 4 | var toString = Object.prototype.toString; 5 | var _isArguments = (function() { 6 | return toString.call(arguments) === '[object Arguments]' ? 7 | function _isArguments(x) { return toString.call(x) === '[object Arguments]'; } : 8 | function _isArguments(x) { return _has('callee', x); }; 9 | }()); 10 | 11 | export default _isArguments; 12 | -------------------------------------------------------------------------------- /source/internal/_isArray.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Tests whether or not an object is an array. 3 | * 4 | * @private 5 | * @param {*} val The object to test. 6 | * @return {Boolean} `true` if `val` is an array, `false` otherwise. 7 | * @example 8 | * 9 | * _isArray([]); //=> true 10 | * _isArray(null); //=> false 11 | * _isArray({}); //=> false 12 | */ 13 | export default Array.isArray || function _isArray(val) { 14 | return (val != null && 15 | val.length >= 0 && 16 | Object.prototype.toString.call(val) === '[object Array]'); 17 | }; 18 | -------------------------------------------------------------------------------- /source/internal/_isFunction.js: -------------------------------------------------------------------------------- 1 | export default function _isFunction(x) { 2 | return Object.prototype.toString.call(x) === '[object Function]'; 3 | } 4 | -------------------------------------------------------------------------------- /source/internal/_isInteger.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Determine if the passed argument is an integer. 3 | * 4 | * @private 5 | * @param {*} n 6 | * @category Type 7 | * @return {Boolean} 8 | */ 9 | export default Number.isInteger || function _isInteger(n) { 10 | return (n << 0) === n; 11 | }; 12 | -------------------------------------------------------------------------------- /source/internal/_isNumber.js: -------------------------------------------------------------------------------- 1 | export default function _isNumber(x) { 2 | return Object.prototype.toString.call(x) === '[object Number]'; 3 | } 4 | -------------------------------------------------------------------------------- /source/internal/_isObject.js: -------------------------------------------------------------------------------- 1 | export default function _isObject(x) { 2 | return Object.prototype.toString.call(x) === '[object Object]'; 3 | } 4 | -------------------------------------------------------------------------------- /source/internal/_isPlaceholder.js: -------------------------------------------------------------------------------- 1 | export default function _isPlaceholder(a) { 2 | return a != null && 3 | typeof a === 'object' && 4 | a['@@functional/placeholder'] === true; 5 | } 6 | -------------------------------------------------------------------------------- /source/internal/_isRegExp.js: -------------------------------------------------------------------------------- 1 | export default function _isRegExp(x) { 2 | return Object.prototype.toString.call(x) === '[object RegExp]'; 3 | } 4 | -------------------------------------------------------------------------------- /source/internal/_isString.js: -------------------------------------------------------------------------------- 1 | export default function _isString(x) { 2 | return Object.prototype.toString.call(x) === '[object String]'; 3 | } 4 | -------------------------------------------------------------------------------- /source/internal/_isTransformer.js: -------------------------------------------------------------------------------- 1 | export default function _isTransformer(obj) { 2 | return obj != null && typeof obj['@@transducer/step'] === 'function'; 3 | } 4 | -------------------------------------------------------------------------------- /source/internal/_makeFlat.js: -------------------------------------------------------------------------------- 1 | import _isArrayLike from './_isArrayLike'; 2 | 3 | 4 | /** 5 | * `_makeFlat` is a helper function that returns a one-level or fully recursive 6 | * function based on the flag passed in. 7 | * 8 | * @private 9 | */ 10 | export default function _makeFlat(recursive) { 11 | return function flatt(list) { 12 | var value, jlen, j; 13 | var result = []; 14 | var idx = 0; 15 | var ilen = list.length; 16 | 17 | while (idx < ilen) { 18 | if (_isArrayLike(list[idx])) { 19 | value = recursive ? flatt(list[idx]) : list[idx]; 20 | j = 0; 21 | jlen = value.length; 22 | while (j < jlen) { 23 | result[result.length] = value[j]; 24 | j += 1; 25 | } 26 | } else { 27 | result[result.length] = list[idx]; 28 | } 29 | idx += 1; 30 | } 31 | return result; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /source/internal/_map.js: -------------------------------------------------------------------------------- 1 | export default function _map(fn, functor) { 2 | var idx = 0; 3 | var len = functor.length; 4 | var result = Array(len); 5 | while (idx < len) { 6 | result[idx] = fn(functor[idx]); 7 | idx += 1; 8 | } 9 | return result; 10 | } 11 | -------------------------------------------------------------------------------- /source/internal/_objectAssign.js: -------------------------------------------------------------------------------- 1 | import _has from './_has'; 2 | 3 | // Based on https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign 4 | function _objectAssign(target) { 5 | if (target == null) { 6 | throw new TypeError('Cannot convert undefined or null to object'); 7 | } 8 | 9 | var output = Object(target); 10 | var idx = 1; 11 | var length = arguments.length; 12 | while (idx < length) { 13 | var source = arguments[idx]; 14 | if (source != null) { 15 | for (var nextKey in source) { 16 | if (_has(nextKey, source)) { 17 | output[nextKey] = source[nextKey]; 18 | } 19 | } 20 | } 21 | idx += 1; 22 | } 23 | return output; 24 | } 25 | 26 | export default typeof Object.assign === 'function' ? Object.assign : _objectAssign; 27 | -------------------------------------------------------------------------------- /source/internal/_objectIs.js: -------------------------------------------------------------------------------- 1 | // Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is 2 | function _objectIs(a, b) { 3 | // SameValue algorithm 4 | if (a === b) { // Steps 1-5, 7-10 5 | // Steps 6.b-6.e: +0 != -0 6 | return a !== 0 || 1 / a === 1 / b; 7 | } else { 8 | // Step 6.a: NaN == NaN 9 | return a !== a && b !== b; 10 | } 11 | } 12 | 13 | export default typeof Object.is === 'function' ? Object.is : _objectIs; 14 | -------------------------------------------------------------------------------- /source/internal/_of.js: -------------------------------------------------------------------------------- 1 | export default function _of(x) { return [x]; } 2 | -------------------------------------------------------------------------------- /source/internal/_pipe.js: -------------------------------------------------------------------------------- 1 | export default function _pipe(f, g) { 2 | return function() { 3 | return g.call(this, f.apply(this, arguments)); 4 | }; 5 | } 6 | -------------------------------------------------------------------------------- /source/internal/_pipeP.js: -------------------------------------------------------------------------------- 1 | export default function _pipeP(f, g) { 2 | return function() { 3 | var ctx = this; 4 | return f.apply(ctx, arguments).then(function(x) { 5 | return g.call(ctx, x); 6 | }); 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /source/internal/_quote.js: -------------------------------------------------------------------------------- 1 | export default function _quote(s) { 2 | var escaped = s 3 | .replace(/\\/g, '\\\\') 4 | .replace(/[\b]/g, '\\b') // \b matches word boundary; [\b] matches backspace 5 | .replace(/\f/g, '\\f') 6 | .replace(/\n/g, '\\n') 7 | .replace(/\r/g, '\\r') 8 | .replace(/\t/g, '\\t') 9 | .replace(/\v/g, '\\v') 10 | .replace(/\0/g, '\\0'); 11 | 12 | return '"' + escaped.replace(/"/g, '\\"') + '"'; 13 | } 14 | -------------------------------------------------------------------------------- /source/internal/_reduced.js: -------------------------------------------------------------------------------- 1 | export default function _reduced(x) { 2 | return x && x['@@transducer/reduced'] ? x : 3 | { 4 | '@@transducer/value': x, 5 | '@@transducer/reduced': true 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /source/internal/_toISOString.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Polyfill from . 3 | */ 4 | var pad = function pad(n) { return (n < 10 ? '0' : '') + n; }; 5 | 6 | var _toISOString = typeof Date.prototype.toISOString === 'function' ? 7 | function _toISOString(d) { 8 | return d.toISOString(); 9 | } : 10 | function _toISOString(d) { 11 | return ( 12 | d.getUTCFullYear() + '-' + 13 | pad(d.getUTCMonth() + 1) + '-' + 14 | pad(d.getUTCDate()) + 'T' + 15 | pad(d.getUTCHours()) + ':' + 16 | pad(d.getUTCMinutes()) + ':' + 17 | pad(d.getUTCSeconds()) + '.' + 18 | (d.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) + 'Z' 19 | ); 20 | }; 21 | 22 | export default _toISOString; 23 | -------------------------------------------------------------------------------- /source/internal/_xall.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _reduced from './_reduced'; 3 | import _xfBase from './_xfBase'; 4 | 5 | 6 | function XAll(f, xf) { 7 | this.xf = xf; 8 | this.f = f; 9 | this.all = true; 10 | } 11 | XAll.prototype['@@transducer/init'] = _xfBase.init; 12 | XAll.prototype['@@transducer/result'] = function(result) { 13 | if (this.all) { 14 | result = this.xf['@@transducer/step'](result, true); 15 | } 16 | return this.xf['@@transducer/result'](result); 17 | }; 18 | XAll.prototype['@@transducer/step'] = function(result, input) { 19 | if (!this.f(input)) { 20 | this.all = false; 21 | result = _reduced(this.xf['@@transducer/step'](result, false)); 22 | } 23 | return result; 24 | }; 25 | 26 | var _xall = _curry2(function _xall(f, xf) { return new XAll(f, xf); }); 27 | export default _xall; 28 | -------------------------------------------------------------------------------- /source/internal/_xany.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _reduced from './_reduced'; 3 | import _xfBase from './_xfBase'; 4 | 5 | 6 | function XAny(f, xf) { 7 | this.xf = xf; 8 | this.f = f; 9 | this.any = false; 10 | } 11 | XAny.prototype['@@transducer/init'] = _xfBase.init; 12 | XAny.prototype['@@transducer/result'] = function(result) { 13 | if (!this.any) { 14 | result = this.xf['@@transducer/step'](result, false); 15 | } 16 | return this.xf['@@transducer/result'](result); 17 | }; 18 | XAny.prototype['@@transducer/step'] = function(result, input) { 19 | if (this.f(input)) { 20 | this.any = true; 21 | result = _reduced(this.xf['@@transducer/step'](result, true)); 22 | } 23 | return result; 24 | }; 25 | 26 | var _xany = _curry2(function _xany(f, xf) { return new XAny(f, xf); }); 27 | export default _xany; 28 | -------------------------------------------------------------------------------- /source/internal/_xchain.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _flatCat from './_flatCat'; 3 | import map from '../map'; 4 | 5 | 6 | var _xchain = _curry2(function _xchain(f, xf) { 7 | return map(f, _flatCat(xf)); 8 | }); 9 | export default _xchain; 10 | -------------------------------------------------------------------------------- /source/internal/_xdrop.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _xfBase from './_xfBase'; 3 | 4 | 5 | function XDrop(n, xf) { 6 | this.xf = xf; 7 | this.n = n; 8 | } 9 | XDrop.prototype['@@transducer/init'] = _xfBase.init; 10 | XDrop.prototype['@@transducer/result'] = _xfBase.result; 11 | XDrop.prototype['@@transducer/step'] = function(result, input) { 12 | if (this.n > 0) { 13 | this.n -= 1; 14 | return result; 15 | } 16 | return this.xf['@@transducer/step'](result, input); 17 | }; 18 | 19 | var _xdrop = _curry2(function _xdrop(n, xf) { return new XDrop(n, xf); }); 20 | export default _xdrop; 21 | -------------------------------------------------------------------------------- /source/internal/_xdropLast.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _xfBase from './_xfBase'; 3 | 4 | 5 | function XDropLast(n, xf) { 6 | this.xf = xf; 7 | this.pos = 0; 8 | this.full = false; 9 | this.acc = new Array(n); 10 | } 11 | XDropLast.prototype['@@transducer/init'] = _xfBase.init; 12 | XDropLast.prototype['@@transducer/result'] = function(result) { 13 | this.acc = null; 14 | return this.xf['@@transducer/result'](result); 15 | }; 16 | XDropLast.prototype['@@transducer/step'] = function(result, input) { 17 | if (this.full) { 18 | result = this.xf['@@transducer/step'](result, this.acc[this.pos]); 19 | } 20 | this.store(input); 21 | return result; 22 | }; 23 | XDropLast.prototype.store = function(input) { 24 | this.acc[this.pos] = input; 25 | this.pos += 1; 26 | if (this.pos === this.acc.length) { 27 | this.pos = 0; 28 | this.full = true; 29 | } 30 | }; 31 | 32 | var _xdropLast = _curry2(function _xdropLast(n, xf) { return new XDropLast(n, xf); }); 33 | export default _xdropLast; 34 | -------------------------------------------------------------------------------- /source/internal/_xdropRepeatsWith.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _xfBase from './_xfBase'; 3 | 4 | 5 | function XDropRepeatsWith(pred, xf) { 6 | this.xf = xf; 7 | this.pred = pred; 8 | this.lastValue = undefined; 9 | this.seenFirstValue = false; 10 | } 11 | 12 | XDropRepeatsWith.prototype['@@transducer/init'] = _xfBase.init; 13 | XDropRepeatsWith.prototype['@@transducer/result'] = _xfBase.result; 14 | XDropRepeatsWith.prototype['@@transducer/step'] = function(result, input) { 15 | var sameAsLast = false; 16 | if (!this.seenFirstValue) { 17 | this.seenFirstValue = true; 18 | } else if (this.pred(this.lastValue, input)) { 19 | sameAsLast = true; 20 | } 21 | this.lastValue = input; 22 | return sameAsLast ? result : this.xf['@@transducer/step'](result, input); 23 | }; 24 | 25 | var _xdropRepeatsWith = _curry2(function _xdropRepeatsWith(pred, xf) { return new XDropRepeatsWith(pred, xf); }); 26 | export default _xdropRepeatsWith; 27 | -------------------------------------------------------------------------------- /source/internal/_xdropWhile.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _xfBase from './_xfBase'; 3 | 4 | 5 | function XDropWhile(f, xf) { 6 | this.xf = xf; 7 | this.f = f; 8 | } 9 | XDropWhile.prototype['@@transducer/init'] = _xfBase.init; 10 | XDropWhile.prototype['@@transducer/result'] = _xfBase.result; 11 | XDropWhile.prototype['@@transducer/step'] = function(result, input) { 12 | if (this.f) { 13 | if (this.f(input)) { 14 | return result; 15 | } 16 | this.f = null; 17 | } 18 | return this.xf['@@transducer/step'](result, input); 19 | }; 20 | 21 | var _xdropWhile = _curry2(function _xdropWhile(f, xf) { return new XDropWhile(f, xf); }); 22 | export default _xdropWhile; 23 | -------------------------------------------------------------------------------- /source/internal/_xfBase.js: -------------------------------------------------------------------------------- 1 | export default { 2 | init: function() { 3 | return this.xf['@@transducer/init'](); 4 | }, 5 | result: function(result) { 6 | return this.xf['@@transducer/result'](result); 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /source/internal/_xfilter.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _xfBase from './_xfBase'; 3 | 4 | 5 | function XFilter(f, xf) { 6 | this.xf = xf; 7 | this.f = f; 8 | } 9 | XFilter.prototype['@@transducer/init'] = _xfBase.init; 10 | XFilter.prototype['@@transducer/result'] = _xfBase.result; 11 | XFilter.prototype['@@transducer/step'] = function(result, input) { 12 | return this.f(input) ? this.xf['@@transducer/step'](result, input) : result; 13 | }; 14 | 15 | var _xfilter = _curry2(function _xfilter(f, xf) { return new XFilter(f, xf); }); 16 | export default _xfilter; 17 | -------------------------------------------------------------------------------- /source/internal/_xfind.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _reduced from './_reduced'; 3 | import _xfBase from './_xfBase'; 4 | 5 | 6 | function XFind(f, xf) { 7 | this.xf = xf; 8 | this.f = f; 9 | this.found = false; 10 | } 11 | XFind.prototype['@@transducer/init'] = _xfBase.init; 12 | XFind.prototype['@@transducer/result'] = function(result) { 13 | if (!this.found) { 14 | result = this.xf['@@transducer/step'](result, void 0); 15 | } 16 | return this.xf['@@transducer/result'](result); 17 | }; 18 | XFind.prototype['@@transducer/step'] = function(result, input) { 19 | if (this.f(input)) { 20 | this.found = true; 21 | result = _reduced(this.xf['@@transducer/step'](result, input)); 22 | } 23 | return result; 24 | }; 25 | 26 | var _xfind = _curry2(function _xfind(f, xf) { return new XFind(f, xf); }); 27 | export default _xfind; 28 | -------------------------------------------------------------------------------- /source/internal/_xfindIndex.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _reduced from './_reduced'; 3 | import _xfBase from './_xfBase'; 4 | 5 | 6 | function XFindIndex(f, xf) { 7 | this.xf = xf; 8 | this.f = f; 9 | this.idx = -1; 10 | this.found = false; 11 | } 12 | XFindIndex.prototype['@@transducer/init'] = _xfBase.init; 13 | XFindIndex.prototype['@@transducer/result'] = function(result) { 14 | if (!this.found) { 15 | result = this.xf['@@transducer/step'](result, -1); 16 | } 17 | return this.xf['@@transducer/result'](result); 18 | }; 19 | XFindIndex.prototype['@@transducer/step'] = function(result, input) { 20 | this.idx += 1; 21 | if (this.f(input)) { 22 | this.found = true; 23 | result = _reduced(this.xf['@@transducer/step'](result, this.idx)); 24 | } 25 | return result; 26 | }; 27 | 28 | var _xfindIndex = _curry2(function _xfindIndex(f, xf) { return new XFindIndex(f, xf); }); 29 | export default _xfindIndex; 30 | -------------------------------------------------------------------------------- /source/internal/_xfindLast.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _xfBase from './_xfBase'; 3 | 4 | 5 | function XFindLast(f, xf) { 6 | this.xf = xf; 7 | this.f = f; 8 | } 9 | XFindLast.prototype['@@transducer/init'] = _xfBase.init; 10 | XFindLast.prototype['@@transducer/result'] = function(result) { 11 | return this.xf['@@transducer/result'](this.xf['@@transducer/step'](result, this.last)); 12 | }; 13 | XFindLast.prototype['@@transducer/step'] = function(result, input) { 14 | if (this.f(input)) { 15 | this.last = input; 16 | } 17 | return result; 18 | }; 19 | 20 | var _xfindLast = _curry2(function _xfindLast(f, xf) { return new XFindLast(f, xf); }); 21 | export default _xfindLast; 22 | -------------------------------------------------------------------------------- /source/internal/_xfindLastIndex.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _xfBase from './_xfBase'; 3 | 4 | 5 | function XFindLastIndex(f, xf) { 6 | this.xf = xf; 7 | this.f = f; 8 | this.idx = -1; 9 | this.lastIdx = -1; 10 | } 11 | XFindLastIndex.prototype['@@transducer/init'] = _xfBase.init; 12 | XFindLastIndex.prototype['@@transducer/result'] = function(result) { 13 | return this.xf['@@transducer/result'](this.xf['@@transducer/step'](result, this.lastIdx)); 14 | }; 15 | XFindLastIndex.prototype['@@transducer/step'] = function(result, input) { 16 | this.idx += 1; 17 | if (this.f(input)) { 18 | this.lastIdx = this.idx; 19 | } 20 | return result; 21 | }; 22 | 23 | var _xfindLastIndex = _curry2(function _xfindLastIndex(f, xf) { return new XFindLastIndex(f, xf); }); 24 | export default _xfindLastIndex; 25 | -------------------------------------------------------------------------------- /source/internal/_xmap.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _xfBase from './_xfBase'; 3 | 4 | 5 | function XMap(f, xf) { 6 | this.xf = xf; 7 | this.f = f; 8 | } 9 | XMap.prototype['@@transducer/init'] = _xfBase.init; 10 | XMap.prototype['@@transducer/result'] = _xfBase.result; 11 | XMap.prototype['@@transducer/step'] = function(result, input) { 12 | return this.xf['@@transducer/step'](result, this.f(input)); 13 | }; 14 | 15 | var _xmap = _curry2(function _xmap(f, xf) { return new XMap(f, xf); }); 16 | export default _xmap; 17 | -------------------------------------------------------------------------------- /source/internal/_xtake.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _reduced from './_reduced'; 3 | import _xfBase from './_xfBase'; 4 | 5 | 6 | function XTake(n, xf) { 7 | this.xf = xf; 8 | this.n = n; 9 | this.i = 0; 10 | } 11 | XTake.prototype['@@transducer/init'] = _xfBase.init; 12 | XTake.prototype['@@transducer/result'] = _xfBase.result; 13 | XTake.prototype['@@transducer/step'] = function(result, input) { 14 | this.i += 1; 15 | var ret = this.n === 0 ? result : this.xf['@@transducer/step'](result, input); 16 | return this.n >= 0 && this.i >= this.n ? _reduced(ret) : ret; 17 | }; 18 | 19 | var _xtake = _curry2(function _xtake(n, xf) { return new XTake(n, xf); }); 20 | export default _xtake; 21 | -------------------------------------------------------------------------------- /source/internal/_xtakeWhile.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _reduced from './_reduced'; 3 | import _xfBase from './_xfBase'; 4 | 5 | 6 | function XTakeWhile(f, xf) { 7 | this.xf = xf; 8 | this.f = f; 9 | } 10 | XTakeWhile.prototype['@@transducer/init'] = _xfBase.init; 11 | XTakeWhile.prototype['@@transducer/result'] = _xfBase.result; 12 | XTakeWhile.prototype['@@transducer/step'] = function(result, input) { 13 | return this.f(input) ? this.xf['@@transducer/step'](result, input) : _reduced(result); 14 | }; 15 | 16 | var _xtakeWhile = _curry2(function _xtakeWhile(f, xf) { return new XTakeWhile(f, xf); }); 17 | export default _xtakeWhile; 18 | -------------------------------------------------------------------------------- /source/internal/_xtap.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './_curry2'; 2 | import _xfBase from './_xfBase'; 3 | 4 | 5 | function XTap(f, xf) { 6 | this.xf = xf; 7 | this.f = f; 8 | } 9 | XTap.prototype['@@transducer/init'] = _xfBase.init; 10 | XTap.prototype['@@transducer/result'] = _xfBase.result; 11 | XTap.prototype['@@transducer/step'] = function(result, input) { 12 | this.f(input); 13 | return this.xf['@@transducer/step'](result, input); 14 | }; 15 | 16 | var _xtap = _curry2(function _xtap(f, xf) { return new XTap(f, xf); }); 17 | export default _xtap; 18 | -------------------------------------------------------------------------------- /source/internal/_xwrap.js: -------------------------------------------------------------------------------- 1 | function XWrap(fn) { 2 | this.f = fn; 3 | } 4 | XWrap.prototype['@@transducer/init'] = function() { 5 | throw new Error('init not implemented on XWrap'); 6 | }; 7 | XWrap.prototype['@@transducer/result'] = function(acc) { return acc; }; 8 | XWrap.prototype['@@transducer/step'] = function(acc, x) { 9 | return this.f(acc, x); 10 | }; 11 | 12 | export default function _xwrap(fn) { return new XWrap(fn); } 13 | -------------------------------------------------------------------------------- /source/is.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * See if an object (`val`) is an instance of the supplied constructor. This 6 | * function will check up the inheritance chain, if any. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.3.0 11 | * @category Type 12 | * @sig (* -> {*}) -> a -> Boolean 13 | * @param {Object} ctor A constructor 14 | * @param {*} val The value to test 15 | * @return {Boolean} 16 | * @example 17 | * 18 | * R.is(Object, {}); //=> true 19 | * R.is(Number, 1); //=> true 20 | * R.is(Object, 1); //=> false 21 | * R.is(String, 's'); //=> true 22 | * R.is(String, new String('')); //=> true 23 | * R.is(Object, new String('')); //=> true 24 | * R.is(Object, 's'); //=> false 25 | * R.is(Number, {}); //=> false 26 | */ 27 | var is = _curry2(function is(Ctor, val) { 28 | return val != null && val.constructor === Ctor || val instanceof Ctor; 29 | }); 30 | export default is; 31 | -------------------------------------------------------------------------------- /source/isEmpty.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import empty from './empty'; 3 | import equals from './equals'; 4 | 5 | 6 | /** 7 | * Returns `true` if the given value is its type's empty value; `false` 8 | * otherwise. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.1.0 13 | * @category Logic 14 | * @sig a -> Boolean 15 | * @param {*} x 16 | * @return {Boolean} 17 | * @see R.empty 18 | * @example 19 | * 20 | * R.isEmpty([1, 2, 3]); //=> false 21 | * R.isEmpty([]); //=> true 22 | * R.isEmpty(''); //=> true 23 | * R.isEmpty(null); //=> false 24 | * R.isEmpty({}); //=> true 25 | * R.isEmpty({length: 0}); //=> false 26 | */ 27 | var isEmpty = _curry1(function isEmpty(x) { 28 | return x != null && equals(x, empty(x)); 29 | }); 30 | export default isEmpty; 31 | -------------------------------------------------------------------------------- /source/isNil.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | 3 | 4 | /** 5 | * Checks if the input value is `null` or `undefined`. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.9.0 10 | * @category Type 11 | * @sig * -> Boolean 12 | * @param {*} x The value to test. 13 | * @return {Boolean} `true` if `x` is `undefined` or `null`, otherwise `false`. 14 | * @example 15 | * 16 | * R.isNil(null); //=> true 17 | * R.isNil(undefined); //=> true 18 | * R.isNil(0); //=> false 19 | * R.isNil([]); //=> false 20 | */ 21 | var isNil = _curry1(function isNil(x) { return x == null; }); 22 | export default isNil; 23 | -------------------------------------------------------------------------------- /source/join.js: -------------------------------------------------------------------------------- 1 | import invoker from './invoker'; 2 | 3 | 4 | /** 5 | * Returns a string made by inserting the `separator` between each element and 6 | * concatenating all the elements into a single string. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.1.0 11 | * @category List 12 | * @sig String -> [a] -> String 13 | * @param {Number|String} separator The string used to separate the elements. 14 | * @param {Array} xs The elements to join into a string. 15 | * @return {String} str The string made by concatenating `xs` with `separator`. 16 | * @see R.split 17 | * @example 18 | * 19 | * const spacer = R.join(' '); 20 | * spacer(['a', 2, 3.4]); //=> 'a 2 3.4' 21 | * R.join('|', [1, 2, 3]); //=> '1|2|3' 22 | */ 23 | var join = invoker(1, 'join'); 24 | export default join; 25 | -------------------------------------------------------------------------------- /source/juxt.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import converge from './converge'; 3 | 4 | 5 | /** 6 | * juxt applies a list of functions to a list of values. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.19.0 11 | * @category Function 12 | * @sig [(a, b, ..., m) -> n] -> ((a, b, ..., m) -> [n]) 13 | * @param {Array} fns An array of functions 14 | * @return {Function} A function that returns a list of values after applying each of the original `fns` to its parameters. 15 | * @see R.applySpec 16 | * @example 17 | * 18 | * const getRange = R.juxt([Math.min, Math.max]); 19 | * getRange(3, 4, 9, -3); //=> [-3, 9] 20 | * @symb R.juxt([f, g, h])(a, b) = [f(a, b), g(a, b), h(a, b)] 21 | */ 22 | var juxt = _curry1(function juxt(fns) { 23 | return converge(function() { return Array.prototype.slice.call(arguments, 0); }, fns); 24 | }); 25 | export default juxt; 26 | -------------------------------------------------------------------------------- /source/keysIn.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | 3 | 4 | /** 5 | * Returns a list containing the names of all the properties of the supplied 6 | * object, including prototype properties. 7 | * Note that the order of the output array is not guaranteed to be consistent 8 | * across different JS platforms. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.2.0 13 | * @category Object 14 | * @sig {k: v} -> [k] 15 | * @param {Object} obj The object to extract properties from 16 | * @return {Array} An array of the object's own and prototype properties. 17 | * @see R.keys, R.valuesIn 18 | * @example 19 | * 20 | * const F = function() { this.x = 'X'; }; 21 | * F.prototype.y = 'Y'; 22 | * const f = new F(); 23 | * R.keysIn(f); //=> ['x', 'y'] 24 | */ 25 | var keysIn = _curry1(function keysIn(obj) { 26 | var prop; 27 | var ks = []; 28 | for (prop in obj) { 29 | ks[ks.length] = prop; 30 | } 31 | return ks; 32 | }); 33 | export default keysIn; 34 | -------------------------------------------------------------------------------- /source/last.js: -------------------------------------------------------------------------------- 1 | import nth from './nth'; 2 | 3 | 4 | /** 5 | * Returns the last element of the given list or string. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.1.4 10 | * @category List 11 | * @sig [a] -> a | Undefined 12 | * @sig String -> String 13 | * @param {*} list 14 | * @return {*} 15 | * @see R.init, R.head, R.tail 16 | * @example 17 | * 18 | * R.last(['fi', 'fo', 'fum']); //=> 'fum' 19 | * R.last([]); //=> undefined 20 | * 21 | * R.last('abc'); //=> 'c' 22 | * R.last(''); //=> '' 23 | */ 24 | var last = nth(-1); 25 | export default last; 26 | -------------------------------------------------------------------------------- /source/length.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import _isNumber from './internal/_isNumber'; 3 | 4 | 5 | /** 6 | * Returns the number of elements in the array by returning `list.length`. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.3.0 11 | * @category List 12 | * @sig [a] -> Number 13 | * @param {Array} list The array to inspect. 14 | * @return {Number} The length of the array. 15 | * @example 16 | * 17 | * R.length([]); //=> 0 18 | * R.length([1, 2, 3]); //=> 3 19 | */ 20 | var length = _curry1(function length(list) { 21 | return list != null && _isNumber(list.length) ? list.length : NaN; 22 | }); 23 | export default length; 24 | -------------------------------------------------------------------------------- /source/lensIndex.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import lens from './lens'; 3 | import nth from './nth'; 4 | import update from './update'; 5 | 6 | 7 | /** 8 | * Returns a lens whose focus is the specified index. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.14.0 13 | * @category Object 14 | * @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s 15 | * @sig Number -> Lens s a 16 | * @param {Number} n 17 | * @return {Lens} 18 | * @see R.view, R.set, R.over 19 | * @example 20 | * 21 | * const headLens = R.lensIndex(0); 22 | * 23 | * R.view(headLens, ['a', 'b', 'c']); //=> 'a' 24 | * R.set(headLens, 'x', ['a', 'b', 'c']); //=> ['x', 'b', 'c'] 25 | * R.over(headLens, R.toUpper, ['a', 'b', 'c']); //=> ['A', 'b', 'c'] 26 | */ 27 | var lensIndex = _curry1(function lensIndex(n) { 28 | return lens(nth(n), update(n)); 29 | }); 30 | export default lensIndex; 31 | -------------------------------------------------------------------------------- /source/lensProp.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import assoc from './assoc'; 3 | import lens from './lens'; 4 | import prop from './prop'; 5 | 6 | 7 | /** 8 | * Returns a lens whose focus is the specified property. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.14.0 13 | * @category Object 14 | * @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s 15 | * @sig String -> Lens s a 16 | * @param {String} k 17 | * @return {Lens} 18 | * @see R.view, R.set, R.over 19 | * @example 20 | * 21 | * const xLens = R.lensProp('x'); 22 | * 23 | * R.view(xLens, {x: 1, y: 2}); //=> 1 24 | * R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2} 25 | * R.over(xLens, R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2} 26 | */ 27 | var lensProp = _curry1(function lensProp(k) { 28 | return lens(prop(k), assoc(k)); 29 | }); 30 | export default lensProp; 31 | -------------------------------------------------------------------------------- /source/lift.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import liftN from './liftN'; 3 | 4 | 5 | /** 6 | * "lifts" a function of arity > 1 so that it may "map over" a list, Function or other 7 | * object that satisfies the [FantasyLand Apply spec](https://github.com/fantasyland/fantasy-land#apply). 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.7.0 12 | * @category Function 13 | * @sig (*... -> *) -> ([*]... -> [*]) 14 | * @param {Function} fn The function to lift into higher context 15 | * @return {Function} The lifted function. 16 | * @see R.liftN 17 | * @example 18 | * 19 | * const madd3 = R.lift((a, b, c) => a + b + c); 20 | * 21 | * madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7] 22 | * 23 | * const madd5 = R.lift((a, b, c, d, e) => a + b + c + d + e); 24 | * 25 | * madd5([1,2], [3], [4, 5], [6], [7, 8]); //=> [21, 22, 22, 23, 22, 23, 23, 24] 26 | */ 27 | var lift = _curry1(function lift(fn) { 28 | return liftN(fn.length, fn); 29 | }); 30 | export default lift; 31 | -------------------------------------------------------------------------------- /source/lt.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Returns `true` if the first argument is less than the second; `false` 6 | * otherwise. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.1.0 11 | * @category Relation 12 | * @sig Ord a => a -> a -> Boolean 13 | * @param {*} a 14 | * @param {*} b 15 | * @return {Boolean} 16 | * @see R.gt 17 | * @example 18 | * 19 | * R.lt(2, 1); //=> false 20 | * R.lt(2, 2); //=> false 21 | * R.lt(2, 3); //=> true 22 | * R.lt('a', 'z'); //=> true 23 | * R.lt('z', 'a'); //=> false 24 | */ 25 | var lt = _curry2(function lt(a, b) { return a < b; }); 26 | export default lt; 27 | -------------------------------------------------------------------------------- /source/lte.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Returns `true` if the first argument is less than or equal to the second; 6 | * `false` otherwise. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.1.0 11 | * @category Relation 12 | * @sig Ord a => a -> a -> Boolean 13 | * @param {Number} a 14 | * @param {Number} b 15 | * @return {Boolean} 16 | * @see R.gte 17 | * @example 18 | * 19 | * R.lte(2, 1); //=> false 20 | * R.lte(2, 2); //=> true 21 | * R.lte(2, 3); //=> true 22 | * R.lte('a', 'z'); //=> true 23 | * R.lte('z', 'a'); //=> false 24 | */ 25 | var lte = _curry2(function lte(a, b) { return a <= b; }); 26 | export default lte; 27 | -------------------------------------------------------------------------------- /source/max.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Returns the larger of its two arguments. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.1.0 10 | * @category Relation 11 | * @sig Ord a => a -> a -> a 12 | * @param {*} a 13 | * @param {*} b 14 | * @return {*} 15 | * @see R.maxBy, R.min 16 | * @example 17 | * 18 | * R.max(789, 123); //=> 789 19 | * R.max('a', 'b'); //=> 'b' 20 | */ 21 | var max = _curry2(function max(a, b) { return b > a ? b : a; }); 22 | export default max; 23 | -------------------------------------------------------------------------------- /source/maxBy.js: -------------------------------------------------------------------------------- 1 | import _curry3 from './internal/_curry3'; 2 | 3 | 4 | /** 5 | * Takes a function and two values, and returns whichever value produces the 6 | * larger result when passed to the provided function. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.8.0 11 | * @category Relation 12 | * @sig Ord b => (a -> b) -> a -> a -> a 13 | * @param {Function} f 14 | * @param {*} a 15 | * @param {*} b 16 | * @return {*} 17 | * @see R.max, R.minBy 18 | * @example 19 | * 20 | * // square :: Number -> Number 21 | * const square = n => n * n; 22 | * 23 | * R.maxBy(square, -3, 2); //=> -3 24 | * 25 | * R.reduce(R.maxBy(square), 0, [3, -5, 4, 1, -2]); //=> -5 26 | * R.reduce(R.maxBy(square), 0, []); //=> 0 27 | */ 28 | var maxBy = _curry3(function maxBy(f, a, b) { 29 | return f(b) > f(a) ? b : a; 30 | }); 31 | export default maxBy; 32 | -------------------------------------------------------------------------------- /source/mean.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import sum from './sum'; 3 | 4 | 5 | /** 6 | * Returns the mean of the given list of numbers. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.14.0 11 | * @category Math 12 | * @sig [Number] -> Number 13 | * @param {Array} list 14 | * @return {Number} 15 | * @see R.median 16 | * @example 17 | * 18 | * R.mean([2, 7, 9]); //=> 6 19 | * R.mean([]); //=> NaN 20 | */ 21 | var mean = _curry1(function mean(list) { 22 | return sum(list) / list.length; 23 | }); 24 | export default mean; 25 | -------------------------------------------------------------------------------- /source/median.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import mean from './mean'; 3 | 4 | 5 | /** 6 | * Returns the median of the given list of numbers. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.14.0 11 | * @category Math 12 | * @sig [Number] -> Number 13 | * @param {Array} list 14 | * @return {Number} 15 | * @see R.mean 16 | * @example 17 | * 18 | * R.median([2, 9, 7]); //=> 7 19 | * R.median([7, 2, 10, 9]); //=> 8 20 | * R.median([]); //=> NaN 21 | */ 22 | var median = _curry1(function median(list) { 23 | var len = list.length; 24 | if (len === 0) { 25 | return NaN; 26 | } 27 | var width = 2 - len % 2; 28 | var idx = (len - width) / 2; 29 | return mean(Array.prototype.slice.call(list, 0).sort(function(a, b) { 30 | return a < b ? -1 : a > b ? 1 : 0; 31 | }).slice(idx, idx + width)); 32 | }); 33 | export default median; 34 | -------------------------------------------------------------------------------- /source/mergeAll.js: -------------------------------------------------------------------------------- 1 | import _objectAssign from './internal/_objectAssign'; 2 | import _curry1 from './internal/_curry1'; 3 | 4 | 5 | /** 6 | * Merges a list of objects together into one object. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.10.0 11 | * @category List 12 | * @sig [{k: v}] -> {k: v} 13 | * @param {Array} list An array of objects 14 | * @return {Object} A merged object. 15 | * @see R.reduce 16 | * @example 17 | * 18 | * R.mergeAll([{foo:1},{bar:2},{baz:3}]); //=> {foo:1,bar:2,baz:3} 19 | * R.mergeAll([{foo:1},{foo:2},{bar:2}]); //=> {foo:2,bar:2} 20 | * @symb R.mergeAll([{ x: 1 }, { y: 2 }, { z: 3 }]) = { x: 1, y: 2, z: 3 } 21 | */ 22 | var mergeAll = _curry1(function mergeAll(list) { 23 | return _objectAssign.apply(null, [{}].concat(list)); 24 | }); 25 | export default mergeAll; 26 | -------------------------------------------------------------------------------- /source/min.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Returns the smaller of its two arguments. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.1.0 10 | * @category Relation 11 | * @sig Ord a => a -> a -> a 12 | * @param {*} a 13 | * @param {*} b 14 | * @return {*} 15 | * @see R.minBy, R.max 16 | * @example 17 | * 18 | * R.min(789, 123); //=> 123 19 | * R.min('a', 'b'); //=> 'a' 20 | */ 21 | var min = _curry2(function min(a, b) { return b < a ? b : a; }); 22 | export default min; 23 | -------------------------------------------------------------------------------- /source/minBy.js: -------------------------------------------------------------------------------- 1 | import _curry3 from './internal/_curry3'; 2 | 3 | 4 | /** 5 | * Takes a function and two values, and returns whichever value produces the 6 | * smaller result when passed to the provided function. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.8.0 11 | * @category Relation 12 | * @sig Ord b => (a -> b) -> a -> a -> a 13 | * @param {Function} f 14 | * @param {*} a 15 | * @param {*} b 16 | * @return {*} 17 | * @see R.min, R.maxBy 18 | * @example 19 | * 20 | * // square :: Number -> Number 21 | * const square = n => n * n; 22 | * 23 | * R.minBy(square, -3, 2); //=> 2 24 | * 25 | * R.reduce(R.minBy(square), Infinity, [3, -5, 4, 1, -2]); //=> 1 26 | * R.reduce(R.minBy(square), Infinity, []); //=> Infinity 27 | */ 28 | var minBy = _curry3(function minBy(f, a, b) { 29 | return f(b) < f(a) ? b : a; 30 | }); 31 | export default minBy; 32 | -------------------------------------------------------------------------------- /source/modulo.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Divides the first parameter by the second and returns the remainder. Note 6 | * that this function preserves the JavaScript-style behavior for modulo. For 7 | * mathematical modulo see [`mathMod`](#mathMod). 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.1.1 12 | * @category Math 13 | * @sig Number -> Number -> Number 14 | * @param {Number} a The value to the divide. 15 | * @param {Number} b The pseudo-modulus 16 | * @return {Number} The result of `b % a`. 17 | * @see R.mathMod 18 | * @example 19 | * 20 | * R.modulo(17, 3); //=> 2 21 | * // JS behavior: 22 | * R.modulo(-17, 3); //=> -2 23 | * R.modulo(17, -3); //=> 2 24 | * 25 | * const isOdd = R.modulo(R.__, 2); 26 | * isOdd(42); //=> 0 27 | * isOdd(21); //=> 1 28 | */ 29 | var modulo = _curry2(function modulo(a, b) { return a % b; }); 30 | export default modulo; 31 | -------------------------------------------------------------------------------- /source/multiply.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Multiplies two numbers. Equivalent to `a * b` but curried. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.1.0 10 | * @category Math 11 | * @sig Number -> Number -> Number 12 | * @param {Number} a The first value. 13 | * @param {Number} b The second value. 14 | * @return {Number} The result of `a * b`. 15 | * @see R.divide 16 | * @example 17 | * 18 | * const double = R.multiply(2); 19 | * const triple = R.multiply(3); 20 | * double(3); //=> 6 21 | * triple(4); //=> 12 22 | * R.multiply(2, 5); //=> 10 23 | */ 24 | var multiply = _curry2(function multiply(a, b) { return a * b; }); 25 | export default multiply; 26 | -------------------------------------------------------------------------------- /source/negate.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | 3 | 4 | /** 5 | * Negates its argument. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.9.0 10 | * @category Math 11 | * @sig Number -> Number 12 | * @param {Number} n 13 | * @return {Number} 14 | * @example 15 | * 16 | * R.negate(42); //=> -42 17 | */ 18 | var negate = _curry1(function negate(n) { return -n; }); 19 | export default negate; 20 | -------------------------------------------------------------------------------- /source/not.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | 3 | 4 | /** 5 | * A function that returns the `!` of its argument. It will return `true` when 6 | * passed false-y value, and `false` when passed a truth-y one. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.1.0 11 | * @category Logic 12 | * @sig * -> Boolean 13 | * @param {*} a any value 14 | * @return {Boolean} the logical inverse of passed argument. 15 | * @see R.complement 16 | * @example 17 | * 18 | * R.not(true); //=> false 19 | * R.not(false); //=> true 20 | * R.not(0); //=> true 21 | * R.not(1); //=> false 22 | */ 23 | var not = _curry1(function not(a) { 24 | return !a; 25 | }); 26 | export default not; 27 | -------------------------------------------------------------------------------- /source/nthArg.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import curryN from './curryN'; 3 | import nth from './nth'; 4 | 5 | 6 | /** 7 | * Returns a function which returns its nth argument. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.9.0 12 | * @category Function 13 | * @sig Number -> *... -> * 14 | * @param {Number} n 15 | * @return {Function} 16 | * @example 17 | * 18 | * R.nthArg(1)('a', 'b', 'c'); //=> 'b' 19 | * R.nthArg(-1)('a', 'b', 'c'); //=> 'c' 20 | * @symb R.nthArg(-1)(a, b, c) = c 21 | * @symb R.nthArg(0)(a, b, c) = a 22 | * @symb R.nthArg(1)(a, b, c) = b 23 | */ 24 | var nthArg = _curry1(function nthArg(n) { 25 | var arity = n < 0 ? 1 : n + 1; 26 | return curryN(arity, function() { 27 | return nth(n, arguments); 28 | }); 29 | }); 30 | export default nthArg; 31 | -------------------------------------------------------------------------------- /source/objOf.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Creates an object containing a single key:value pair. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.18.0 10 | * @category Object 11 | * @sig String -> a -> {String:a} 12 | * @param {String} key 13 | * @param {*} val 14 | * @return {Object} 15 | * @see R.pair 16 | * @example 17 | * 18 | * const matchPhrases = R.compose( 19 | * R.objOf('must'), 20 | * R.map(R.objOf('match_phrase')) 21 | * ); 22 | * matchPhrases(['foo', 'bar', 'baz']); //=> {must: [{match_phrase: 'foo'}, {match_phrase: 'bar'}, {match_phrase: 'baz'}]} 23 | */ 24 | var objOf = _curry2(function objOf(key, val) { 25 | var obj = {}; 26 | obj[key] = val; 27 | return obj; 28 | }); 29 | export default objOf; 30 | -------------------------------------------------------------------------------- /source/of.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import _of from './internal/_of'; 3 | 4 | 5 | /** 6 | * Returns a singleton array containing the value provided. 7 | * 8 | * Note this `of` is different from the ES6 `of`; See 9 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of 10 | * 11 | * @func 12 | * @memberOf R 13 | * @since v0.3.0 14 | * @category Function 15 | * @sig a -> [a] 16 | * @param {*} x any value 17 | * @return {Array} An array wrapping `x`. 18 | * @example 19 | * 20 | * R.of(null); //=> [null] 21 | * R.of([42]); //=> [[42]] 22 | */ 23 | var of = _curry1(_of); 24 | export default of; 25 | -------------------------------------------------------------------------------- /source/or.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Returns `true` if one or both of its arguments are `true`. Returns `false` 6 | * if both arguments are `false`. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.1.0 11 | * @category Logic 12 | * @sig a -> b -> a | b 13 | * @param {Any} a 14 | * @param {Any} b 15 | * @return {Any} the first argument if truthy, otherwise the second argument. 16 | * @see R.either 17 | * @example 18 | * 19 | * R.or(true, true); //=> true 20 | * R.or(true, false); //=> true 21 | * R.or(false, true); //=> true 22 | * R.or(false, false); //=> false 23 | */ 24 | var or = _curry2(function or(a, b) { 25 | return a || b; 26 | }); 27 | export default or; 28 | -------------------------------------------------------------------------------- /source/pair.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Takes two arguments, `fst` and `snd`, and returns `[fst, snd]`. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.18.0 10 | * @category List 11 | * @sig a -> b -> (a,b) 12 | * @param {*} fst 13 | * @param {*} snd 14 | * @return {Array} 15 | * @see R.objOf, R.of 16 | * @example 17 | * 18 | * R.pair('foo', 'bar'); //=> ['foo', 'bar'] 19 | */ 20 | var pair = _curry2(function pair(fst, snd) { return [fst, snd]; }); 21 | export default pair; 22 | -------------------------------------------------------------------------------- /source/path.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Retrieve the value at a given path. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.2.0 10 | * @category Object 11 | * @typedefn Idx = String | Int 12 | * @sig [Idx] -> {a} -> a | Undefined 13 | * @param {Array} path The path to use. 14 | * @param {Object} obj The object to retrieve the nested property from. 15 | * @return {*} The data at `path`. 16 | * @see R.prop 17 | * @example 18 | * 19 | * R.path(['a', 'b'], {a: {b: 2}}); //=> 2 20 | * R.path(['a', 'b'], {c: {b: 2}}); //=> undefined 21 | */ 22 | var path = _curry2(function path(paths, obj) { 23 | var val = obj; 24 | var idx = 0; 25 | while (idx < paths.length) { 26 | if (val == null) { 27 | return; 28 | } 29 | val = val[paths[idx]]; 30 | idx += 1; 31 | } 32 | return val; 33 | }); 34 | export default path; 35 | -------------------------------------------------------------------------------- /source/pathOr.js: -------------------------------------------------------------------------------- 1 | import _curry3 from './internal/_curry3'; 2 | import defaultTo from './defaultTo'; 3 | import path from './path'; 4 | 5 | 6 | /** 7 | * If the given, non-null object has a value at the given path, returns the 8 | * value at that path. Otherwise returns the provided default value. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.18.0 13 | * @category Object 14 | * @typedefn Idx = String | Int 15 | * @sig a -> [Idx] -> {a} -> a 16 | * @param {*} d The default value. 17 | * @param {Array} p The path to use. 18 | * @param {Object} obj The object to retrieve the nested property from. 19 | * @return {*} The data at `path` of the supplied object or the default value. 20 | * @example 21 | * 22 | * R.pathOr('N/A', ['a', 'b'], {a: {b: 2}}); //=> 2 23 | * R.pathOr('N/A', ['a', 'b'], {c: {b: 2}}); //=> "N/A" 24 | */ 25 | var pathOr = _curry3(function pathOr(d, p, obj) { 26 | return defaultTo(d, path(p, obj)); 27 | }); 28 | export default pathOr; 29 | -------------------------------------------------------------------------------- /source/pathSatisfies.js: -------------------------------------------------------------------------------- 1 | import _curry3 from './internal/_curry3'; 2 | import path from './path'; 3 | 4 | 5 | /** 6 | * Returns `true` if the specified object property at given path satisfies the 7 | * given predicate; `false` otherwise. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.19.0 12 | * @category Logic 13 | * @typedefn Idx = String | Int 14 | * @sig (a -> Boolean) -> [Idx] -> {a} -> Boolean 15 | * @param {Function} pred 16 | * @param {Array} propPath 17 | * @param {*} obj 18 | * @return {Boolean} 19 | * @see R.propSatisfies, R.path 20 | * @example 21 | * 22 | * R.pathSatisfies(y => y > 0, ['x', 'y'], {x: {y: 2}}); //=> true 23 | */ 24 | var pathSatisfies = _curry3(function pathSatisfies(pred, propPath, obj) { 25 | return propPath.length > 0 && pred(path(propPath, obj)); 26 | }); 27 | export default pathSatisfies; 28 | -------------------------------------------------------------------------------- /source/prepend.js: -------------------------------------------------------------------------------- 1 | import _concat from './internal/_concat'; 2 | import _curry2 from './internal/_curry2'; 3 | 4 | 5 | /** 6 | * Returns a new list with the given element at the front, followed by the 7 | * contents of the list. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.1.0 12 | * @category List 13 | * @sig a -> [a] -> [a] 14 | * @param {*} el The item to add to the head of the output list. 15 | * @param {Array} list The array to add to the tail of the output list. 16 | * @return {Array} A new array. 17 | * @see R.append 18 | * @example 19 | * 20 | * R.prepend('fee', ['fi', 'fo', 'fum']); //=> ['fee', 'fi', 'fo', 'fum'] 21 | */ 22 | var prepend = _curry2(function prepend(el, list) { 23 | return _concat([el], list); 24 | }); 25 | export default prepend; 26 | -------------------------------------------------------------------------------- /source/product.js: -------------------------------------------------------------------------------- 1 | import multiply from './multiply'; 2 | import reduce from './reduce'; 3 | 4 | 5 | /** 6 | * Multiplies together all the elements of a list. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.1.0 11 | * @category Math 12 | * @sig [Number] -> Number 13 | * @param {Array} list An array of numbers 14 | * @return {Number} The product of all the numbers in the list. 15 | * @see R.reduce 16 | * @example 17 | * 18 | * R.product([2,4,6,8,100,1]); //=> 38400 19 | */ 20 | var product = reduce(multiply, 1); 21 | export default product; 22 | -------------------------------------------------------------------------------- /source/project.js: -------------------------------------------------------------------------------- 1 | import _map from './internal/_map'; 2 | import identity from './identity'; 3 | import pickAll from './pickAll'; 4 | import useWith from './useWith'; 5 | 6 | 7 | /** 8 | * Reasonable analog to SQL `select` statement. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.1.0 13 | * @category Object 14 | * @category Relation 15 | * @sig [k] -> [{k: v}] -> [{k: v}] 16 | * @param {Array} props The property names to project 17 | * @param {Array} objs The objects to query 18 | * @return {Array} An array of objects with just the `props` properties. 19 | * @example 20 | * 21 | * const abby = {name: 'Abby', age: 7, hair: 'blond', grade: 2}; 22 | * const fred = {name: 'Fred', age: 12, hair: 'brown', grade: 7}; 23 | * const kids = [abby, fred]; 24 | * R.project(['name', 'grade'], kids); //=> [{name: 'Abby', grade: 2}, {name: 'Fred', grade: 7}] 25 | */ 26 | var project = useWith(_map, [pickAll, identity]); // passing `identity` gives correct arity 27 | export default project; 28 | -------------------------------------------------------------------------------- /source/prop.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | import path from './path'; 3 | 4 | 5 | /** 6 | * Returns a function that when supplied an object returns the indicated 7 | * property of that object, if it exists. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.1.0 12 | * @category Object 13 | * @sig s -> {s: a} -> a | Undefined 14 | * @param {String} p The property name 15 | * @param {Object} obj The object to query 16 | * @return {*} The value at `obj.p`. 17 | * @see R.path 18 | * @example 19 | * 20 | * R.prop('x', {x: 100}); //=> 100 21 | * R.prop('x', {}); //=> undefined 22 | * R.compose(R.inc, R.prop('x'))({ x: 3 }) //=> 4 23 | */ 24 | 25 | var prop = _curry2(function prop(p, obj) { return path([p], obj); }); 26 | export default prop; 27 | -------------------------------------------------------------------------------- /source/propIs.js: -------------------------------------------------------------------------------- 1 | import _curry3 from './internal/_curry3'; 2 | import is from './is'; 3 | 4 | 5 | /** 6 | * Returns `true` if the specified object property is of the given type; 7 | * `false` otherwise. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.16.0 12 | * @category Type 13 | * @sig Type -> String -> Object -> Boolean 14 | * @param {Function} type 15 | * @param {String} name 16 | * @param {*} obj 17 | * @return {Boolean} 18 | * @see R.is, R.propSatisfies 19 | * @example 20 | * 21 | * R.propIs(Number, 'x', {x: 1, y: 2}); //=> true 22 | * R.propIs(Number, 'x', {x: 'foo'}); //=> false 23 | * R.propIs(Number, 'x', {}); //=> false 24 | */ 25 | var propIs = _curry3(function propIs(type, name, obj) { 26 | return is(type, obj[name]); 27 | }); 28 | export default propIs; 29 | -------------------------------------------------------------------------------- /source/propSatisfies.js: -------------------------------------------------------------------------------- 1 | import _curry3 from './internal/_curry3'; 2 | 3 | 4 | /** 5 | * Returns `true` if the specified object property satisfies the given 6 | * predicate; `false` otherwise. You can test multiple properties with 7 | * [`R.where`](#where). 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.16.0 12 | * @category Logic 13 | * @sig (a -> Boolean) -> String -> {String: a} -> Boolean 14 | * @param {Function} pred 15 | * @param {String} name 16 | * @param {*} obj 17 | * @return {Boolean} 18 | * @see R.where, R.propEq, R.propIs 19 | * @example 20 | * 21 | * R.propSatisfies(x => x > 0, 'x', {x: 1, y: 2}); //=> true 22 | */ 23 | var propSatisfies = _curry3(function propSatisfies(pred, name, obj) { 24 | return pred(obj[name]); 25 | }); 26 | export default propSatisfies; 27 | -------------------------------------------------------------------------------- /source/range.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | import _isNumber from './internal/_isNumber'; 3 | 4 | 5 | /** 6 | * Returns a list of numbers from `from` (inclusive) to `to` (exclusive). 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.1.0 11 | * @category List 12 | * @sig Number -> Number -> [Number] 13 | * @param {Number} from The first number in the list. 14 | * @param {Number} to One more than the last number in the list. 15 | * @return {Array} The list of numbers in the set `[a, b)`. 16 | * @example 17 | * 18 | * R.range(1, 5); //=> [1, 2, 3, 4] 19 | * R.range(50, 53); //=> [50, 51, 52] 20 | */ 21 | var range = _curry2(function range(from, to) { 22 | if (!(_isNumber(from) && _isNumber(to))) { 23 | throw new TypeError('Both arguments to range must be numbers'); 24 | } 25 | var result = []; 26 | var n = from; 27 | while (n < to) { 28 | result.push(n); 29 | n += 1; 30 | } 31 | return result; 32 | }); 33 | export default range; 34 | -------------------------------------------------------------------------------- /source/reduced.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import _reduced from './internal/_reduced'; 3 | 4 | /** 5 | * Returns a value wrapped to indicate that it is the final value of the reduce 6 | * and transduce functions. The returned value should be considered a black 7 | * box: the internal structure is not guaranteed to be stable. 8 | * 9 | * Note: this optimization is only available to the below functions: 10 | * - [`reduce`](#reduce) 11 | * - [`reduceWhile`](#reduceWhile) 12 | * - [`transduce`](#transduce) 13 | * 14 | * @func 15 | * @memberOf R 16 | * @since v0.15.0 17 | * @category List 18 | * @sig a -> * 19 | * @param {*} x The final value of the reduce. 20 | * @return {*} The wrapped value. 21 | * @see R.reduce, R.reduceWhile, R.transduce 22 | * @example 23 | * 24 | * R.reduce( 25 | * (acc, item) => item > 3 ? R.reduced(acc) : acc.concat(item), 26 | * [], 27 | * [1, 2, 3, 4, 5]) // [1, 2, 3] 28 | */ 29 | var reduced = _curry1(_reduced); 30 | export default reduced; 31 | -------------------------------------------------------------------------------- /source/repeat.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | import always from './always'; 3 | import times from './times'; 4 | 5 | 6 | /** 7 | * Returns a fixed list of size `n` containing a specified identical value. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.1.1 12 | * @category List 13 | * @sig a -> n -> [a] 14 | * @param {*} value The value to repeat. 15 | * @param {Number} n The desired size of the output list. 16 | * @return {Array} A new array containing `n` `value`s. 17 | * @see R.times 18 | * @example 19 | * 20 | * R.repeat('hi', 5); //=> ['hi', 'hi', 'hi', 'hi', 'hi'] 21 | * 22 | * const obj = {}; 23 | * const repeatedObjs = R.repeat(obj, 5); //=> [{}, {}, {}, {}, {}] 24 | * repeatedObjs[0] === repeatedObjs[1]; //=> true 25 | * @symb R.repeat(a, 0) = [] 26 | * @symb R.repeat(a, 1) = [a] 27 | * @symb R.repeat(a, 2) = [a, a] 28 | */ 29 | var repeat = _curry2(function repeat(value, n) { 30 | return times(always(value), n); 31 | }); 32 | export default repeat; 33 | -------------------------------------------------------------------------------- /source/set.js: -------------------------------------------------------------------------------- 1 | import _curry3 from './internal/_curry3'; 2 | import always from './always'; 3 | import over from './over'; 4 | 5 | 6 | /** 7 | * Returns the result of "setting" the portion of the given data structure 8 | * focused by the given lens to the given value. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.16.0 13 | * @category Object 14 | * @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s 15 | * @sig Lens s a -> a -> s -> s 16 | * @param {Lens} lens 17 | * @param {*} v 18 | * @param {*} x 19 | * @return {*} 20 | * @see R.prop, R.lensIndex, R.lensProp 21 | * @example 22 | * 23 | * const xLens = R.lensProp('x'); 24 | * 25 | * R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2} 26 | * R.set(xLens, 8, {x: 1, y: 2}); //=> {x: 8, y: 2} 27 | */ 28 | var set = _curry3(function set(lens, v, x) { 29 | return over(lens, always(v), x); 30 | }); 31 | export default set; 32 | -------------------------------------------------------------------------------- /source/split.js: -------------------------------------------------------------------------------- 1 | import invoker from './invoker'; 2 | 3 | 4 | /** 5 | * Splits a string into an array of strings based on the given 6 | * separator. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.1.0 11 | * @category String 12 | * @sig (String | RegExp) -> String -> [String] 13 | * @param {String|RegExp} sep The pattern. 14 | * @param {String} str The string to separate into an array. 15 | * @return {Array} The array of strings from `str` separated by `str`. 16 | * @see R.join 17 | * @example 18 | * 19 | * const pathComponents = R.split('/'); 20 | * R.tail(pathComponents('/usr/local/bin/node')); //=> ['usr', 'local', 'bin', 'node'] 21 | * 22 | * R.split('.', 'a.b.c.xyz.d'); //=> ['a', 'b', 'c', 'xyz', 'd'] 23 | */ 24 | var split = invoker(1, 'split'); 25 | export default split; 26 | -------------------------------------------------------------------------------- /source/splitAt.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | import length from './length'; 3 | import slice from './slice'; 4 | 5 | 6 | /** 7 | * Splits a given list or string at a given index. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.19.0 12 | * @category List 13 | * @sig Number -> [a] -> [[a], [a]] 14 | * @sig Number -> String -> [String, String] 15 | * @param {Number} index The index where the array/string is split. 16 | * @param {Array|String} array The array/string to be split. 17 | * @return {Array} 18 | * @example 19 | * 20 | * R.splitAt(1, [1, 2, 3]); //=> [[1], [2, 3]] 21 | * R.splitAt(5, 'hello world'); //=> ['hello', ' world'] 22 | * R.splitAt(-1, 'foobar'); //=> ['fooba', 'r'] 23 | */ 24 | var splitAt = _curry2(function splitAt(index, array) { 25 | return [slice(0, index, array), slice(index, length(array), array)]; 26 | }); 27 | export default splitAt; 28 | -------------------------------------------------------------------------------- /source/splitEvery.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | import slice from './slice'; 3 | 4 | 5 | /** 6 | * Splits a collection into slices of the specified length. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.16.0 11 | * @category List 12 | * @sig Number -> [a] -> [[a]] 13 | * @sig Number -> String -> [String] 14 | * @param {Number} n 15 | * @param {Array} list 16 | * @return {Array} 17 | * @example 18 | * 19 | * R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7]); //=> [[1, 2, 3], [4, 5, 6], [7]] 20 | * R.splitEvery(3, 'foobarbaz'); //=> ['foo', 'bar', 'baz'] 21 | */ 22 | var splitEvery = _curry2(function splitEvery(n, list) { 23 | if (n <= 0) { 24 | throw new Error('First argument to splitEvery must be a positive integer'); 25 | } 26 | var result = []; 27 | var idx = 0; 28 | while (idx < list.length) { 29 | result.push(slice(idx, idx += n, list)); 30 | } 31 | return result; 32 | }); 33 | export default splitEvery; 34 | -------------------------------------------------------------------------------- /source/startsWith.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | import equals from './equals'; 3 | import take from './take'; 4 | 5 | /** 6 | * Checks if a list starts with the provided sublist. 7 | * 8 | * Similarly, checks if a string starts with the provided substring. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.24.0 13 | * @category List 14 | * @sig [a] -> [a] -> Boolean 15 | * @sig String -> String -> Boolean 16 | * @param {*} prefix 17 | * @param {*} list 18 | * @return {Boolean} 19 | * @see R.endsWith 20 | * @example 21 | * 22 | * R.startsWith('a', 'abc') //=> true 23 | * R.startsWith('b', 'abc') //=> false 24 | * R.startsWith(['a'], ['a', 'b', 'c']) //=> true 25 | * R.startsWith(['b'], ['a', 'b', 'c']) //=> false 26 | */ 27 | var startsWith = _curry2(function(prefix, list) { 28 | return equals(take(prefix.length, list), prefix); 29 | }); 30 | export default startsWith; 31 | -------------------------------------------------------------------------------- /source/subtract.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | 3 | 4 | /** 5 | * Subtracts its second argument from its first argument. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.1.0 10 | * @category Math 11 | * @sig Number -> Number -> Number 12 | * @param {Number} a The first value. 13 | * @param {Number} b The second value. 14 | * @return {Number} The result of `a - b`. 15 | * @see R.add 16 | * @example 17 | * 18 | * R.subtract(10, 8); //=> 2 19 | * 20 | * const minus5 = R.subtract(R.__, 5); 21 | * minus5(17); //=> 12 22 | * 23 | * const complementaryAngle = R.subtract(90); 24 | * complementaryAngle(30); //=> 60 25 | * complementaryAngle(72); //=> 18 26 | */ 27 | var subtract = _curry2(function subtract(a, b) { 28 | return Number(a) - Number(b); 29 | }); 30 | export default subtract; 31 | -------------------------------------------------------------------------------- /source/sum.js: -------------------------------------------------------------------------------- 1 | import add from './add'; 2 | import reduce from './reduce'; 3 | 4 | 5 | /** 6 | * Adds together all the elements of a list. 7 | * 8 | * @func 9 | * @memberOf R 10 | * @since v0.1.0 11 | * @category Math 12 | * @sig [Number] -> Number 13 | * @param {Array} list An array of numbers 14 | * @return {Number} The sum of all the numbers in the list. 15 | * @see R.reduce 16 | * @example 17 | * 18 | * R.sum([2,4,6,8,100,1]); //=> 121 19 | */ 20 | var sum = reduce(add, 0); 21 | export default sum; 22 | -------------------------------------------------------------------------------- /source/symmetricDifference.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | import concat from './concat'; 3 | import difference from './difference'; 4 | 5 | 6 | /** 7 | * Finds the set (i.e. no duplicates) of all elements contained in the first or 8 | * second list, but not both. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.19.0 13 | * @category Relation 14 | * @sig [*] -> [*] -> [*] 15 | * @param {Array} list1 The first list. 16 | * @param {Array} list2 The second list. 17 | * @return {Array} The elements in `list1` or `list2`, but not both. 18 | * @see R.symmetricDifferenceWith, R.difference, R.differenceWith 19 | * @example 20 | * 21 | * R.symmetricDifference([1,2,3,4], [7,6,5,4,3]); //=> [1,2,7,6,5] 22 | * R.symmetricDifference([7,6,5,4,3], [1,2,3,4]); //=> [7,6,5,1,2] 23 | */ 24 | var symmetricDifference = _curry2(function symmetricDifference(list1, list2) { 25 | return concat(difference(list1, list2), difference(list2, list1)); 26 | }); 27 | export default symmetricDifference; 28 | -------------------------------------------------------------------------------- /source/tail.js: -------------------------------------------------------------------------------- 1 | import _checkForMethod from './internal/_checkForMethod'; 2 | import _curry1 from './internal/_curry1'; 3 | import slice from './slice'; 4 | 5 | 6 | /** 7 | * Returns all but the first element of the given list or string (or object 8 | * with a `tail` method). 9 | * 10 | * Dispatches to the `slice` method of the first argument, if present. 11 | * 12 | * @func 13 | * @memberOf R 14 | * @since v0.1.0 15 | * @category List 16 | * @sig [a] -> [a] 17 | * @sig String -> String 18 | * @param {*} list 19 | * @return {*} 20 | * @see R.head, R.init, R.last 21 | * @example 22 | * 23 | * R.tail([1, 2, 3]); //=> [2, 3] 24 | * R.tail([1, 2]); //=> [2] 25 | * R.tail([1]); //=> [] 26 | * R.tail([]); //=> [] 27 | * 28 | * R.tail('abc'); //=> 'bc' 29 | * R.tail('ab'); //=> 'b' 30 | * R.tail('a'); //=> '' 31 | * R.tail(''); //=> '' 32 | */ 33 | var tail = _curry1(_checkForMethod('tail', slice(1, Infinity))); 34 | export default tail; 35 | -------------------------------------------------------------------------------- /source/tap.js: -------------------------------------------------------------------------------- 1 | import _curry2 from './internal/_curry2'; 2 | import _dispatchable from './internal/_dispatchable'; 3 | import _xtap from './internal/_xtap'; 4 | 5 | 6 | /** 7 | * Runs the given function with the supplied object, then returns the object. 8 | * 9 | * Acts as a transducer if a transformer is given as second parameter. 10 | * 11 | * @func 12 | * @memberOf R 13 | * @since v0.1.0 14 | * @category Function 15 | * @sig (a -> *) -> a -> a 16 | * @param {Function} fn The function to call with `x`. The return value of `fn` will be thrown away. 17 | * @param {*} x 18 | * @return {*} `x`. 19 | * @example 20 | * 21 | * const sayX = x => console.log('x is ' + x); 22 | * R.tap(sayX, 100); //=> 100 23 | * // logs 'x is 100' 24 | * @symb R.tap(f, a) = a 25 | */ 26 | var tap = _curry2(_dispatchable([], _xtap, function tap(fn, x) { 27 | fn(x); 28 | return x; 29 | })); 30 | export default tap; 31 | -------------------------------------------------------------------------------- /source/test.js: -------------------------------------------------------------------------------- 1 | import _cloneRegExp from './internal/_cloneRegExp'; 2 | import _curry2 from './internal/_curry2'; 3 | import _isRegExp from './internal/_isRegExp'; 4 | import toString from './toString'; 5 | 6 | 7 | /** 8 | * Determines whether a given string matches a given regular expression. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.12.0 13 | * @category String 14 | * @sig RegExp -> String -> Boolean 15 | * @param {RegExp} pattern 16 | * @param {String} str 17 | * @return {Boolean} 18 | * @see R.match 19 | * @example 20 | * 21 | * R.test(/^x/, 'xyz'); //=> true 22 | * R.test(/^y/, 'xyz'); //=> false 23 | */ 24 | var test = _curry2(function test(pattern, str) { 25 | if (!_isRegExp(pattern)) { 26 | throw new TypeError('‘test’ requires a value of type RegExp as its first argument; received ' + toString(pattern)); 27 | } 28 | return _cloneRegExp(pattern).test(str); 29 | }); 30 | export default test; 31 | -------------------------------------------------------------------------------- /source/toLower.js: -------------------------------------------------------------------------------- 1 | import invoker from './invoker'; 2 | 3 | 4 | /** 5 | * The lower case version of a string. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.9.0 10 | * @category String 11 | * @sig String -> String 12 | * @param {String} str The string to lower case. 13 | * @return {String} The lower case version of `str`. 14 | * @see R.toUpper 15 | * @example 16 | * 17 | * R.toLower('XYZ'); //=> 'xyz' 18 | */ 19 | var toLower = invoker(0, 'toLowerCase'); 20 | export default toLower; 21 | -------------------------------------------------------------------------------- /source/toPairs.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import _has from './internal/_has'; 3 | 4 | 5 | /** 6 | * Converts an object into an array of key, value arrays. Only the object's 7 | * own properties are used. 8 | * Note that the order of the output array is not guaranteed to be consistent 9 | * across different JS platforms. 10 | * 11 | * @func 12 | * @memberOf R 13 | * @since v0.4.0 14 | * @category Object 15 | * @sig {String: *} -> [[String,*]] 16 | * @param {Object} obj The object to extract from 17 | * @return {Array} An array of key, value arrays from the object's own properties. 18 | * @see R.fromPairs 19 | * @example 20 | * 21 | * R.toPairs({a: 1, b: 2, c: 3}); //=> [['a', 1], ['b', 2], ['c', 3]] 22 | */ 23 | var toPairs = _curry1(function toPairs(obj) { 24 | var pairs = []; 25 | for (var prop in obj) { 26 | if (_has(prop, obj)) { 27 | pairs[pairs.length] = [prop, obj[prop]]; 28 | } 29 | } 30 | return pairs; 31 | }); 32 | export default toPairs; 33 | -------------------------------------------------------------------------------- /source/toUpper.js: -------------------------------------------------------------------------------- 1 | import invoker from './invoker'; 2 | 3 | 4 | /** 5 | * The upper case version of a string. 6 | * 7 | * @func 8 | * @memberOf R 9 | * @since v0.9.0 10 | * @category String 11 | * @sig String -> String 12 | * @param {String} str The string to upper case. 13 | * @return {String} The upper case version of `str`. 14 | * @see R.toLower 15 | * @example 16 | * 17 | * R.toUpper('abc'); //=> 'ABC' 18 | */ 19 | var toUpper = invoker(0, 'toUpperCase'); 20 | export default toUpper; 21 | -------------------------------------------------------------------------------- /source/unapply.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | 3 | 4 | /** 5 | * Takes a function `fn`, which takes a single array argument, and returns a 6 | * function which: 7 | * 8 | * - takes any number of positional arguments; 9 | * - passes these arguments to `fn` as an array; and 10 | * - returns the result. 11 | * 12 | * In other words, `R.unapply` derives a variadic function from a function which 13 | * takes an array. `R.unapply` is the inverse of [`R.apply`](#apply). 14 | * 15 | * @func 16 | * @memberOf R 17 | * @since v0.8.0 18 | * @category Function 19 | * @sig ([*...] -> a) -> (*... -> a) 20 | * @param {Function} fn 21 | * @return {Function} 22 | * @see R.apply 23 | * @example 24 | * 25 | * R.unapply(JSON.stringify)(1, 2, 3); //=> '[1,2,3]' 26 | * @symb R.unapply(f)(a, b) = f([a, b]) 27 | */ 28 | var unapply = _curry1(function unapply(fn) { 29 | return function() { 30 | return fn(Array.prototype.slice.call(arguments, 0)); 31 | }; 32 | }); 33 | export default unapply; 34 | -------------------------------------------------------------------------------- /source/union.js: -------------------------------------------------------------------------------- 1 | import _concat from './internal/_concat'; 2 | import _curry2 from './internal/_curry2'; 3 | import compose from './compose'; 4 | import uniq from './uniq'; 5 | 6 | 7 | /** 8 | * Combines two lists into a set (i.e. no duplicates) composed of the elements 9 | * of each list. 10 | * 11 | * @func 12 | * @memberOf R 13 | * @since v0.1.0 14 | * @category Relation 15 | * @sig [*] -> [*] -> [*] 16 | * @param {Array} as The first list. 17 | * @param {Array} bs The second list. 18 | * @return {Array} The first and second lists concatenated, with 19 | * duplicates removed. 20 | * @example 21 | * 22 | * R.union([1, 2, 3], [2, 3, 4]); //=> [1, 2, 3, 4] 23 | */ 24 | var union = _curry2(compose(uniq, _concat)); 25 | export default union; 26 | -------------------------------------------------------------------------------- /source/uniq.js: -------------------------------------------------------------------------------- 1 | import identity from './identity'; 2 | import uniqBy from './uniqBy'; 3 | 4 | 5 | /** 6 | * Returns a new list containing only one copy of each element in the original 7 | * list. [`R.equals`](#equals) is used to determine equality. 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.1.0 12 | * @category List 13 | * @sig [a] -> [a] 14 | * @param {Array} list The array to consider. 15 | * @return {Array} The list of unique items. 16 | * @example 17 | * 18 | * R.uniq([1, 1, 2, 1]); //=> [1, 2] 19 | * R.uniq([1, '1']); //=> [1, '1'] 20 | * R.uniq([[42], [42]]); //=> [[42]] 21 | */ 22 | var uniq = uniqBy(identity); 23 | export default uniq; 24 | -------------------------------------------------------------------------------- /source/unnest.js: -------------------------------------------------------------------------------- 1 | import _identity from './internal/_identity'; 2 | import chain from './chain'; 3 | 4 | 5 | /** 6 | * Shorthand for `R.chain(R.identity)`, which removes one level of nesting from 7 | * any [Chain](https://github.com/fantasyland/fantasy-land#chain). 8 | * 9 | * @func 10 | * @memberOf R 11 | * @since v0.3.0 12 | * @category List 13 | * @sig Chain c => c (c a) -> c a 14 | * @param {*} list 15 | * @return {*} 16 | * @see R.flatten, R.chain 17 | * @example 18 | * 19 | * R.unnest([1, [2], [[3]]]); //=> [1, 2, [3]] 20 | * R.unnest([[1, 2], [3, 4], [5, 6]]); //=> [1, 2, 3, 4, 5, 6] 21 | */ 22 | var unnest = chain(_identity); 23 | export default unnest; 24 | -------------------------------------------------------------------------------- /source/until.js: -------------------------------------------------------------------------------- 1 | import _curry3 from './internal/_curry3'; 2 | 3 | 4 | /** 5 | * Takes a predicate, a transformation function, and an initial value, 6 | * and returns a value of the same type as the initial value. 7 | * It does so by applying the transformation until the predicate is satisfied, 8 | * at which point it returns the satisfactory value. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.20.0 13 | * @category Logic 14 | * @sig (a -> Boolean) -> (a -> a) -> a -> a 15 | * @param {Function} pred A predicate function 16 | * @param {Function} fn The iterator function 17 | * @param {*} init Initial value 18 | * @return {*} Final value that satisfies predicate 19 | * @example 20 | * 21 | * R.until(R.gt(R.__, 100), R.multiply(2))(1) // => 128 22 | */ 23 | var until = _curry3(function until(pred, fn, init) { 24 | var val = init; 25 | while (!pred(val)) { 26 | val = fn(val); 27 | } 28 | return val; 29 | }); 30 | export default until; 31 | -------------------------------------------------------------------------------- /source/values.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | import keys from './keys'; 3 | 4 | 5 | /** 6 | * Returns a list of all the enumerable own properties of the supplied object. 7 | * Note that the order of the output array is not guaranteed across different 8 | * JS platforms. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.1.0 13 | * @category Object 14 | * @sig {k: v} -> [v] 15 | * @param {Object} obj The object to extract values from 16 | * @return {Array} An array of the values of the object's own properties. 17 | * @see R.valuesIn, R.keys 18 | * @example 19 | * 20 | * R.values({a: 1, b: 2, c: 3}); //=> [1, 2, 3] 21 | */ 22 | var values = _curry1(function values(obj) { 23 | var props = keys(obj); 24 | var len = props.length; 25 | var vals = []; 26 | var idx = 0; 27 | while (idx < len) { 28 | vals[idx] = obj[props[idx]]; 29 | idx += 1; 30 | } 31 | return vals; 32 | }); 33 | export default values; 34 | -------------------------------------------------------------------------------- /source/valuesIn.js: -------------------------------------------------------------------------------- 1 | import _curry1 from './internal/_curry1'; 2 | 3 | 4 | /** 5 | * Returns a list of all the properties, including prototype properties, of the 6 | * supplied object. 7 | * Note that the order of the output array is not guaranteed to be consistent 8 | * across different JS platforms. 9 | * 10 | * @func 11 | * @memberOf R 12 | * @since v0.2.0 13 | * @category Object 14 | * @sig {k: v} -> [v] 15 | * @param {Object} obj The object to extract values from 16 | * @return {Array} An array of the values of the object's own and prototype properties. 17 | * @see R.values, R.keysIn 18 | * @example 19 | * 20 | * const F = function() { this.x = 'X'; }; 21 | * F.prototype.y = 'Y'; 22 | * const f = new F(); 23 | * R.valuesIn(f); //=> ['X', 'Y'] 24 | */ 25 | var valuesIn = _curry1(function valuesIn(obj) { 26 | var prop; 27 | var vs = []; 28 | for (prop in obj) { 29 | vs[vs.length] = obj[prop]; 30 | } 31 | return vs; 32 | }); 33 | export default valuesIn; 34 | -------------------------------------------------------------------------------- /source/without.js: -------------------------------------------------------------------------------- 1 | import _includes from './internal/_includes'; 2 | import _curry2 from './internal/_curry2'; 3 | import flip from './flip'; 4 | import reject from './reject'; 5 | 6 | 7 | /** 8 | * Returns a new list without values in the first argument. 9 | * [`R.equals`](#equals) is used to determine equality. 10 | * 11 | * Acts as a transducer if a transformer is given in list position. 12 | * 13 | * @func 14 | * @memberOf R 15 | * @since v0.19.0 16 | * @category List 17 | * @sig [a] -> [a] -> [a] 18 | * @param {Array} list1 The values to be removed from `list2`. 19 | * @param {Array} list2 The array to remove values from. 20 | * @return {Array} The new array without values in `list1`. 21 | * @see R.transduce, R.difference, R.remove 22 | * @example 23 | * 24 | * R.without([1, 2], [1, 2, 1, 3, 4]); //=> [3, 4] 25 | */ 26 | var without = _curry2(function(xs, list) { 27 | return reject(flip(_includes)(xs), list); 28 | }); 29 | export default without; 30 | -------------------------------------------------------------------------------- /test/F.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('F', function() { 6 | it('always returns false', function() { 7 | eq(R.F(), false); 8 | eq(R.F(10), false); 9 | eq(R.F(true), false); 10 | }); 11 | 12 | }); 13 | -------------------------------------------------------------------------------- /test/T.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('T', function() { 6 | it('always returns true', function() { 7 | eq(R.T(), true); 8 | eq(R.T(10), true); 9 | eq(R.T(true), true); 10 | }); 11 | 12 | }); 13 | -------------------------------------------------------------------------------- /test/and.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('and', function() { 6 | it('compares two values with js &&', function() { 7 | eq(R.and(true, true), true); 8 | eq(R.and(true, false), false); 9 | eq(R.and(false, true), false); 10 | eq(R.and(false, false), false); 11 | }); 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /test/aperture.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('aperture', function() { 6 | var sevenLs = [1, 2, 3, 4, 5, 6, 7]; 7 | it('creates a list of n-tuples from a list', function() { 8 | eq(R.aperture(1, sevenLs), [[1], [2], [3], [4], [5], [6], [7]]); 9 | eq(R.aperture(2, sevenLs), [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]); 10 | eq(R.aperture(3, sevenLs), [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7]]); 11 | eq(R.aperture(4, [1, 2, 3, 4]), [[1, 2, 3, 4]]); 12 | }); 13 | 14 | it('returns an empty list when `n` > `list.length`', function() { 15 | eq(R.aperture(6, [1, 2, 3]), []); 16 | eq(R.aperture(1, []), []); 17 | }); 18 | 19 | it('can act as a transducer', function() { 20 | eq(R.into([], R.aperture(2), sevenLs), [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]); 21 | }); 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /test/append.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('append', function() { 6 | it('adds the element to the end of the list', function() { 7 | eq(R.append('z', ['x', 'y']), ['x', 'y', 'z']); 8 | eq(R.append(['a', 'z'], ['x', 'y']), ['x', 'y', ['a', 'z']]); 9 | }); 10 | 11 | it('works on empty list', function() { 12 | eq(R.append(1, []), [1]); 13 | }); 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /test/apply.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('apply', function() { 6 | it('applies function to argument list', function() { 7 | eq(R.apply(Math.max, [1, 2, 3, -99, 42, 6, 7]), 42); 8 | }); 9 | 10 | it('provides no way to specify context', function() { 11 | var obj = {method: function() { return this === obj; }}; 12 | eq(R.apply(obj.method, []), false); 13 | eq(R.apply(R.bind(obj.method, obj), []), true); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/applyTo.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | describe('applyTo', function() { 5 | it('applies the function to its first argument', function() { 6 | eq(R.applyTo(21, R.multiply(2)), 42); 7 | }); 8 | 9 | it('has length 2', function() { 10 | eq(R.applyTo.length, 2); 11 | }); 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /test/ascend.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | describe('ascend', function() { 5 | it('builds an ascending comparator function out of the identity function', function() { 6 | eq([3, 1, 8, 1, 2, 5].sort(R.ascend(R.identity)), [1, 1, 2, 3, 5, 8]); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /test/binary.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('binary', function() { 6 | it('turns multiple-argument function into binary one', function() { 7 | R.binary(function(x, y, z) { 8 | eq(arguments.length, 2); 9 | eq(typeof z, 'undefined'); 10 | })(10, 20, 30); 11 | }); 12 | 13 | it('initial arguments are passed through normally', function() { 14 | R.binary(function(x, y, z) { 15 | eq(x, 10); 16 | eq(y, 20); 17 | void z; 18 | })(10, 20, 30); 19 | }); 20 | 21 | }); 22 | -------------------------------------------------------------------------------- /test/call.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('call', function() { 6 | it('returns the result of calling its first argument with the remaining arguments', function() { 7 | eq(R.call(Math.max, 1, 2, 3, -99, 42, 6, 7), 42); 8 | }); 9 | 10 | it('accepts one or more arguments', function() { 11 | var fn = function() { return arguments.length; }; 12 | eq(R.call(fn), 0); 13 | eq(R.call(fn, 'x'), 1); 14 | eq(R.call(fn, 'x', 'y'), 2); 15 | eq(R.call(fn, 'x', 'y', 'z'), 3); 16 | }); 17 | 18 | it('provides no way to specify context', function() { 19 | var obj = {method: function() { return this === obj; }}; 20 | eq(R.call(obj.method), false); 21 | eq(R.call(R.bind(obj.method, obj)), true); 22 | }); 23 | 24 | }); 25 | -------------------------------------------------------------------------------- /test/clamp.js: -------------------------------------------------------------------------------- 1 | var eq = require('./shared/eq'); 2 | var R = require('../source'); 3 | 4 | describe('clamp', function() { 5 | it('clamps to the lower bound', function() { 6 | eq(R.clamp(1, 10, 0), 1); 7 | eq(R.clamp(3, 12, 1), 3); 8 | eq(R.clamp(-15, 3, -100), -15); 9 | }); 10 | 11 | it('clamps to the upper bound', function() { 12 | eq(R.clamp(1, 10, 20), 10); 13 | eq(R.clamp(3, 12, 23), 12); 14 | eq(R.clamp(-15, 3, 16), 3); 15 | }); 16 | 17 | it('leaves it alone when within the bound', function() { 18 | eq(R.clamp(1, 10, 4), 4); 19 | eq(R.clamp(3, 12, 6), 6); 20 | eq(R.clamp(-15, 3, 0), 0); 21 | }); 22 | 23 | it('works with letters as well', function() { 24 | eq(R.clamp('d', 'n', 'f'), 'f'); 25 | eq(R.clamp('d', 'n', 'a'), 'd'); 26 | eq(R.clamp('d', 'n', 'q'), 'n'); 27 | }); 28 | 29 | }); 30 | -------------------------------------------------------------------------------- /test/comparator.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('comparator', function() { 6 | it('builds a comparator function for sorting out of a simple predicate that reports whether the first param is smaller', function() { 7 | eq([3, 1, 8, 1, 2, 5].sort(R.comparator(function(a, b) {return a < b;})), [1, 1, 2, 3, 5, 8]); 8 | }); 9 | 10 | }); 11 | -------------------------------------------------------------------------------- /test/complement.js: -------------------------------------------------------------------------------- 1 | var S = require('sanctuary'); 2 | 3 | var R = require('../source'); 4 | var eq = require('./shared/eq'); 5 | 6 | 7 | describe('complement', function() { 8 | it('creates boolean-returning function that reverses another', function() { 9 | var even = function(x) {return x % 2 === 0;}; 10 | var f = R.complement(even); 11 | eq(f(8), false); 12 | eq(f(13), true); 13 | }); 14 | 15 | it('accepts a function that take multiple parameters', function() { 16 | var between = function(a, b, c) {return a < b && b < c;}; 17 | var f = R.complement(between); 18 | eq(f(4, 5, 11), false); 19 | eq(f(12, 2, 6), true); 20 | }); 21 | 22 | it('accepts fantasy-land functors', function() { 23 | var Just = S.Just; 24 | var Nothing = S.Nothing; 25 | eq(R.complement(Just(true)), Just(false)); 26 | eq(R.complement(Just(false)), Just(true)); 27 | eq(R.complement(Nothing()), Nothing()); 28 | }); 29 | 30 | }); 31 | -------------------------------------------------------------------------------- /test/dec.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('dec', function() { 6 | 7 | it('decrements its argument', function() { 8 | eq(R.dec(-1), -2); 9 | eq(R.dec(0), -1); 10 | eq(R.dec(1), 0); 11 | eq(R.dec(12.34), 11.34); 12 | eq(R.dec(-Infinity), -Infinity); 13 | eq(R.dec(Infinity), Infinity); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/defaultTo.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | describe('defaultTo', function() { 5 | 6 | var defaultTo42 = R.defaultTo(42); 7 | 8 | it('returns the default value if input is null, undefined or NaN', function() { 9 | eq(42, defaultTo42(null)); 10 | eq(42, defaultTo42(undefined)); 11 | eq(42, defaultTo42(NaN)); 12 | }); 13 | 14 | it('returns the input value if it is not null/undefined', function() { 15 | eq('a real value', defaultTo42('a real value')); 16 | }); 17 | 18 | it('returns the input value even if it is considered falsy', function() { 19 | eq('', defaultTo42('')); 20 | eq(0, defaultTo42(0)); 21 | eq(false, defaultTo42(false)); 22 | eq([], defaultTo42([])); 23 | }); 24 | 25 | it('can be called with both arguments directly', function() { 26 | eq(42, R.defaultTo(42, null)); 27 | eq('a real value', R.defaultTo(42, 'a real value')); 28 | }); 29 | 30 | }); 31 | -------------------------------------------------------------------------------- /test/descend.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | describe('descend', function() { 5 | it('builds a descending comparator function out of the identity function', function() { 6 | eq([3, 1, 8, 1, 2, 5].sort(R.descend(R.identity)), [8, 5, 3, 2, 1, 1]); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /test/divide.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('divide', function() { 6 | it('divides two numbers', function() { 7 | eq(R.divide(28, 7), 4); 8 | }); 9 | 10 | }); 11 | -------------------------------------------------------------------------------- /test/dropWhile.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('dropWhile', function() { 6 | it('skips elements while the function reports `true`', function() { 7 | eq(R.dropWhile(function(x) {return x < 5;}, [1, 3, 5, 7, 9]), [5, 7, 9]); 8 | }); 9 | 10 | it('returns an empty list for an empty list', function() { 11 | eq(R.dropWhile(function() { return false; }, []), []); 12 | eq(R.dropWhile(function() { return true; }, []), []); 13 | }); 14 | 15 | it('starts at the right arg and acknowledges undefined', function() { 16 | var sublist = R.dropWhile(function(x) {return x !== void 0;}, [1, 3, void 0, 5, 7]); 17 | eq(sublist.length, 3); 18 | eq(sublist[0], void 0); 19 | eq(sublist[1], 5); 20 | eq(sublist[2], 7); 21 | }); 22 | 23 | it('can operate on strings', function() { 24 | eq(R.dropWhile(function(x) { return x !== 'd'; }, 'Ramda'), 'da'); 25 | }); 26 | 27 | }); 28 | -------------------------------------------------------------------------------- /test/eqBy.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('eqBy', function() { 6 | 7 | it('determines whether two values map to the same value in the codomain', function() { 8 | eq(R.eqBy(Math.abs, 5, 5), true); 9 | eq(R.eqBy(Math.abs, 5, -5), true); 10 | eq(R.eqBy(Math.abs, -5, 5), true); 11 | eq(R.eqBy(Math.abs, -5, -5), true); 12 | eq(R.eqBy(Math.abs, 42, 99), false); 13 | }); 14 | 15 | it('has R.equals semantics', function() { 16 | function Just(x) { this.value = x; } 17 | Just.prototype.equals = function(x) { 18 | return x instanceof Just && R.equals(x.value, this.value); 19 | }; 20 | 21 | eq(R.eqBy(R.identity, 0, -0), false); 22 | eq(R.eqBy(R.identity, -0, 0), false); 23 | eq(R.eqBy(R.identity, NaN, NaN), true); 24 | eq(R.eqBy(R.identity, new Just([42]), new Just([42])), true); 25 | }); 26 | 27 | }); 28 | -------------------------------------------------------------------------------- /test/eqProps.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('eqProps', function() { 6 | it('reports whether two objects have the same value for a given property', function() { 7 | eq(R.eqProps('name', {name: 'fred', age: 10}, {name: 'fred', age: 12}), true); 8 | eq(R.eqProps('name', {name: 'fred', age: 10}, {name: 'franny', age: 10}), false); 9 | }); 10 | 11 | it('has R.equals semantics', function() { 12 | function Just(x) { this.value = x; } 13 | Just.prototype.equals = function(x) { 14 | return x instanceof Just && R.equals(x.value, this.value); 15 | }; 16 | 17 | eq(R.eqProps('value', {value: 0}, {value: -0}), false); 18 | eq(R.eqProps('value', {value: -0}, {value: 0}), false); 19 | eq(R.eqProps('value', {value: NaN}, {value: NaN}), true); 20 | eq(R.eqProps('value', {value: new Just([42])}, {value: new Just([42])}), true); 21 | }); 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /test/forEachObjIndexed.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('forEachObjIndexed', function() { 6 | var obj = { x: 1, y: 2, z: 123 }; 7 | 8 | it('performs the passed in function on each key and value of the object', function() { 9 | var sideEffect = {}; 10 | R.forEachObjIndexed(function(value, key) { sideEffect[key] = value; }, obj); 11 | eq(sideEffect, obj); 12 | }); 13 | 14 | it('returns the original object', function() { 15 | var s = ''; 16 | eq(R.forEachObjIndexed(function(value) { s += value; }, obj), obj); 17 | eq('12123', s); 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /test/fromPairs.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('fromPairs', function() { 6 | 7 | it('combines an array of two-element arrays into an object', function() { 8 | eq(R.fromPairs([['a', 1], ['b', 2], ['c', 3]]), {a: 1, b: 2, c: 3}); 9 | }); 10 | 11 | it('gives later entries precedence over earlier ones', function() { 12 | eq(R.fromPairs([['x', 1], ['x', 2]]), {x: 2}); 13 | }); 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /test/gt.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('gt', function() { 6 | it('reports whether one item is greater than another', function() { 7 | eq(R.gt(3, 5), false); 8 | eq(R.gt(6, 4), true); 9 | eq(R.gt(7.0, 7.0), false); 10 | eq(R.gt('abc', 'xyz'), false); 11 | eq(R.gt('abcd', 'abc'), true); 12 | }); 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /test/gte.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('gte', function() { 6 | it('reports whether one item is greater than or equal to another', function() { 7 | eq(R.gte(3, 5), false); 8 | eq(R.gte(6, 4), true); 9 | eq(R.gte(7.0, 7.0), true); 10 | eq(R.gte('abc', 'xyz'), false); 11 | eq(R.gte('abcd', 'abc'), true); 12 | }); 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /test/has.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('has', function() { 6 | var fred = {name: 'Fred', age: 23}; 7 | var anon = {age: 99}; 8 | 9 | it('returns true if the specified property is present', function() { 10 | eq(R.has('name', fred), true); 11 | }); 12 | 13 | it('returns false if the specified property is absent', function() { 14 | eq(R.has('name', anon), false); 15 | }); 16 | 17 | it('does not check properties from the prototype chain', function() { 18 | var Person = function() {}; 19 | Person.prototype.age = function() {}; 20 | 21 | var bob = new Person(); 22 | eq(R.has('age', bob), false); 23 | }); 24 | 25 | }); 26 | -------------------------------------------------------------------------------- /test/hasIn.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('hasIn', function() { 6 | var fred = {name: 'Fred', age: 23}; 7 | var anon = {age: 99}; 8 | 9 | it('returns a function that checks the appropriate property', function() { 10 | var nm = R.hasIn('name'); 11 | eq(typeof nm, 'function'); 12 | eq(nm(fred), true); 13 | eq(nm(anon), false); 14 | }); 15 | 16 | it('checks properties from the prototype chain', function() { 17 | var Person = function() {}; 18 | Person.prototype.age = function() {}; 19 | 20 | var bob = new Person(); 21 | eq(R.hasIn('age', bob), true); 22 | }); 23 | 24 | it('works properly when called with two arguments', function() { 25 | eq(R.hasIn('name', fred), true); 26 | eq(R.hasIn('name', anon), false); 27 | }); 28 | 29 | }); 30 | -------------------------------------------------------------------------------- /test/head.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | 3 | var R = require('../source'); 4 | var eq = require('./shared/eq'); 5 | 6 | 7 | describe('head', function() { 8 | 9 | it('returns the first element of an ordered collection', function() { 10 | eq(R.head([1, 2, 3]), 1); 11 | eq(R.head([2, 3]), 2); 12 | eq(R.head([3]), 3); 13 | eq(R.head([]), undefined); 14 | 15 | eq(R.head('abc'), 'a'); 16 | eq(R.head('bc'), 'b'); 17 | eq(R.head('c'), 'c'); 18 | eq(R.head(''), ''); 19 | }); 20 | 21 | it('throws if applied to null or undefined', function() { 22 | assert.throws(function() { R.head(null); }, TypeError); 23 | assert.throws(function() { R.head(undefined); }, TypeError); 24 | }); 25 | 26 | }); 27 | -------------------------------------------------------------------------------- /test/helpers/listXf.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | '@@transducer/init': function() { return []; }, 3 | '@@transducer/step': function(acc, x) { return acc.concat([x]); }, 4 | '@@transducer/result': function(x) { return x; } 5 | }; 6 | -------------------------------------------------------------------------------- /test/identical.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('identical', function() { 6 | var a = []; 7 | var b = a; 8 | it('has Object.is semantics', function() { 9 | eq(R.identical(100, 100), true); 10 | eq(R.identical(100, '100'), false); 11 | eq(R.identical('string', 'string'), true); 12 | eq(R.identical([], []), false); 13 | eq(R.identical(a, b), true); 14 | eq(R.identical(undefined, undefined), true); 15 | eq(R.identical(null, undefined), false); 16 | 17 | eq(R.identical(-0, 0), false); 18 | eq(R.identical(0, -0), false); 19 | eq(R.identical(NaN, NaN), true); 20 | 21 | eq(R.identical(NaN, 42), false); 22 | eq(R.identical(42, NaN), false); 23 | 24 | eq(R.identical(0, new Number(0)), false); 25 | eq(R.identical(new Number(0), 0), false); 26 | eq(R.identical(new Number(0), new Number(0)), false); 27 | }); 28 | 29 | }); 30 | -------------------------------------------------------------------------------- /test/identity.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('identity', function() { 6 | it('returns its first argument', function() { 7 | eq(R.identity(undefined), undefined); 8 | eq(R.identity('foo'), 'foo'); 9 | eq(R.identity('foo', 'bar'), 'foo'); 10 | }); 11 | 12 | it('has length 1', function() { 13 | eq(R.identity.length, 1); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/inc.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('inc', function() { 6 | 7 | it('increments its argument', function() { 8 | eq(R.inc(-1), 0); 9 | eq(R.inc(0), 1); 10 | eq(R.inc(1), 2); 11 | eq(R.inc(12.34), 13.34); 12 | eq(R.inc(-Infinity), -Infinity); 13 | eq(R.inc(Infinity), Infinity); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/init.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | 3 | var R = require('../source'); 4 | var eq = require('./shared/eq'); 5 | 6 | 7 | describe('init', function() { 8 | 9 | it('returns all but the last element of an ordered collection', function() { 10 | eq(R.init([1, 2, 3]), [1, 2]); 11 | eq(R.init([2, 3]), [2]); 12 | eq(R.init([3]), []); 13 | eq(R.init([]), []); 14 | 15 | eq(R.init('abc'), 'ab'); 16 | eq(R.init('bc'), 'b'); 17 | eq(R.init('c'), ''); 18 | eq(R.init(''), ''); 19 | }); 20 | 21 | it('throws if applied to null or undefined', function() { 22 | assert.throws(function() { R.init(null); }, TypeError); 23 | assert.throws(function() { R.init(undefined); }, TypeError); 24 | }); 25 | 26 | it('handles array-like object', function() { 27 | var args = (function() { return arguments; }(1, 2, 3, 4, 5)); 28 | eq(R.init(args), [1, 2, 3, 4]); 29 | }); 30 | 31 | }); 32 | -------------------------------------------------------------------------------- /test/innerJoin.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | var a = {id: 1, name: 'a'}; 6 | var b = {id: 2, name: 'b'}; 7 | var c = {id: 3, name: 'c'}; 8 | var f = R.innerJoin(function(r, id) { return r.id === id; }); 9 | 10 | 11 | describe('innerJoin', function() { 12 | 13 | it('only returns elements from the first list', function() { 14 | eq(f([a, b, c], []), []); 15 | eq(f([a, b, c], [1]), [a]); 16 | eq(f([a, b, c], [1, 2]), [a, b]); 17 | eq(f([a, b, c], [1, 2, 3]), [a, b, c]); 18 | eq(f([a, b, c], [1, 2, 3, 4]), [a, b, c]); 19 | }); 20 | 21 | it('does not remove duplicates', function() { 22 | eq(f([a, a, a], [1, 2, 3]), [a, a, a]); 23 | eq(f([a, b, c], [1, 1, 1]), [a]); 24 | }); 25 | 26 | }); 27 | -------------------------------------------------------------------------------- /test/insert.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('insert', function() { 6 | it('inserts an element into the given list', function() { 7 | var list = ['a', 'b', 'c', 'd', 'e']; 8 | eq(R.insert(2, 'x', list), ['a', 'b', 'x', 'c', 'd', 'e']); 9 | }); 10 | 11 | it('inserts another list as an element', function() { 12 | var list = ['a', 'b', 'c', 'd', 'e']; 13 | eq(R.insert(2, ['s', 't'], list), ['a', 'b', ['s', 't'], 'c', 'd', 'e']); 14 | }); 15 | 16 | it('appends to the end of the list if the index is too large', function() { 17 | var list = ['a', 'b', 'c', 'd', 'e']; 18 | eq(R.insert(8, 'z', list), ['a', 'b', 'c', 'd', 'e', 'z']); 19 | }); 20 | 21 | }); 22 | -------------------------------------------------------------------------------- /test/insertAll.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('insertAll', function() { 6 | it('inserts a list of elements into the given list', function() { 7 | var list = ['a', 'b', 'c', 'd', 'e']; 8 | eq(R.insertAll(2, ['x', 'y', 'z'], list), ['a', 'b', 'x', 'y', 'z', 'c', 'd', 'e']); 9 | }); 10 | 11 | it('appends to the end of the list if the index is too large', function() { 12 | var list = ['a', 'b', 'c', 'd', 'e']; 13 | eq(R.insertAll(8, ['p', 'q', 'r'], list), ['a', 'b', 'c', 'd', 'e', 'p', 'q', 'r']); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/internal/_curry2.js: -------------------------------------------------------------------------------- 1 | var eq = require('../shared/eq'); 2 | var _ = require('../../source/__'); 3 | var _curry2 = require('../../source/internal/_curry2'); 4 | 5 | 6 | describe('_curry2', function() { 7 | it('supports R.__ placeholder', function() { 8 | var f = function(a, b) { return [a, b]; }; 9 | var g = _curry2(f); 10 | 11 | eq(g(1)(2), [1, 2]); 12 | eq(g(1, 2), [1, 2]); 13 | 14 | eq(g(_, 2)(1), [1, 2]); 15 | eq(g(1, _)(2), [1, 2]); 16 | 17 | eq(g(_, _)(1)(2), [1, 2]); 18 | eq(g(_, _)(1, 2), [1, 2]); 19 | eq(g(_, _)(_)(1, 2), [1, 2]); 20 | eq(g(_, _)(_, 2)(1), [1, 2]); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /test/intersperse.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('intersperse', function() { 6 | it('interposes a separator between list items', function() { 7 | eq(R.intersperse('n', ['ba', 'a', 'a']), ['ba', 'n', 'a', 'n', 'a']); 8 | eq(R.intersperse('bar', ['foo']), ['foo']); 9 | eq(R.intersperse('bar', []), []); 10 | }); 11 | 12 | it('dispatches', function() { 13 | var obj = {intersperse: function(x) { return 'override ' + x; }}; 14 | eq(R.intersperse('x', obj), 'override x'); 15 | }); 16 | 17 | }); 18 | -------------------------------------------------------------------------------- /test/isNil.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | describe('isNil', function() { 5 | it('tests a value for `null` or `undefined`', function() { 6 | eq(R.isNil(void 0), true); 7 | eq(R.isNil(null), true); 8 | eq(R.isNil([]), false); 9 | eq(R.isNil({}), false); 10 | eq(R.isNil(0), false); 11 | eq(R.isNil(''), false); 12 | }); 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /test/join.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('join', function() { 6 | it("concatenates a list's elements to a string, with an separator string between elements", function() { 7 | var list = [1, 2, 3, 4]; 8 | eq(R.join('~', list), '1~2~3~4'); 9 | }); 10 | 11 | }); 12 | -------------------------------------------------------------------------------- /test/keysIn.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('keysIn', function() { 6 | var obj = {a: 100, b: [1, 2, 3], c: {x: 200, y: 300}, d: 'D', e: null, f: undefined}; 7 | function C() { this.a = 100; this.b = 200; } 8 | C.prototype.x = function() { return 'x'; }; 9 | C.prototype.y = 'y'; 10 | var cobj = new C(); 11 | 12 | it("returns an array of the given object's keys", function() { 13 | eq(R.keysIn(obj).sort(), ['a', 'b', 'c', 'd', 'e', 'f']); 14 | }); 15 | 16 | it("includes the given object's prototype properties", function() { 17 | eq(R.keysIn(cobj).sort(), ['a', 'b', 'x', 'y']); 18 | }); 19 | 20 | it('works for primitives', function() { 21 | var result = R.map(function(val) { 22 | return R.keys(val); 23 | }, [null, undefined, 55, '', true, false, NaN, Infinity, , []]); 24 | eq(result, R.repeat([], 10)); 25 | }); 26 | 27 | }); 28 | -------------------------------------------------------------------------------- /test/last.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | 3 | var R = require('../source'); 4 | var eq = require('./shared/eq'); 5 | 6 | 7 | describe('last', function() { 8 | 9 | it('returns the last element of an ordered collection', function() { 10 | eq(R.last([1, 2, 3]), 3); 11 | eq(R.last([1, 2]), 2); 12 | eq(R.last([1]), 1); 13 | eq(R.last([]), undefined); 14 | 15 | eq(R.last('abc'), 'c'); 16 | eq(R.last('ab'), 'b'); 17 | eq(R.last('a'), 'a'); 18 | eq(R.last(''), ''); 19 | }); 20 | 21 | it('throws if applied to null or undefined', function() { 22 | assert.throws(function() { R.last(null); }, TypeError); 23 | assert.throws(function() { R.last(undefined); }, TypeError); 24 | }); 25 | 26 | }); 27 | -------------------------------------------------------------------------------- /test/lt.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('lt', function() { 6 | it('reports whether one item is less than another', function() { 7 | eq(R.lt(3, 5), true); 8 | eq(R.lt(6, 4), false); 9 | eq(R.lt(7.0, 7.0), false); 10 | eq(R.lt('abc', 'xyz'), true); 11 | eq(R.lt('abcd', 'abc'), false); 12 | }); 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /test/lte.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('lte', function() { 6 | it('reports whether one item is less than or equal to another', function() { 7 | eq(R.lte(3, 5), true); 8 | eq(R.lte(6, 4), false); 9 | eq(R.lte(7.0, 7.0), true); 10 | eq(R.lte('abc', 'xyz'), true); 11 | eq(R.lte('abcd', 'abc'), false); 12 | }); 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /test/mapAccum.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('mapAccum', function() { 6 | var add = function(a, b) {return [a + b, a + b];}; 7 | var mult = function(a, b) {return [a * b, a * b];}; 8 | var concat = function(a, b) {return [a.concat(b), a.concat(b)];}; 9 | 10 | it('map and accumulate simple functions over arrays with the supplied accumulator', function() { 11 | eq(R.mapAccum(add, 0, [1, 2, 3, 4]), [10, [1, 3, 6, 10]]); 12 | eq(R.mapAccum(mult, 1, [1, 2, 3, 4]), [24, [1, 2, 6, 24]]); 13 | }); 14 | 15 | it('returns the list and accumulator for an empty array', function() { 16 | eq(R.mapAccum(add, 0, []), [0, []]); 17 | eq(R.mapAccum(mult, 1, []), [1, []]); 18 | eq(R.mapAccum(concat, [], []), [[], []]); 19 | }); 20 | 21 | }); 22 | -------------------------------------------------------------------------------- /test/mapAccumRight.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('mapAccumRight', function() { 6 | var add = function(a, b) {return [a + b, a + b];}; 7 | var mult = function(a, b) {return [a * b, a * b];}; 8 | 9 | it('map and accumulate simple functions over arrays with the supplied accumulator', function() { 10 | eq(R.mapAccumRight(add, 0, [1, 2, 3, 4]), [10, [10, 9, 7, 4]]); 11 | eq(R.mapAccumRight(mult, 1, [1, 2, 3, 4]), [24, [24, 24, 12, 4]]); 12 | }); 13 | 14 | it('returns the list and accumulator for an empty array', function() { 15 | eq(R.mapAccumRight(add, 0, []), [0, []]); 16 | eq(R.mapAccumRight(mult, 1, []), [1, []]); 17 | eq(R.mapAccumRight(R.concat, [], []), [[], []]); 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /test/match.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | 3 | var R = require('../source'); 4 | var eq = require('./shared/eq'); 5 | 6 | 7 | describe('match', function() { 8 | var re = /[A-Z]\d\d\-[a-zA-Z]+/; 9 | var matching = 'B17-afn'; 10 | var notMatching = 'B1-afn'; 11 | 12 | it('determines whether a string matches a regex', function() { 13 | eq(R.match(re, matching).length, 1); 14 | eq(R.match(re, notMatching), []); 15 | }); 16 | 17 | it('defaults to a different empty array each time', function() { 18 | var first = R.match(re, notMatching); 19 | var second = R.match(re, notMatching); 20 | assert.notStrictEqual(first, second); 21 | }); 22 | 23 | it('throws on null input', function() { 24 | assert.throws(function shouldThrow() { R.match(re, null); }, TypeError); 25 | }); 26 | 27 | }); 28 | -------------------------------------------------------------------------------- /test/mathMod.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | 3 | var R = require('../source'); 4 | var eq = require('./shared/eq'); 5 | 6 | 7 | describe('mathMod', function() { 8 | it('requires integer arguments', function() { 9 | assert(Number.isNaN(R.mathMod('s', 3))); 10 | assert(Number.isNaN(R.mathMod(3, 's'))); 11 | assert(Number.isNaN(R.mathMod(12.2, 3))); 12 | assert(Number.isNaN(R.mathMod(3, 12.2))); 13 | }); 14 | 15 | it('behaves differently than JS modulo', function() { 16 | assert.notStrictEqual(R.mathMod(-17, 5), -17 % 5); 17 | assert.notStrictEqual(R.mathMod(17.2, 5), 17.2 % 5); 18 | assert.notStrictEqual(R.mathMod(17, -5), 17 % -5); 19 | }); 20 | 21 | it('computes the true modulo function', function() { 22 | eq(R.mathMod(-17, 5), 3); 23 | eq(R.identical(NaN, R.mathMod(17, -5)), true); 24 | eq(R.identical(NaN, R.mathMod(17, 0)), true); 25 | eq(R.identical(NaN, R.mathMod(17.2, 5)), true); 26 | eq(R.identical(NaN, R.mathMod(17, 5.5)), true); 27 | }); 28 | 29 | }); 30 | -------------------------------------------------------------------------------- /test/max.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('max', function() { 6 | 7 | it('returns the larger of its two arguments', function() { 8 | eq(R.max(-7, 7), 7); 9 | eq(R.max(7, -7), 7); 10 | }); 11 | 12 | it('works for any orderable type', function() { 13 | var d1 = new Date('2001-01-01'); 14 | var d2 = new Date('2002-02-02'); 15 | 16 | eq(R.max(d1, d2), d2); 17 | eq(R.max(d2, d1), d2); 18 | eq(R.max('a', 'b'), 'b'); 19 | eq(R.max('b', 'a'), 'b'); 20 | }); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /test/maxBy.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('maxBy', function() { 6 | 7 | it('returns the larger value as determined by the function', function() { 8 | eq(R.maxBy(function(n) { return n * n; }, -3, 2), -3); 9 | eq(R.maxBy(R.prop('x'), {x: 3, y: 1}, {x: 5, y: 10}), {x: 5, y: 10}); 10 | }); 11 | 12 | }); 13 | -------------------------------------------------------------------------------- /test/mean.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('mean', function() { 6 | 7 | it('returns mean of a nonempty list', function() { 8 | eq(R.mean([2]), 2); 9 | eq(R.mean([2, 7]), 4.5); 10 | eq(R.mean([2, 7, 9]), 6); 11 | eq(R.mean([2, 7, 9, 10]), 7); 12 | }); 13 | 14 | it('returns NaN for an empty list', function() { 15 | eq(R.identical(NaN, R.mean([])), true); 16 | }); 17 | 18 | it('handles array-like object', function() { 19 | eq(R.mean((function() { return arguments; })(1, 2, 3)), 2); 20 | }); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /test/median.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('median', function() { 6 | 7 | it('returns middle value of an odd-length list', function() { 8 | eq(R.median([2]), 2); 9 | eq(R.median([2, 9, 7]), 7); 10 | }); 11 | 12 | it('returns mean of two middle values of a nonempty even-length list', function() { 13 | eq(R.median([7, 2]), 4.5); 14 | eq(R.median([7, 2, 10, 9]), 8); 15 | }); 16 | 17 | it('returns NaN for an empty list', function() { 18 | eq(R.identical(NaN, R.median([])), true); 19 | }); 20 | 21 | it('handles array-like object', function() { 22 | eq(R.median((function() { return arguments; })(1, 2, 3)), 2); 23 | }); 24 | 25 | }); 26 | -------------------------------------------------------------------------------- /test/mergeAll.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('mergeAll', function() { 6 | it('merges a list of objects together into one object', function() { 7 | eq(R.mergeAll([{foo:1}, {bar:2}, {baz:3}]), {foo:1, bar:2, baz:3}); 8 | }); 9 | 10 | it('gives precedence to later objects in the list', function() { 11 | eq(R.mergeAll([{foo:1}, {foo:2}, {bar:2}]), {foo:2, bar:2}); 12 | }); 13 | 14 | it('ignores inherited properties', function() { 15 | function Foo() {} 16 | Foo.prototype.bar = 42; 17 | var foo = new Foo(); 18 | var res = R.mergeAll([foo, {fizz: 'buzz'}]); 19 | eq(res, {fizz: 'buzz'}); 20 | }); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /test/min.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('min', function() { 6 | 7 | it('returns the smaller of its two arguments', function() { 8 | eq(R.min(-7, 7), -7); 9 | eq(R.min(7, -7), -7); 10 | }); 11 | 12 | it('works for any orderable type', function() { 13 | var d1 = new Date('2001-01-01'); 14 | var d2 = new Date('2002-02-02'); 15 | 16 | eq(R.min(d1, d2), d1); 17 | eq(R.min(d2, d1), d1); 18 | eq(R.min('a', 'b'), 'a'); 19 | eq(R.min('b', 'a'), 'a'); 20 | }); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /test/minBy.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('minBy', function() { 6 | 7 | it('returns the smaller value as determined by the function', function() { 8 | eq(R.minBy(function(n) { return n * n; }, -3, 2), 2); 9 | eq(R.minBy(R.prop('x'), {x: 3, y: 1}, {x: 5, y: 10}), {x: 3, y: 1}); 10 | }); 11 | 12 | }); 13 | -------------------------------------------------------------------------------- /test/modulo.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('modulo', function() { 6 | it('divides the first param by the second and returns the remainder', function() { 7 | eq(R.modulo(100, 2), 0); 8 | eq(R.modulo(100, 3), 1); 9 | eq(R.modulo(100, 17), 15); 10 | }); 11 | 12 | it('preserves javascript-style modulo evaluation for negative numbers', function() { 13 | eq(R.modulo(-5, 4), -1); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/multiply.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('multiply', function() { 6 | it('multiplies together two numbers', function() { 7 | eq(R.multiply(6, 7), 42); 8 | }); 9 | 10 | }); 11 | -------------------------------------------------------------------------------- /test/negate.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('negate', function() { 6 | 7 | it('negates its argument', function() { 8 | eq(R.negate(-Infinity), Infinity); 9 | eq(R.negate(-1), 1); 10 | eq(R.negate(-0), 0); 11 | eq(R.negate(0), -0); 12 | eq(R.negate(1), -1); 13 | eq(R.negate(Infinity), -Infinity); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/not.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('not', function() { 6 | it('reverses argument', function() { 7 | eq(R.not(false), true); 8 | eq(R.not(1), false); 9 | eq(R.not(''), true); 10 | }); 11 | 12 | }); 13 | -------------------------------------------------------------------------------- /test/objOf.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('objOf', function() { 6 | 7 | it('creates an object containing a single key:value pair', function() { 8 | eq(R.objOf('foo', 42), {foo: 42}); 9 | eq(R.objOf('foo')(42), {foo: 42}); 10 | }); 11 | 12 | }); 13 | -------------------------------------------------------------------------------- /test/of.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('of', function() { 6 | it('returns its argument as an Array', function() { 7 | eq(R.of(100), [100]); 8 | eq(R.of([100]), [[100]]); 9 | eq(R.of(null), [null]); 10 | eq(R.of(undefined), [undefined]); 11 | eq(R.of([]), [[]]); 12 | }); 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /test/omit.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('omit', function() { 6 | var obj = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}; 7 | 8 | it('copies an object omitting the listed properties', function() { 9 | eq(R.omit(['a', 'c', 'f'], obj), {b: 2, d: 4, e: 5}); 10 | }); 11 | 12 | it('includes prototype properties', function() { 13 | var F = function(param) {this.x = param;}; 14 | F.prototype.y = 40; F.prototype.z = 50; 15 | var obj = new F(30); 16 | obj.v = 10; obj.w = 20; 17 | eq(R.omit(['w', 'x', 'y'], obj), {v: 10, z: 50}); 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /test/or.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('or', function() { 6 | it('compares two values with js ||', function() { 7 | eq(R.or(true, true), true); 8 | eq(R.or(true, false), true); 9 | eq(R.or(false, true), true); 10 | eq(R.or(false, false), false); 11 | }); 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /test/pair.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('pair', function() { 6 | 7 | it('creates a two-element array', function() { 8 | eq(R.pair('foo', 'bar'), ['foo', 'bar']); 9 | eq(R.pair('foo')('bar'), ['foo', 'bar']); 10 | }); 11 | 12 | }); 13 | -------------------------------------------------------------------------------- /test/partial.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('partial', function() { 6 | var disc = function(a, b, c) { // note disc(3, 7, 4) => 1 7 | return b * b - 4 * a * c; 8 | }; 9 | 10 | it('caches the initially supplied arguments', function() { 11 | var f = R.partial(disc, [3]); 12 | eq(f(7, 4), 1); 13 | var g = R.partial(disc, [3, 7]); 14 | eq(g(4), 1); 15 | }); 16 | 17 | it('correctly reports the arity of the new function', function() { 18 | var f = R.partial(disc, [3]); 19 | eq(f.length, 2); 20 | var g = R.partial(disc, [3, 7]); 21 | eq(g.length, 1); 22 | }); 23 | 24 | }); 25 | -------------------------------------------------------------------------------- /test/partialRight.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('partialRight', function() { 6 | var disc = function(a, b, c) { // note disc(3, 7, 4) => 1 7 | return b * b - 4 * a * c; 8 | }; 9 | 10 | it('caches the initially supplied arguments', function() { 11 | var f = R.partialRight(disc, [4]); 12 | eq(f(3, 7), 1); 13 | var g = R.partialRight(disc, [7, 4]); 14 | eq(g(3), 1); 15 | }); 16 | 17 | it('correctly reports the arity of the new function', function() { 18 | var f = R.partialRight(disc, [4]); 19 | eq(f.length, 2); 20 | var g = R.partialRight(disc, [7, 4]); 21 | eq(g.length, 1); 22 | }); 23 | 24 | }); 25 | -------------------------------------------------------------------------------- /test/pathSatisfies.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('pathSatisfies', function() { 6 | 7 | var isPositive = function(n) { return n > 0; }; 8 | 9 | it('returns true if the specified object path satisfies the given predicate', function() { 10 | eq(R.pathSatisfies(isPositive, ['x', 1, 'y'], {x: [{y: -1}, {y: 1}]}), true); 11 | }); 12 | 13 | it('returns false if the specified path does not exist', function() { 14 | eq(R.pathSatisfies(isPositive, ['x', 'y'], {x: {z: 42}}), false); 15 | }); 16 | 17 | it('returns false if the path is empty', function() { 18 | eq(R.pathSatisfies(isPositive, [], {x: {z: 42}}), false); 19 | }); 20 | 21 | it('returns false otherwise', function() { 22 | eq(R.pathSatisfies(isPositive, ['x', 'y'], {x: {y: 0}}), false); 23 | }); 24 | 25 | }); 26 | -------------------------------------------------------------------------------- /test/pick.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('pick', function() { 6 | var obj = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, 1: 7}; 7 | 8 | it('copies the named properties of an object to the new object', function() { 9 | eq(R.pick(['a', 'c', 'f'], obj), {a: 1, c: 3, f: 6}); 10 | }); 11 | 12 | it('handles numbers as properties', function() { 13 | eq(R.pick([1], obj), {1: 7}); 14 | }); 15 | 16 | it('ignores properties not included', function() { 17 | eq(R.pick(['a', 'c', 'g'], obj), {a: 1, c: 3}); 18 | }); 19 | 20 | it('retrieves prototype properties', function() { 21 | var F = function(param) {this.x = param;}; 22 | F.prototype.y = 40; F.prototype.z = 50; 23 | var obj = new F(30); 24 | obj.v = 10; obj.w = 20; 25 | eq(R.pick(['w', 'x', 'y'], obj), {w: 20, x: 30, y: 40}); 26 | }); 27 | 28 | }); 29 | -------------------------------------------------------------------------------- /test/pickAll.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('pickAll', function() { 6 | var obj = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}; 7 | it('copies the named properties of an object to the new object', function() { 8 | eq(R.pickAll(['a', 'c', 'f'], obj), {a: 1, c: 3, f: 6}); 9 | }); 10 | 11 | it('includes properties not present on the input object', function() { 12 | eq(R.pickAll(['a', 'c', 'g'], obj), {a: 1, c: 3, g: undefined}); 13 | }); 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /test/pluck.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('pluck', function() { 6 | var people = [ 7 | {name: 'Fred', age: 23}, 8 | {name: 'Wilma', age: 21}, 9 | {name: 'Pebbles', age: 2} 10 | ]; 11 | 12 | it('returns a function that maps the appropriate property over an array', function() { 13 | var nm = R.pluck('name'); 14 | eq(typeof nm, 'function'); 15 | eq(nm(people), ['Fred', 'Wilma', 'Pebbles']); 16 | }); 17 | 18 | it('behaves as a transducer when given a transducer in list position', function() { 19 | var numbers = [{a: 1}, {a: 2}, {a: 3}, {a: 4}]; 20 | var transducer = R.compose(R.pluck('a'), R.map(R.add(1)), R.take(2)); 21 | eq(R.transduce(transducer, R.flip(R.append), [], numbers), [2, 3]); 22 | }); 23 | 24 | }); 25 | -------------------------------------------------------------------------------- /test/prepend.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('prepend', function() { 6 | it('adds the element to the beginning of the list', function() { 7 | eq(R.prepend('x', ['y', 'z']), ['x', 'y', 'z']); 8 | eq(R.prepend(['a', 'z'], ['x', 'y']), [['a', 'z'], 'x', 'y']); 9 | }); 10 | 11 | it('works on empty list', function() { 12 | eq(R.prepend(1, []), [1]); 13 | }); 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /test/product.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('product', function() { 6 | it('multiplies together the array of numbers supplied', function() { 7 | eq(R.product([1, 2, 3, 4]), 24); 8 | }); 9 | 10 | }); 11 | -------------------------------------------------------------------------------- /test/prop.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('prop', function() { 6 | var fred = {name: 'Fred', age: 23}; 7 | 8 | it('returns a function that fetches the appropriate property', function() { 9 | var nm = R.prop('name'); 10 | eq(typeof nm, 'function'); 11 | eq(nm(fred), 'Fred'); 12 | }); 13 | 14 | it('shows the same behaviour as path for an undefined object', function() { 15 | var propResult, propException, pathResult, pathException; 16 | try { 17 | propResult = R.prop('name', undefined); 18 | } catch (e) { 19 | propException = e; 20 | } 21 | 22 | try { 23 | pathResult = R.path(['name'], undefined); 24 | } catch (e) { 25 | pathException = e; 26 | } 27 | 28 | eq(propResult, pathResult); 29 | eq(propException, pathException); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /test/propEq.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('propEq', function() { 6 | var obj1 = {name: 'Abby', age: 7, hair: 'blond'}; 7 | var obj2 = {name: 'Fred', age: 12, hair: 'brown'}; 8 | 9 | it('determines whether a particular property matches a given value for a specific object', function() { 10 | eq(R.propEq('name', 'Abby', obj1), true); 11 | eq(R.propEq('hair', 'brown', obj2), true); 12 | eq(R.propEq('hair', 'blond', obj2), false); 13 | }); 14 | 15 | it('has R.equals semantics', function() { 16 | function Just(x) { this.value = x; } 17 | Just.prototype.equals = function(x) { 18 | return x instanceof Just && R.equals(x.value, this.value); 19 | }; 20 | 21 | eq(R.propEq('value', 0, {value: -0}), false); 22 | eq(R.propEq('value', -0, {value: 0}), false); 23 | eq(R.propEq('value', NaN, {value: NaN}), true); 24 | eq(R.propEq('value', new Just([42]), {value: new Just([42])}), true); 25 | }); 26 | 27 | }); 28 | -------------------------------------------------------------------------------- /test/propIs.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('propIs', function() { 6 | 7 | it('returns true if the specified object property is of the given type', function() { 8 | eq(R.propIs(Number, 'value', {value: 1}), true); 9 | }); 10 | 11 | it('returns false otherwise', function() { 12 | eq(R.propIs(String, 'value', {value: 1}), false); 13 | eq(R.propIs(String, 'value', {}), false); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/propOr.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('propOr', function() { 6 | var fred = {name: 'Fred', age: 23}; 7 | var anon = {age: 99}; 8 | 9 | var nm = R.propOr('Unknown', 'name'); 10 | 11 | it('returns a function that fetches the appropriate property', function() { 12 | eq(typeof nm, 'function'); 13 | eq(nm(fred), 'Fred'); 14 | }); 15 | 16 | it('returns the default value when the property does not exist', function() { 17 | eq(nm(anon), 'Unknown'); 18 | }); 19 | 20 | it('returns the default value when the object is nil', function() { 21 | eq(nm(null), 'Unknown'); 22 | eq(nm(void 0), 'Unknown'); 23 | }); 24 | 25 | it('uses the default when supplied an object with a nil value', function() { 26 | eq(R.propOr('foo', 'x', {x: null}), 'foo'); 27 | eq(R.propOr('foo', 'x', {x: undefined}), 'foo'); 28 | }); 29 | 30 | }); 31 | -------------------------------------------------------------------------------- /test/propSatisfies.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('propSatisfies', function() { 6 | 7 | var isPositive = function(n) { return n > 0; }; 8 | 9 | it('returns true if the specified object property satisfies the given predicate', function() { 10 | eq(R.propSatisfies(isPositive, 'x', {x: 1, y: 0}), true); 11 | }); 12 | 13 | it('returns false otherwise', function() { 14 | eq(R.propSatisfies(isPositive, 'y', {x: 1, y: 0}), false); 15 | }); 16 | 17 | }); 18 | -------------------------------------------------------------------------------- /test/props.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('props', function() { 6 | var obj = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}; 7 | 8 | it('returns empty array if no properties requested', function() { 9 | eq(R.props([], obj), []); 10 | }); 11 | 12 | it('returns values for requested properties', function() { 13 | eq(R.props(['a', 'e'], obj), [1, 5]); 14 | }); 15 | 16 | it('preserves order', function() { 17 | eq(R.props(['f', 'c', 'e'], obj), [6, 3, 5]); 18 | }); 19 | 20 | it('returns undefined for nonexistent properties', function() { 21 | var ps = R.props(['a', 'nonexistent'], obj); 22 | eq(ps.length, 2); 23 | eq(ps[0], 1); 24 | eq(ps[1], void 0); 25 | }); 26 | 27 | }); 28 | -------------------------------------------------------------------------------- /test/range.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | 3 | var R = require('../source'); 4 | var eq = require('./shared/eq'); 5 | 6 | 7 | describe('range', function() { 8 | 9 | it('returns list of numbers', function() { 10 | eq(R.range(0, 5), [0, 1, 2, 3, 4]); 11 | eq(R.range(4, 7), [4, 5, 6]); 12 | }); 13 | 14 | it('returns the empty list if the first parameter is not larger than the second', function() { 15 | eq(R.range(7, 3), []); 16 | eq(R.range(5, 5), []); 17 | }); 18 | 19 | it('returns an empty array if from > to', function() { 20 | var result = R.range(10, 5); 21 | eq(result, []); 22 | result.push(5); 23 | eq(R.range(10, 5), []); 24 | }); 25 | 26 | it('terminates given bad input', function() { 27 | assert.throws( 28 | function() { R.range('a', 'z'); }, 29 | function(err) { 30 | return err.constructor === TypeError && 31 | err.message === 'Both arguments to range must be numbers'; 32 | } 33 | ); 34 | }); 35 | 36 | }); 37 | -------------------------------------------------------------------------------- /test/reduceRight.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('reduceRight', function() { 6 | var avg = function(a, b) {return (a + b) / 2;}; 7 | 8 | it('folds lists in the right order', function() { 9 | eq(R.reduceRight(function(a, b) {return a + b;}, '', ['a', 'b', 'c', 'd']), 'abcd'); 10 | }); 11 | 12 | it('folds subtract over arrays in the right order', function() { 13 | eq(R.reduceRight(function(a, b) {return a - b;}, 0, [1, 2, 3, 4]), -2); 14 | }); 15 | 16 | it('folds simple functions over arrays with the supplied accumulator', function() { 17 | eq(R.reduceRight(avg, 54, [12, 4, 10, 6]), 12); 18 | }); 19 | 20 | it('returns the accumulator for an empty array', function() { 21 | eq(R.reduceRight(avg, 0, []), 0); 22 | }); 23 | 24 | }); 25 | -------------------------------------------------------------------------------- /test/reduceWhile.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | var isOdd = function(_, x) {return x % 2 === 1; }; 5 | 6 | describe('reduceWhile', function() { 7 | it('reduces until its predicate fails', function() { 8 | eq(R.reduceWhile(isOdd, R.add, 0, [1, 3, 1, 5, 20, 7, 7, 7]), 10); 9 | }); 10 | 11 | it('returns its accumulator when given an empty array', function() { 12 | eq(R.reduceWhile(isOdd, R.add, 101, []), 101); 13 | }); 14 | 15 | it('short circuits with reduced', function() { 16 | var appendWhileLessThan10 = function(acc, val) {return val > 10 ? R.reduced(acc) : R.append(val, acc);}; 17 | eq(R.reduceWhile(isOdd, appendWhileLessThan10, [], [1, 3, 1, 5, 20, 7]), [1, 3, 1, 5]); 18 | eq(R.reduceWhile(isOdd, appendWhileLessThan10, [], [1, 3, 2, 5, 20, 7]), [1, 3]); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /test/reduced.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('reduced', function() { 6 | it('wraps a value', function() { 7 | // white box test. 8 | var v = {}; 9 | eq(R.reduced(v)['@@transducer/value'], v); 10 | }); 11 | 12 | it('flags value as reduced', function() { 13 | // white box test. 14 | eq(R.reduced({})['@@transducer/reduced'], true); 15 | }); 16 | 17 | it('short-circuits reduce', function() { 18 | // black box test. 19 | eq( 20 | R.reduce( 21 | function(acc, v) { 22 | var result = acc + v; 23 | if (result >= 10) {result = R.reduced(result);} 24 | return result; 25 | }, 26 | 0, 27 | [1, 2, 3, 4, 5]), 28 | 10); 29 | }); 30 | 31 | }); 32 | -------------------------------------------------------------------------------- /test/repeat.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('repeat', function() { 6 | it('returns a lazy list of identical values', function() { 7 | eq(R.repeat(0, 5), [0, 0, 0, 0, 0]); 8 | }); 9 | 10 | it('can accept any value, including `null`', function() { 11 | eq(R.repeat(null, 3), [null, null, null]); 12 | }); 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /test/replace.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('replace', function() { 6 | 7 | it('replaces substrings of the input string', function() { 8 | eq(R.replace('1', 'one', '1 two three'), 'one two three'); 9 | }); 10 | 11 | it('replaces regex matches of the input string', function() { 12 | eq(R.replace(/\d+/g, 'num', '1 2 three'), 'num num three'); 13 | }); 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /test/reverse.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('reverse', function() { 6 | 7 | it('reverses arrays', function() { 8 | eq(R.reverse([]), []); 9 | eq(R.reverse([1]), [1]); 10 | eq(R.reverse([1, 2]), [2, 1]); 11 | eq(R.reverse([1, 2, 3]), [3, 2, 1]); 12 | }); 13 | 14 | it('reverses strings', function() { 15 | eq(R.reverse(''), ''); 16 | eq(R.reverse('a'), 'a'); 17 | eq(R.reverse('ab'), 'ba'); 18 | eq(R.reverse('abc'), 'cba'); 19 | }); 20 | 21 | }); 22 | -------------------------------------------------------------------------------- /test/scan.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('scan', function() { 6 | var add = function(a, b) {return a + b;}; 7 | var mult = function(a, b) {return a * b;}; 8 | 9 | it('scans simple functions over arrays with the supplied accumulator', function() { 10 | eq(R.scan(add, 0, [1, 2, 3, 4]), [0, 1, 3, 6, 10]); 11 | eq(R.scan(mult, 1, [1, 2, 3, 4]), [1, 1, 2, 6, 24]); 12 | }); 13 | 14 | it('returns the accumulator for an empty array', function() { 15 | eq(R.scan(add, 0, []), [0]); 16 | eq(R.scan(mult, 1, []), [1]); 17 | }); 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /test/shared/Id.js: -------------------------------------------------------------------------------- 1 | var R = require('../../source'); 2 | 3 | 4 | // Id :: a -> Id a 5 | module.exports = function Id(value) { 6 | return { 7 | '@@type': 'ramda/Id', 8 | 'fantasy-land/equals': function(other) { return other != null && other['@@type'] === this['@@type'] && R.equals(other.value, value); }, 9 | 'fantasy-land/concat': function(id) { return Id(R.concat(value, id.value)); }, 10 | 'fantasy-land/map': function(f) { return Id(f(value)); }, 11 | 'fantasy-land/ap': function(id) { return Id(id.value(value)); }, 12 | 'fantasy-land/chain': function(f) { return f(value); }, 13 | 'fantasy-land/reduce': function(f, x) { return f(x, value); }, 14 | 'fantasy-land/traverse': function(f, of) { return R.map(Id, f(value)); }, 15 | sequence: function(of) { return R.map(Id, this.value); }, 16 | constructor: {'fantasy-land/of': Id}, 17 | toString: function() { return 'Id(' + R.toString(value) + ')'; }, 18 | value: value 19 | }; 20 | }; 21 | -------------------------------------------------------------------------------- /test/shared/eq.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | 3 | var R = require('../../source'); 4 | 5 | 6 | module.exports = function(actual, expected) { 7 | assert.strictEqual(arguments.length, 2); 8 | assert.strictEqual(R.toString(actual), R.toString(expected)); 9 | }; 10 | -------------------------------------------------------------------------------- /test/sort.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('sort', function() { 6 | it('sorts the elements of a list', function() { 7 | eq(R.sort(function(a, b) {return a - b;}, [3, 1, 8, 1, 2, 5]), [1, 1, 2, 3, 5, 8]); 8 | }); 9 | 10 | it('does not affect the list passed supplied', function() { 11 | var list = [3, 1, 8, 1, 2, 5]; 12 | eq(R.sort(function(a, b) {return a - b;}, list), [1, 1, 2, 3, 5, 8]); 13 | eq(list, [3, 1, 8, 1, 2, 5]); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/split.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('split', function() { 6 | it('splits a string into an array', function() { 7 | eq(R.split('.', 'a.b.c.xyz.d'), ['a', 'b', 'c', 'xyz', 'd']); 8 | }); 9 | 10 | it('the split string can be arbitrary', function() { 11 | eq(R.split('at', 'The Cat in the Hat sat on the mat'), ['The C', ' in the H', ' s', ' on the m', '']); 12 | }); 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /test/splitAt.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('splitAt', function() { 6 | it('splits an array at a given index', function() { 7 | eq(R.splitAt(1, [1, 2, 3]), [[1], [2, 3]]); 8 | }); 9 | 10 | it('splits a string at a given index', function() { 11 | eq(R.splitAt(5, 'hello world'), ['hello', ' world']); 12 | }); 13 | 14 | it('can handle index greater than array length', function() { 15 | eq(R.splitAt(4, [1, 2]), [[1, 2], []]); 16 | }); 17 | 18 | it('can support negative index', function() { 19 | eq(R.splitAt(-1, 'foobar'), ['fooba', 'r']); 20 | }); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /test/splitWhen.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('splitWhen', function() { 6 | it('splits an array at the first instance to satisfy the predicate', function() { 7 | eq(R.splitWhen(R.equals(2), [1, 2, 3]), [[1], [2, 3]]); 8 | }); 9 | 10 | it('retains all original elements', function() { 11 | eq(R.splitWhen(R.T, [1, 1, 1]), [[], [1, 1, 1]]); 12 | }); 13 | 14 | it('only splits once', function() { 15 | eq(R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]), [[1], [2, 3, 1, 2, 3]]); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /test/subtract.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('subtract', function() { 6 | it('subtracts two numbers', function() { 7 | eq(R.subtract(22, 7), 15); 8 | }); 9 | 10 | it('coerces its arguments to numbers', function() { 11 | eq(R.subtract('1', '2'), -1); 12 | eq(R.subtract(1, '2'), -1); 13 | eq(R.subtract(true, false), 1); 14 | eq(R.subtract(null, null), 0); 15 | eq(R.subtract(undefined, undefined), NaN); 16 | eq(R.subtract(new Date(1), new Date(2)), -1); 17 | }); 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /test/sum.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('sum', function() { 6 | it('adds together the array of numbers supplied', function() { 7 | eq(R.sum([1, 2, 3, 4]), 10); 8 | }); 9 | 10 | it('does not save the state of the accumulator', function() { 11 | eq(R.sum([1, 2, 3, 4]), 10); 12 | eq(R.sum([1]), 1); 13 | eq(R.sum([5, 5, 5, 5, 5]), 25); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/tail.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | 3 | var R = require('../source'); 4 | var eq = require('./shared/eq'); 5 | 6 | 7 | describe('tail', function() { 8 | 9 | it('returns the tail of an ordered collection', function() { 10 | eq(R.tail([1, 2, 3]), [2, 3]); 11 | eq(R.tail([2, 3]), [3]); 12 | eq(R.tail([3]), []); 13 | eq(R.tail([]), []); 14 | 15 | eq(R.tail('abc'), 'bc'); 16 | eq(R.tail('bc'), 'c'); 17 | eq(R.tail('c'), ''); 18 | eq(R.tail(''), ''); 19 | }); 20 | 21 | it('throws if applied to null or undefined', function() { 22 | assert.throws(function() { R.tail(null); }, TypeError); 23 | assert.throws(function() { R.tail(undefined); }, TypeError); 24 | }); 25 | 26 | }); 27 | -------------------------------------------------------------------------------- /test/takeLastWhile.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | 3 | var R = require('../source'); 4 | var eq = require('./shared/eq'); 5 | 6 | 7 | describe('takeLastWhile', function() { 8 | it('continues taking elements while the function reports `true`', function() { 9 | eq(R.takeLastWhile(function(x) {return x !== 5;}, [1, 3, 5, 7, 9]), [7, 9]); 10 | }); 11 | 12 | it('starts at the right arg and acknowledges undefined', function() { 13 | eq(R.takeLastWhile(function() { assert(false); }, []), []); 14 | eq(R.takeLastWhile(function(x) {return x !== void 0;}, [1, 3, void 0, 5, 7]), [5, 7]); 15 | }); 16 | 17 | it('can operate on strings', function() { 18 | eq(R.takeLastWhile(function(x) { return x !== 'R'; }, 'Ramda'), 'amda'); 19 | }); 20 | 21 | }); 22 | -------------------------------------------------------------------------------- /test/takeWhile.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | 3 | var R = require('../source'); 4 | var eq = require('./shared/eq'); 5 | 6 | 7 | describe('takeWhile', function() { 8 | it('continues taking elements while the function reports `true`', function() { 9 | eq(R.takeWhile(function(x) {return x !== 5;}, [1, 3, 5, 7, 9]), [1, 3]); 10 | }); 11 | 12 | it('starts at the right arg and acknowledges undefined', function() { 13 | eq(R.takeWhile(function() { assert(false); }, []), []); 14 | eq(R.takeWhile(function(x) {return x !== void 0;}, [1, 3, void 0, 5, 7]), [1, 3]); 15 | }); 16 | 17 | it('can operate on strings', function() { 18 | eq(R.takeWhile(function(x) { return x !== 'd'; }, 'Ramda'), 'Ram'); 19 | }); 20 | 21 | }); 22 | -------------------------------------------------------------------------------- /test/thunkify.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | describe('thunkify', function() { 5 | it('returns a function with the same arity as the given function', function() { 6 | var input = function input(a0, a1) { }; 7 | var thunk = R.thunkify(input); 8 | eq(typeof thunk, 'function'); 9 | eq(thunk.length, input.length); 10 | }); 11 | 12 | it('returns a function that expects arguments and returns a new invoker function', function() { 13 | var input = function input(a0, a1) { }; 14 | var thunk = R.thunkify(input); 15 | eq(typeof thunk(42, 'xyz'), 'function'); 16 | }); 17 | 18 | it('calls the original function with the provided arguments when all were supplied', function() { 19 | var thunk = R.thunkify(R.add(2)); 20 | eq(thunk(40)(), 42); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /test/times.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | 3 | var R = require('../source'); 4 | var eq = require('./shared/eq'); 5 | 6 | 7 | describe('times', function() { 8 | it('takes a map func', function() { 9 | eq(R.times(R.identity, 5), [0, 1, 2, 3, 4]); 10 | eq(R.times(function(x) { 11 | return x * 2; 12 | }, 5), [0, 2, 4, 6, 8]); 13 | }); 14 | 15 | it('throws if second argument is not a valid array length', function() { 16 | assert.throws(function() { R.times(3)('cheers!'); }, RangeError); 17 | assert.throws(function() { R.times(R.identity, -1); }, RangeError); 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /test/toLower.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('toLower', function() { 6 | it('returns the lower-case equivalent of the input string', function() { 7 | eq(R.toLower('XYZ'), 'xyz'); 8 | }); 9 | 10 | }); 11 | -------------------------------------------------------------------------------- /test/toPairs.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('toPairs', function() { 6 | it('converts an object into an array of two-element [key, value] arrays', function() { 7 | eq(R.toPairs({a: 1, b: 2, c: 3}), [['a', 1], ['b', 2], ['c', 3]]); 8 | }); 9 | 10 | it("only iterates the object's own properties", function() { 11 | var F = function() { 12 | this.x = 1; 13 | this.y = 2; 14 | }; 15 | F.prototype.protoProp = 'you can\'t see me'; 16 | var f = new F(); 17 | eq(R.toPairs(f), [['x', 1], ['y', 2]]); 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /test/toPairsIn.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('toPairsIn', function() { 6 | it('converts an object into an array of two-element [key, value] arrays', function() { 7 | eq(R.toPairsIn({a: 1, b: 2, c: 3}), [['a', 1], ['b', 2], ['c', 3]]); 8 | }); 9 | 10 | it("iterates properties on the object's prototype chain", function() { 11 | function sortPairs(a, b) { 12 | return a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0; 13 | } 14 | var F = function() { 15 | this.x = 1; 16 | this.y = 2; 17 | }; 18 | F.prototype.protoProp = 'you can see me'; 19 | var f = new F(); 20 | eq(R.toPairsIn(f).sort(sortPairs), [['protoProp', 'you can see me'], ['x', 1], ['y', 2]]); 21 | }); 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /test/toUpper.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('toUpper', function() { 6 | it('returns the upper-case equivalent of the input string', function() { 7 | eq(R.toUpper('abc'), 'ABC'); 8 | }); 9 | 10 | }); 11 | -------------------------------------------------------------------------------- /test/transpose.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | describe('transpose', function() { 5 | it('returns an array of two arrays', function() { 6 | var input = [['a', 1], ['b', 2], ['c', 3]]; 7 | eq(R.transpose(input), [['a', 'b', 'c'], [1, 2, 3]]); 8 | }); 9 | it('skips elements when rows are shorter', function() { 10 | var actual = R.transpose([[10, 11], [20], [], [30, 31, 32]]); 11 | var expected = [[10, 20, 30], [11, 31], [32]]; 12 | eq(actual, expected); 13 | }); 14 | it('copes with empty arrays', function() { 15 | eq(R.transpose([]), []); 16 | }); 17 | it('copes with true, false, null & undefined elements of arrays', function() { 18 | var actual = R.transpose([[true, false, undefined, null], [null, undefined, false, true]]); 19 | var expected = [[true, null], [false, undefined], [undefined, false], [null, true]]; 20 | eq(actual, expected); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /test/unary.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('unary', function() { 6 | it('turns multiple-argument function into unary one', function() { 7 | R.unary(function(x, y, z) { 8 | eq(arguments.length, 1); 9 | eq(typeof y, 'undefined'); 10 | eq(typeof z, 'undefined'); 11 | })(10, 20, 30); 12 | }); 13 | 14 | it('initial argument is passed through normally', function() { 15 | R.unary(function(x, y, z) { 16 | eq(x, 10); 17 | void z; 18 | })(10, 20, 30); 19 | }); 20 | 21 | }); 22 | -------------------------------------------------------------------------------- /test/unfold.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('unfold', function() { 6 | it('unfolds simple functions with a starting point to create a list', function() { 7 | eq(R.unfold(function(n) {if (n > 0) {return [n, n - 1];}}, 10), [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]); 8 | }); 9 | 10 | it('is cool!', function() { 11 | var fib = function(n) { 12 | var count = 0; 13 | return function(pair) { 14 | count += 1; 15 | if (count <= n) { 16 | return [pair[0], [pair[1], pair[0] + pair[1]]]; 17 | } 18 | }; 19 | }; 20 | eq(R.unfold(fib(10), [0, 1]), [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]); 21 | }); 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /test/union.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('union', function() { 6 | var M = [1, 2, 3, 4]; 7 | var N = [3, 4, 5, 6]; 8 | it('combines two lists into the set of all their elements', function() { 9 | eq(R.union(M, N), [1, 2, 3, 4, 5, 6]); 10 | }); 11 | 12 | it('has R.equals semantics', function() { 13 | function Just(x) { this.value = x; } 14 | Just.prototype.equals = function(x) { 15 | return x instanceof Just && R.equals(x.value, this.value); 16 | }; 17 | 18 | eq(R.union([0], [-0]).length, 2); 19 | eq(R.union([-0], [0]).length, 2); 20 | eq(R.union([NaN], [NaN]).length, 1); 21 | eq(R.union([new Just([42])], [new Just([42])]).length, 1); 22 | }); 23 | 24 | }); 25 | -------------------------------------------------------------------------------- /test/unionWith.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('unionWith', function() { 6 | var Ro = [{a: 1}, {a: 2}, {a: 3}, {a: 4}]; 7 | var So = [{a: 3}, {a: 4}, {a: 5}, {a: 6}]; 8 | var eqA = function(r, s) { return r.a === s.a; }; 9 | it('combines two lists into the set of all their elements based on the passed-in equality predicate', function() { 10 | eq(R.unionWith(eqA, Ro, So), [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}, {a: 6}]); 11 | }); 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /test/uniqBy.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('uniqBy', function() { 6 | 7 | it('returns a set from any array based on predicate', function() { 8 | eq(R.uniqBy(Math.abs, [-2, -1, 0, 1, 2]), [-2, -1, 0]); 9 | }); 10 | 11 | it('keeps elements from the left', function() { 12 | eq(R.uniqBy(Math.abs, [-1, 2, 4, 3, 1, 3]), [-1, 2, 4, 3]); 13 | }); 14 | 15 | it('returns an empty array for an empty array', function() { 16 | eq(R.uniqBy(R.identity, []), []); 17 | }); 18 | 19 | it('has R.equals semantics', function() { 20 | function Just(x) { 21 | this.value = x; 22 | } 23 | Just.prototype.equals = function(x) { 24 | return x instanceof Just && R.equals(x.value, this.value); 25 | }; 26 | eq(R.uniqBy(R.identity, [-0, 0]).length, 2); 27 | eq(R.uniqBy(R.identity, [NaN, NaN]).length, 1); 28 | eq(R.uniqBy(R.identity, [new Just([1, 2, 3]), new Just([1, 2, 3])]).length, 1); 29 | }); 30 | 31 | }); 32 | -------------------------------------------------------------------------------- /test/unless.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | var _isArrayLike = require('../source/internal/_isArrayLike'); 4 | 5 | 6 | describe('unless', function() { 7 | it('calls the whenFalse function if the validator returns a falsy value', function() { 8 | eq(R.unless(_isArrayLike, R.of)(10), [10]); 9 | }); 10 | 11 | it('returns the argument unmodified if the validator returns a truthy value', function() { 12 | eq(R.unless(_isArrayLike, R.of)([10]), [10]); 13 | }); 14 | 15 | it('returns a curried function', function() { 16 | eq(R.unless(_isArrayLike)(R.of)(10), [10]); 17 | eq(R.unless(_isArrayLike)(R.of)([10]), [10]); 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /test/until.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | var _isArrayLike = require('../source/internal/_isArrayLike'); 4 | 5 | 6 | describe('until', function() { 7 | it('applies fn until pred is satisfied', function() { 8 | eq(R.until(R.gt(R.__, 100), R.multiply(2), 1), 128); 9 | }); 10 | 11 | it('works with lists', function() { 12 | eq(R.until(R.none(_isArrayLike), R.unnest)([1, [2], [[3]]]), [1, 2, 3]); 13 | }); 14 | 15 | it('ignores fn if predicate is always true', function() { 16 | eq(R.until(R.T, R.T, false), false); 17 | }); 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /test/when.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('when', function() { 6 | it('calls the whenTrue function if the validator returns a truthy value', function() { 7 | eq(R.when(R.is(Number), R.add(1))(10), 11); 8 | }); 9 | 10 | it('returns the argument unmodified if the validator returns a falsy value', function() { 11 | eq(R.when(R.is(Number), R.add(1))('hello'), 'hello'); 12 | }); 13 | 14 | it('returns a curried function', function() { 15 | var ifIsNumber = R.when(R.is(Number)); 16 | eq(ifIsNumber(R.add(1))(15), 16); 17 | eq(ifIsNumber(R.add(1))('hello'), 'hello'); 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /test/without.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('without', function() { 6 | it('returns an array not containing values in the first argument', function() { 7 | eq(R.without([1, 2], [1, 2, 1, 4, 5]), [4, 5]); 8 | }); 9 | 10 | it('can act as a transducer', function() { 11 | eq(R.into([], R.without([1]), [1]), []); 12 | }); 13 | 14 | it('has R.equals semantics', function() { 15 | function Just(x) { this.value = x; } 16 | Just.prototype.equals = function(x) { 17 | return x instanceof Just && R.equals(x.value, this.value); 18 | }; 19 | 20 | eq(R.without([0], [-0]).length, 1); 21 | eq(R.without([-0], [0]).length, 1); 22 | eq(R.without([NaN], [NaN]).length, 0); 23 | eq(R.without([[1]], [[1]]).length, 0); 24 | eq(R.without([new Just([42])], [new Just([42])]).length, 0); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /test/xprod.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('xprod', function() { 6 | var a = [1, 2]; 7 | var b = ['a', 'b', 'c']; 8 | 9 | it('returns an empty list if either input list is empty', function() { 10 | eq(R.xprod([], [1, 2, 3]), []); 11 | eq(R.xprod([1, 2, 3], []), []); 12 | }); 13 | 14 | it('creates the collection of all cross-product pairs of its parameters', function() { 15 | eq(R.xprod(a, b), [[1, 'a'], [1, 'b'], [1, 'c'], [2, 'a'], [2, 'b'], [2, 'c']]); 16 | }); 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /test/zip.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('zip', function() { 6 | it('returns an array of "tuples"', function() { 7 | var a = [1, 2, 3]; 8 | var b = [100, 200, 300]; 9 | 10 | eq(R.zip(a, b), [[1, 100], [2, 200], [3, 300]]); 11 | }); 12 | 13 | it('returns a list as long as the shorter of the lists input', function() { 14 | var a = [1, 2, 3]; 15 | var b = [100, 200, 300, 400]; 16 | var c = [10, 20]; 17 | 18 | eq(R.zip(a, b), [[1, 100], [2, 200], [3, 300]]); 19 | eq(R.zip(a, c), [[1, 10], [2, 20]]); 20 | }); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /test/zipObj.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('zipObj', function() { 6 | it('combines an array of keys with an array of values into a single object', function() { 7 | eq(R.zipObj(['a', 'b', 'c'], [1, 2, 3]), {a: 1, b: 2, c: 3}); 8 | }); 9 | 10 | it('ignores extra values', function() { 11 | eq(R.zipObj(['a', 'b', 'c'], [1, 2, 3, 4, 5, 6, 7]), {a: 1, b: 2, c: 3}); 12 | }); 13 | 14 | it('ignores extra keys', function() { 15 | eq(R.zipObj(['a', 'b', 'c', 'd', 'e', 'f'], [1, 2, 3]), {a: 1, b: 2, c: 3}); 16 | }); 17 | 18 | it('last one in wins when there are duplicate keys', function() { 19 | eq(R.zipObj(['a', 'b', 'c', 'a'], [1, 2, 3, 'LAST']), {a: 'LAST', b: 2, c: 3}); 20 | }); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /test/zipWith.js: -------------------------------------------------------------------------------- 1 | var R = require('../source'); 2 | var eq = require('./shared/eq'); 3 | 4 | 5 | describe('zipWith', function() { 6 | var a = [1, 2, 3]; 7 | var b = [100, 200, 300]; 8 | var c = [10, 20, 30, 40, 50, 60]; 9 | var add = function(a, b) { return a + b; }; 10 | var x = function(a, b) { return a * b; }; 11 | var s = function(a, b) { return a + ' cow ' + b; }; 12 | it('returns an array created by applying its passed-in function pair-wise on its passed in arrays', function() { 13 | eq(R.zipWith(add, a, b), [101, 202, 303]); 14 | eq(R.zipWith(x, a, b), [100, 400, 900]); 15 | eq(R.zipWith(s, a, b), ['1 cow 100', '2 cow 200', '3 cow 300']); 16 | }); 17 | 18 | it('returns an array whose length is equal to the shorter of its input arrays', function() { 19 | eq(R.zipWith(add, a, c).length, a.length); 20 | }); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /testem.json: -------------------------------------------------------------------------------- 1 | { 2 | "framework": "mocha", 3 | "cwd": ".", 4 | "src_files": [ 5 | "dist/ramda.js", 6 | "test/*.js" 7 | ], 8 | "serve_files": [ 9 | "tmp-test-bundle.js" 10 | ], 11 | "before_tests": "cross-env BABEL_ENV=cjs browserify test/*.js -t babelify --outfile tmp-test-bundle.js", 12 | "after_tests": "rimraf tmp-test-bundle.js" 13 | } 14 | --------------------------------------------------------------------------------