Comparing version 1.6.0 to 1.7.0
@@ -0,1 +1,13 @@ | ||
# [1.7.0](https://github.com/adobe/ferrum/compare/v1.6.0...v1.7.0) (2020-01-17) | ||
### Bug Fixes | ||
* Add missing export for Pairs ([492c02c](https://github.com/adobe/ferrum/commit/492c02c7e1dea16e924ab04bf64d78f1c15e902f)) | ||
### Features | ||
* Use ferrum.doctest to make sure examples are valid js code ([b0f9d45](https://github.com/adobe/ferrum/commit/b0f9d4569b4439ffb94c6b3f7a00bf2d6b0ab78a)) | ||
# [1.6.0](https://github.com/adobe/ferrum/compare/v1.5.0...v1.6.0) (2020-01-10) | ||
@@ -2,0 +14,0 @@ |
{ | ||
"name": "ferrum", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "Features from the rust language in javascript: Provides Traits/Type classes & an advanced library for working with sequences/iterators in js.", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "nyc --reporter=text --reporter=lcov --check-coverage --branches 90 --statements 90 --lines 90 mocha --reporter xunit --reporter-options output=./junit/test-results.xml test src", | ||
"test": "ferrum.doctest exec -s src --mdsrc README.md -c 'nyc --reporter=text --reporter=lcov --check-coverage --branches 90 --statements 90 --lines 90 mocha --reporter mocha-multi-reporters --reporter-options configFile=.mochaReportersConfig.json --require source-map-support/register -t 20000 \"$DOCTEST_FILE\" test'", | ||
"test-ci": "npm run test && codecov", | ||
@@ -31,6 +31,6 @@ "lint": "./node_modules/.bin/eslint src test", | ||
"@semantic-release/changelog": "3.0.6", | ||
"@semantic-release/commit-analyzer": "6.3.3", | ||
"@semantic-release/git": "7.0.18", | ||
"@semantic-release/github": "5.5.5", | ||
"@semantic-release/npm": "5.3.5", | ||
"@semantic-release/commit-analyzer": "7.0.0", | ||
"@semantic-release/git": "8.0.0", | ||
"@semantic-release/github": "6.0.1", | ||
"@semantic-release/npm": "6.0.0", | ||
"@semantic-release/release-notes-generator": "7.3.5", | ||
@@ -45,5 +45,6 @@ "ajv": "6.10.2", | ||
"eslint-plugin-header": "3.0.0", | ||
"eslint-plugin-import": "2.19.1", | ||
"eslint-plugin-import": "2.20.0", | ||
"eslint-plugin-jsx-a11y": "6.2.3", | ||
"eslint-plugin-react": "7.17.0", | ||
"ferrum.doctest": "0.1.0", | ||
"jsdoc": "3.6.3", | ||
@@ -53,7 +54,8 @@ "junit-report-builder": "1.3.3", | ||
"mocha": "7.0.0", | ||
"mocha-junit-reporter": "1.23.1", | ||
"mocha-junit-reporter": "1.23.2", | ||
"mocha-multi-reporters": "^1.1.7", | ||
"mocha-parallel-tests": "2.2.2", | ||
"nyc": "15.0.0", | ||
"semantic-release": "15.14.0", | ||
"snyk": "1.274.0" | ||
"semantic-release": "16.0.1", | ||
"snyk": "1.278.1" | ||
}, | ||
@@ -60,0 +62,0 @@ "snyk": true, |
@@ -47,3 +47,3 @@ <a name="ferrum"></a> | ||
```bash | ||
```bash,notest | ||
$ npm add ferrum | ||
@@ -92,5 +92,6 @@ ``` | ||
const log = []; | ||
for (const [key, value] in iter(obj)) { | ||
for (const [key, value] of iter(obj)) { | ||
log.push(`${key} | ${value}`); | ||
} | ||
assertEquals(log, [ | ||
@@ -140,2 +141,4 @@ 'foo | 23', | ||
```js | ||
const { map, plus, list, assertSequenceEquals } = require('ferrum'); | ||
const myList = [ | ||
@@ -151,3 +154,3 @@ [1,2,3], | ||
const a = map(myList, map(plus(2))); | ||
assertSequenceEquals(a, [ | ||
assertSequenceEquals(map(a, list), [ | ||
[3,4,5], | ||
@@ -161,3 +164,3 @@ [6,7,8], | ||
const b = map(myList, (sublist) => map(sublist, (b) => plus(b, 2))); | ||
assertSequenceEquals(b, [ | ||
assertSequenceEquals(map(b, list), [ | ||
[3,4,5], | ||
@@ -174,3 +177,3 @@ [6,7,8], | ||
```js | ||
```js,notest | ||
const {each} = require('ferrum'); | ||
@@ -205,4 +208,6 @@ | ||
const {sqrt} = Math; | ||
const {pipe, filter, uniq, map, mul, mapSort, identity, pipe, | ||
prepend, takeWhile, all, range} = require('ferrum'); | ||
const { | ||
pipe, filter, uniq, map, mul, mapSort, identity, | ||
prepend, takeWhile, all, range, assertSequenceEquals, | ||
} = require('ferrum'); | ||
@@ -215,3 +220,3 @@ const a = pipe( | ||
mapSort(identity)); // Sort all numbers | ||
assertSequenceEquals(q, [3,9,12,15,18,21,30,33]); | ||
assertSequenceEquals(a, [3,9,15,21,33]); | ||
@@ -341,3 +346,3 @@ // Very simple primality test | ||
```js | ||
const {map, plus} = require('ferrum'); | ||
const {map, plus, list} = require('ferrum'); | ||
const a = map([1,2,3], plus(2)); // At this point, no calculations have been performed | ||
@@ -354,9 +359,19 @@ const b = list(a); // This will actually cause the values of the a iterator to be calculated | ||
```js | ||
const {take, list, assertEquals} = require('ferrum'); | ||
const {take, list, assertSequenceEquals} = require('ferrum'); | ||
// Even though primes() is infinite, this just works because only the | ||
// first five primes are actually calculated. | ||
// Note that just list(primes()) would crash the program since that would | ||
function* fibonacci() { | ||
let a=0, b=1; | ||
while (true) { | ||
yield a; | ||
yield b; | ||
a += b; | ||
b += a; | ||
} | ||
} | ||
// Even though fibonacci() is infinite, this just works because only the | ||
// first five fibonacci numbers are actually generated | ||
// Note that just list(fibonacci()) would crash the program since that would | ||
// require infinite memory and infinite time | ||
assertEquals(list(take(5, primes())), [2, 3, 5, 7, 11]); | ||
assertSequenceEquals(take(fibonacci(), 5), [0, 1, 1, 2, 3]); | ||
``` | ||
@@ -459,3 +474,4 @@ | ||
// being thrown | ||
null[Size] = () => 0; | ||
//null[Size] = () => 0; // throws TypeError | ||
``` | ||
@@ -492,3 +508,3 @@ | ||
// dbtable.js | ||
const { Trait } = require('ferrum'); | ||
const { Trait, Size: SyncSize } = require('ferrum'); | ||
const Size = new Trait('Size'); | ||
@@ -502,12 +518,2 @@ | ||
module.exports = {Size, DbTable}; | ||
``` | ||
```js | ||
// localtable.js | ||
const { Trait } = require('ferrum'); | ||
const {Size: AsyncSize} = require('./dbtable.js') | ||
const Size = new Trait('Size'); | ||
class MyLocalTable { | ||
@@ -519,3 +525,3 @@ [Size.sym]() { | ||
AsyncSize.implDerived([Size], ([size], v) => Promise.resolve(size(v))); | ||
Size.implDerived([SyncSize], ([size], v) => Promise.resolve(size(v))); | ||
``` | ||
@@ -544,6 +550,6 @@ | ||
list(map([1,2,3], plus(2))); // => [3,4,5] | ||
and(True, False); // => False | ||
not(1); // => False | ||
is(2, 2); // => True | ||
xor(True, False); // => True | ||
and(true, false); // => false | ||
not(1); // => false | ||
is(2, 2); // => true | ||
xor(true, false); // => true | ||
``` | ||
@@ -558,3 +564,3 @@ | ||
```js | ||
class {isdef, type, typename} = require('ferrum'); | ||
const {isdef, type, typename} = require('ferrum'); | ||
@@ -626,3 +632,3 @@ isdef(0); // => true | ||
```bash | ||
```bash,notest | ||
$ npm install | ||
@@ -634,3 +640,3 @@ ``` | ||
```bash | ||
```bash,notest | ||
$ npm test | ||
@@ -642,4 +648,4 @@ ``` | ||
```bash | ||
```bash,notest | ||
$ npm run lint | ||
``` |
@@ -32,3 +32,3 @@ /* | ||
* // Can be rewritten as | ||
* const r = exec(() => { | ||
* const q = exec(() => { | ||
* let x = 42, y = 5; | ||
@@ -45,6 +45,6 @@ * return x + y; | ||
* ``` | ||
* const {identity, list, filter} = require('ferrum'); | ||
* const {identity, list, filter, pipe} = require('ferrum'); | ||
* | ||
* identity(null) # => null | ||
* identity(42) # => 42 | ||
* identity(null); // => null | ||
* identity(42); // => 42 | ||
* | ||
@@ -68,2 +68,4 @@ * // Identity is sometimes useful in higher order functions like | ||
* ``` | ||
* const { pipe, filter, uniq, map, plus, identity } = require('ferrum'); | ||
* | ||
* // Sometimes you get very nested function invocations: | ||
@@ -136,2 +138,4 @@ * | ||
* ``` | ||
* const { map } = require('ferrum'); | ||
* | ||
* const toNumber = (seq) => map(seq, n => Number(n)); | ||
@@ -141,7 +145,7 @@ * | ||
* | ||
* const toNumber = map(n => Number(n)) | ||
* const toNumber2 = map(n => Number(n)); | ||
* | ||
* // or even | ||
* | ||
* const toNumber = map(Number); | ||
* const toNumber3 = map(Number); | ||
* ``` | ||
@@ -155,2 +159,4 @@ * | ||
* ``` | ||
* const { foldl, plus } = require('ferrum'); | ||
* | ||
* const sum = (seq) => foldl(seq, 0, (a, b) => a+b); | ||
@@ -160,7 +166,7 @@ * | ||
* | ||
* const sum = foldl(0, (a, b) => a+b); | ||
* const sum2 = foldl(0, (a, b) => a+b); | ||
* | ||
* // or even | ||
* | ||
* concat = sum = foldl(0, plus); | ||
* const sum3 = foldl(0, plus); | ||
* ``` | ||
@@ -167,0 +173,0 @@ * |
@@ -192,2 +192,3 @@ /* | ||
* ``` | ||
* const assert = require('assert'); | ||
* const {is, count, filter, pipe} = require('ferrum'); | ||
@@ -207,5 +208,4 @@ * | ||
* filter(is(42)), | ||
* count | ||
* ); | ||
* assert(cnt == 42); | ||
* count); | ||
* assert.strictEqual(cnt, 2); | ||
* ``` | ||
@@ -240,4 +240,3 @@ * | ||
* filter(aint(42)), | ||
* list; | ||
* ) | ||
* list); | ||
* // => [1,2,3,4,5] | ||
@@ -294,9 +293,9 @@ * ``` | ||
* ``` | ||
* const {mul, list, map, pipe} = require('ferrum'); | ||
* const { mul, list, map, pipe, plus } = require('ferrum'); | ||
* | ||
* mul(3, 4) // => 12 | ||
* mul(3, 1/10) // => -1; Can also be used for s | ||
* mul(3, 4); // => 12 | ||
* mul(3, 1/10); // => -1; Can also be used for s | ||
* | ||
* plus(3)(4) // => 7 | ||
* plus(3)(-4) // => -1; Can also be used for subtraction | ||
* plus(3)(4); // => 7 | ||
* plus(3)(-4); // => -1; Can also be used for subtraction | ||
* | ||
@@ -306,5 +305,4 @@ * // Divide each element in the list by ten | ||
* [1,2,3,4,5], | ||
* map(div(1/10)), | ||
* list | ||
* ); | ||
* map(mul(1/10)), | ||
* list); | ||
* // [0.1, 0.2, 0.3, 0.4, 0.5] | ||
@@ -311,0 +309,0 @@ * ``` |
@@ -51,3 +51,4 @@ /* | ||
* ``` | ||
* each(map(sequence, (x) => x*2), console.log) | ||
* const { each, map } = require('ferrum'); | ||
* each(map([1,2,3], (x) => x*2), console.log); | ||
* ``` | ||
@@ -64,4 +65,5 @@ * | ||
* ``` | ||
* each(seq, (elm) => { | ||
* doSomething(elm); | ||
* const { each } = require('ferrum'); | ||
* each([1,2,3,4], (elm) => { | ||
* // doSomething(elm); | ||
* console.log(elm); | ||
@@ -76,6 +78,10 @@ * }); | ||
* ``` | ||
* const each = (fn, seq) => { | ||
* for (const val of seq) fn(val); | ||
* }; | ||
* | ||
* each((elm) => { | ||
* doSomething(elm); | ||
* // doSomething(elm); | ||
* console.log(elm); | ||
* }, seq); | ||
* }, [1,2,3,4]); | ||
* ``` | ||
@@ -93,6 +99,6 @@ * | ||
* | ||
* ```notest | ||
* for (const v of {foo: 42, bar: 23}) console.log(v); | ||
* // throws TypeError: {(intermediate value)(intermediate value)} is not iterable | ||
* ``` | ||
* > for (const v of {foo: 42, bar: 23}) console.log(v); | ||
* TypeError: {(intermediate value)(intermediate value)} is not iterable | ||
* ``` | ||
* | ||
@@ -104,7 +110,8 @@ * Does not work because plain objects do not implement the iterator protocol. | ||
* ``` | ||
* > each([1,2,3,4], console.log); | ||
* 1 | ||
* 2 | ||
* 3 | ||
* 4 | ||
* const { each } = require('ferrum'); | ||
* each([1,2,3,4], console.log); | ||
* // 1 | ||
* // 2 | ||
* // 3 | ||
* // 4 | ||
* ``` | ||
@@ -115,4 +122,5 @@ * | ||
* ``` | ||
* > each({foo: 42}, v => console.log(v)); | ||
* [ 'foo', 42 ] | ||
* const { each } = require('ferrum'); | ||
* each({foo: 42}, v => console.log(v)); | ||
* // [ 'foo', 42 ] | ||
* ``` | ||
@@ -123,4 +131,5 @@ * | ||
* ``` | ||
* const { each, iter } = require('ferrum'); | ||
* for (const v of iter({foo: 42})) console.log(v); | ||
*[ 'foo', 42 ] | ||
* // [ 'foo', 42 ] | ||
* ``` | ||
@@ -131,7 +140,8 @@ * | ||
* ``` | ||
* > [1,2,3,4].forEach(console.log) | ||
* 1 0 [ 1, 2, 3, 4 ] | ||
* 2 1 [ 1, 2, 3, 4 ] | ||
* 3 2 [ 1, 2, 3, 4 ] | ||
* 4 3 [ 1, 2, 3, 4 ] | ||
* const { each } = require('ferrum'); | ||
* [1,2,3,4].forEach(console.log) | ||
* // 1 0 [ 1, 2, 3, 4 ] | ||
* // 2 1 [ 1, 2, 3, 4 ] | ||
* // 3 2 [ 1, 2, 3, 4 ] | ||
* // 4 3 [ 1, 2, 3, 4 ] | ||
* ``` | ||
@@ -147,7 +157,8 @@ * | ||
* ``` | ||
* > each([1,2,3,4], console.log); | ||
* 1 | ||
* 2 | ||
* 3 | ||
* 4 | ||
* const { each } = require('ferrum'); | ||
* each([1,2,3,4], console.log); | ||
* // 1 | ||
* // 2 | ||
* // 3 | ||
* // 4 | ||
* ``` | ||
@@ -158,5 +169,6 @@ * | ||
* ``` | ||
* const { each, enumerate } = require('ferrum'); | ||
* each(enumerate([42, 23]), console.log) | ||
* [ 0, 42 ] | ||
* [ 1, 23 ] | ||
* // [ 0, 42 ] | ||
* // [ 1, 23 ] | ||
* ``` | ||
@@ -260,4 +272,7 @@ * | ||
* ``` | ||
* const { extend, takeUntilVal } = require('ferrum'); | ||
* | ||
* // Generate an infinite list of all positive integers | ||
* extend(0, x => x+1); | ||
* | ||
* // Generate the range of integers [first; last[ | ||
@@ -311,2 +326,4 @@ * const range = (first, last) => | ||
* ``` | ||
* const { flattenTree } = require('ferrum'); | ||
* | ||
* flattenTree((node, recurse) => { | ||
@@ -328,3 +345,2 @@ * if (isEmptyLeaf()) { | ||
* } | ||
* } | ||
* }); | ||
@@ -355,4 +371,4 @@ * ``` | ||
* next(it); // => 3 | ||
* next(it); // throws IteratorEnded | ||
* next(it); // throws IteratorEnded | ||
* //next(it); // throws IteratorEnded | ||
* //next(it); // throws IteratorEnded | ||
* ``` | ||
@@ -415,3 +431,3 @@ * | ||
* fifth(it) // => 'l' | ||
* nth(it, 10); // throws IteratorEnded | ||
* //nth(it, 10); // throws IteratorEnded | ||
* ``` | ||
@@ -426,2 +442,3 @@ * | ||
const nth = curry('nth', (seq, idx) => next(skip(seq, idx))); | ||
/** | ||
@@ -435,3 +452,3 @@ * Extract the first element from the sequence; this is effectively | ||
* first([1,2]) // => 1 | ||
* first([]); // throws IteratorEnded | ||
* //first([]); // throws IteratorEnded | ||
* ``` | ||
@@ -445,2 +462,3 @@ * | ||
const first = (seq) => next(seq); | ||
/** | ||
@@ -453,3 +471,3 @@ * Extract the second element from the sequence | ||
* second([1,2]) // => 2 | ||
* second([1]); // throws IteratorEnded | ||
* //second([1]); // throws IteratorEnded | ||
* ``` | ||
@@ -463,2 +481,3 @@ * | ||
const second = (seq) => nth(seq, 1); | ||
/** | ||
@@ -470,4 +489,4 @@ * Extract the last element from the sequence | ||
* | ||
* last([1,2,3,4,5]) // => 5 | ||
* last([]); // throws IteratorEnded | ||
* last([1,2,3,4,5]); // => 5 | ||
* //last([]); // throws IteratorEnded | ||
* ``` | ||
@@ -494,3 +513,3 @@ * | ||
* ``` | ||
* const {iter, next, tryNth} = require('ferrum'); | ||
* const { iter, next, tryNth, nth } = require('ferrum'); | ||
* | ||
@@ -501,4 +520,4 @@ * const it = iter('hello world'); | ||
* | ||
* const fifth = nth(4, null); | ||
* fifth(it) // => 'l' | ||
* const fifth = tryNth(4, null); | ||
* fifth(it); // => 'l' | ||
* tryNth(it, 10, null); // => null | ||
@@ -514,2 +533,3 @@ * ``` | ||
const tryNth = curry('tryNth', (seq, idx, fallback) => tryNext(trySkip(seq, idx), fallback)); | ||
/** | ||
@@ -535,2 +555,3 @@ * Extract the first element from the sequence; this is effectively | ||
const tryFirst = curry('tryFirst', (seq, fallback) => tryNext(seq, fallback)); | ||
/** | ||
@@ -555,2 +576,3 @@ * Extract the second element from the sequence | ||
const trySecond = curry('trySecond', (seq, fallback) => tryNth(seq, 1, fallback)); | ||
/** | ||
@@ -619,7 +641,7 @@ * Extract the last element from the sequence | ||
* find([1,2,3,4], v => v>2); // => 3 | ||
* find([1,2,3,4], v => v>10); // throws IteratorEnded | ||
* //find([1,2,3,4], v => v>10); // throws IteratorEnded | ||
* | ||
* const findEven = find(v => v % 2 === 0); | ||
* find([3,4,1,2]); // => 4 | ||
* find([]); // throws IteratorEnded | ||
* // find([]); // throws IteratorEnded | ||
* ``` | ||
@@ -683,2 +705,4 @@ * | ||
* ``` | ||
* const { tryFind, contains, is, not } = require('ferrum'); | ||
* | ||
* // The usual pattern checking whether a value is contained would be this: | ||
@@ -724,3 +748,3 @@ * tryFind([1,2,3,4], null, is(3)); // => 3 (truthy) | ||
* ``` | ||
* const {seqEq, eq} = require('ferrum'); | ||
* const { seqEq, eq, dict } = require('ferrum'); | ||
* | ||
@@ -750,3 +774,3 @@ * seqEq([1,2,3,4], [1,2,3,4]); // => true | ||
* // Same goes of course for es6 Maps created from objects | ||
* seqEq(dict(obj), dict(obj))); // => UNDEFINED BEHAVIOUR; could be true or false | ||
* seqEq(dict(obj), dict(obj)); // => UNDEFINED BEHAVIOUR; could be true or false | ||
* | ||
@@ -945,2 +969,4 @@ * // Objects as elements inside the iterator are OK; elements are compared | ||
* ``` | ||
* const { into } = require('ferrum'); | ||
* | ||
* into({foo: 42, bar: 23}, Map) // Map { 'foo' => 42, 'bar' } | ||
@@ -955,2 +981,4 @@ * into(["foo", " bar"], String) // "foo bar" | ||
* ``` | ||
* const { into, filter } = require('ferrum'); | ||
* | ||
* // Remove odd numbers from a set | ||
@@ -962,3 +990,3 @@ * const st = new Set([1,1,2,2,3,4,5]); | ||
* const obj = {foo: 42, bar: 5}; | ||
* into(filter(obj, ([k, v]) => k !== 'foo'), Obj) | ||
* into(filter(obj, ([k, v]) => k !== 'foo'), Object) | ||
* // yields {bar: 5} | ||
@@ -970,4 +998,6 @@ * ``` | ||
* ``` | ||
* const { concat, into } = require('ferrum'); | ||
* | ||
* // Merge multiple key/value containers into one sequence: | ||
* const seq = concat([[99, 42]], new Map(true, 23), {bar: 13}); | ||
* const seq = concat([[99, 42]], new Map([[true, 23]]), {bar: 13}); | ||
* into(seq, Map) // Map( 99 => 42, true => 23, bar => 13 ) | ||
@@ -1080,3 +1110,4 @@ * ``` | ||
* ``` | ||
* into(map([1,2,3,4], n => n*2), Array) // [2,4,6,8] | ||
* const { into, map } = require('ferrum'); | ||
* into(map([1,2,3,4], n => n*2), Array); // [2,4,6,8] | ||
* ``` | ||
@@ -1099,3 +1130,4 @@ * | ||
* ``` | ||
* filter(range(0,10), x => x%2 === 0) // [2,4,6,8] | ||
* const { filter, range } = require('ferrum'); | ||
* filter(range(0,10), x => x%2 === 0); // [2,4,6,8] | ||
* ``` | ||
@@ -1329,2 +1361,3 @@ * | ||
* ``` | ||
* const { into, flat } = require('ferrum'); | ||
* into(flat([[1,2], [3,4]]), Array) // [1,2,3,4] | ||
@@ -1511,3 +1544,3 @@ * into(flat({foo: 42}), Array) // ["foo", 42] | ||
* ``` | ||
* const { intersperse } = require('ferrum'); | ||
* const { intersperse, assertSequenceEquals } = require('ferrum'); | ||
* assertSequenceEquals( | ||
@@ -1612,2 +1645,3 @@ * intersperse('ABC', '|'), | ||
* ``` | ||
* const { lookahead } = require('ferrum'); | ||
* lookahead([], 3, null) // => [] | ||
@@ -1759,3 +1793,3 @@ * lookahead([42], 3, null) // => [[42, null, null, null]] | ||
* { foo: 13, bar: 22 }]], | ||
* [42, [ | ||
* [99, [ | ||
* { foo: 42, bar: 99 }]] | ||
@@ -1790,3 +1824,3 @@ * ]) | ||
* // => [[1,3,5], [1,3,6], [1,4,5], [1,4,6], | ||
* [2,3,5], [2,3,6], [2,4,5], [2,4,6]] | ||
* // [2,3,5], [2,3,6], [2,4,5], [2,4,6]] | ||
* list(cartesian([[], [3,4], [5,6]])); // => [] | ||
@@ -1855,4 +1889,6 @@ * ``` | ||
* ``` | ||
* const assert = require('assert'); | ||
* const { mod, map, plus } = require('ferrum'); | ||
* const s = new Set([1,2,3,4]); | ||
* const z = mod1(s, map(plus(1))); # => new Set([2,3,4,5]), | ||
* const z = mod(s, map(plus(1))); // => new Set([2,3,4,5]), | ||
* assert(z.constructor === Set) | ||
@@ -1859,0 +1895,0 @@ * ``` |
@@ -56,2 +56,3 @@ /* | ||
* ``` | ||
* const { typeIsImmutable } = require('ferrum'); | ||
* typeIsImmutable(Object); // => false | ||
@@ -73,2 +74,3 @@ * typeIsImmutable(String); // => true | ||
* ``` | ||
* const { isImmutable } = require('ferrum'); | ||
* isImmutable({}); // => false | ||
@@ -147,2 +149,3 @@ * isImmutable(42); // => true | ||
* ``` | ||
* const { eq } = require('ferrum'); | ||
* eq([{foo: 42}], [{foo: 42}]); // => true | ||
@@ -187,3 +190,4 @@ * eq(1, 2); // => false | ||
* ``` | ||
* uneq(4, 5); # => true | ||
* const { uneq } = require('ferrum'); | ||
* uneq(4, 5); // => true | ||
* ``` | ||
@@ -209,4 +213,5 @@ * | ||
* ``` | ||
* const { assertEquals } = require('ferrum'); | ||
* assertEquals([{foo: 42}], [{foo: 42}]); // OK! | ||
* assertEquals(1, 2); // AssertionError! | ||
* //assertEquals(1, 2); // AssertionError! | ||
* ``` | ||
@@ -247,4 +252,5 @@ * | ||
* ``` | ||
* const { assertUneq } = require('ferrum'); | ||
* assertUneq(1, 2); // OK! | ||
* assertUneq([{foo: 42}], [{foo: 42}]); // AssertionError! | ||
* //assertUneq([{foo: 42}], [{foo: 42}]); // AssertionError! | ||
* ``` | ||
@@ -285,3 +291,3 @@ * | ||
* ``` | ||
* const {equals, eq, uneq, assertEquals, assertUneq} = require('ferrum'); | ||
* const { Equals, equals, eq, uneq, assertEquals, assertUneq } = require('ferrum'); | ||
* | ||
@@ -304,3 +310,3 @@ * // Implementing this type | ||
* Equals.impl(Bar, (a, b) => { | ||
* ... | ||
* // ... | ||
* }); | ||
@@ -316,6 +322,6 @@ * | ||
* assertEquals({}, {}, 'Values where different!'); // OK! | ||
* assertEquals({}, {foo: 42}, 'Values where different!'); // Assertion Error! | ||
* //assertEquals({}, {foo: 42}, 'Values where different!'); // Assertion Error! | ||
* | ||
* assertUneq([], [{}], 'Values where the same'); // OK! | ||
* assertUneq([], [], 'Values where the same'); // Assertion Error! | ||
* //assertUneq([], [], 'Values where the same'); // Assertion Error! | ||
* ``` | ||
@@ -349,8 +355,10 @@ * | ||
* | ||
* ``` | ||
* ```notest | ||
* const { Equals, type } = require('ferrum'); | ||
* | ||
* Equals.impl(Number, (a, b) => | ||
* type(b) === (String || type(b) === Number) | ||
* (type(b) === String || type(b) === Number) | ||
* && a.toString() === b.toString()); | ||
* Equals.impl(String, (a, b) => | ||
* type(b) === (String || type(b) === Number) | ||
* (type(b) === String || type(b) === Number) | ||
* && a.toString() === b.toString()); | ||
@@ -410,2 +418,3 @@ * ``` | ||
* ``` | ||
* const { size } = require('ferrum'); | ||
* size({foo: 42}); // => 1 | ||
@@ -430,2 +439,3 @@ * size([1,2,3]); // => 3 | ||
* ``` | ||
* const { empty } = require('ferrum'); | ||
* empty([]); // => true | ||
@@ -452,2 +462,4 @@ * empty({}); // => true | ||
* ``` | ||
* const { Size, size, empty } = require('ferrum'); | ||
* | ||
* // Implementing size | ||
@@ -512,2 +524,3 @@ * class Foo { | ||
* ``` | ||
* const { shallowclone } = require('ferrum'); | ||
* const a = {foo: []}; | ||
@@ -537,3 +550,4 @@ * const b = shallowclone(a); | ||
* ``` | ||
* const {Shallowclone, shallowclone} = require('ferrum'); | ||
* const assert = require('assert'); | ||
* const { Shallowclone, shallowclone, assertEquals, Equals, eq } = require('ferrum'); | ||
* | ||
@@ -547,4 +561,8 @@ * class Bar { | ||
* [Shallowclone.sym]() { | ||
* return new Bar(this.foo, this.bar); | ||
* return new Bar(this.foo, this.bang); | ||
* } | ||
* | ||
* [Equals.sym](otr) { | ||
* return eq(this.foo, otr.foo) && eq(this.bar, otr.bar); | ||
* } | ||
* } | ||
@@ -559,3 +577,3 @@ * | ||
* a.foo.foo = 5; | ||
* assert(b.foo.foo === 5); | ||
* assert.strictEqual(b.foo.foo, 5); | ||
* ``` | ||
@@ -603,2 +621,4 @@ * | ||
* ``` | ||
* const { deepclone } = require('ferrum'); | ||
* | ||
* const a = {foo: []}; | ||
@@ -628,3 +648,4 @@ * const b = deepclone(a); | ||
* ``` | ||
* const {Deepclone, deepclone} = require('ferrum'); | ||
* const assert = require('assert'); | ||
* const { Deepclone, deepclone, Equals, eq, assertEquals } = require('ferrum'); | ||
* | ||
@@ -638,4 +659,8 @@ * class Bar { | ||
* [Deepclone.sym]() { | ||
* return new Bar(deepclone(this.foo), deepclone(this.bar)); | ||
* return new Bar(deepclone(this.foo), deepclone(this.bang)); | ||
* } | ||
* | ||
* [Equals.sym](otr) { | ||
* return eq(this.foo, otr.foo) && eq(this.bar, otr.bar); | ||
* } | ||
* } | ||
@@ -714,6 +739,6 @@ * | ||
* ``` | ||
* const {list, pairs} = require('ferrum'); | ||
* const { list, pairs } = require('ferrum'); | ||
* | ||
* list(pairs(['a', 'b'])); // => [[0, 'a'], [1, 'b']] | ||
* list(pairs(new Set[1, 2])); // => [[1, 1], [2, 2]] | ||
* list(pairs(new Set([1, 2]))); // => [[1, 1], [2, 2]] | ||
* list(pairs({foo: 42})); // [['foo', 42]] | ||
@@ -740,3 +765,3 @@ * ``` | ||
* list(keys(['a', 'b'])); // => [0, 1] | ||
* list(keys(new Set[1, 2])); // => [1, 2] | ||
* list(keys(new Set([1, 2]))); // => [1, 2] | ||
* list(keys({foo: 42})); // ['foo'] | ||
@@ -766,3 +791,3 @@ * ``` | ||
* list(values(['a', 'b'])); // => ['a', 'b'] | ||
* list(values(new Set[1, 2])); // => [1, 2] | ||
* list(values(new Set([1, 2]))); // => [1, 2] | ||
* list(values({foo: 42})); // [42] | ||
@@ -790,3 +815,4 @@ * ``` | ||
* ``` | ||
* const {list, values, keys, pairs, Pairs} = require('ferrum'); | ||
* const { list, values, keys, pairs, Pairs } = require('ferrum'); | ||
* | ||
* class Bar { | ||
@@ -799,5 +825,5 @@ * *[Pairs.sym]() { | ||
* | ||
* list(pairs(new Bar()); // => [['foo', 42], ['bar', 5]] | ||
* list(keys(new Bar()); // => ['foo', 'bar'] | ||
* list(values(new Bar()); // => [42, 5] | ||
* list(pairs(new Bar())); // => [['foo', 42], ['bar', 5]] | ||
* list(keys(new Bar())); // => ['foo', 'bar'] | ||
* list(values(new Bar())); // => [42, 5] | ||
* ``` | ||
@@ -1094,2 +1120,3 @@ * | ||
Deepclone, | ||
Pairs, | ||
pairs, | ||
@@ -1096,0 +1123,0 @@ keys, |
@@ -27,2 +27,3 @@ /* | ||
* ``` | ||
* const { multiline } = require('ferrum'); | ||
* const s = multiline(` | ||
@@ -29,0 +30,0 @@ * Foo |
@@ -28,3 +28,3 @@ /* | ||
* ``` | ||
* new | ||
* const { HybridWeakMap } = require('ferrum'); | ||
* const m = new HybridWeakMap([['foo', 42], ]); | ||
@@ -85,2 +85,4 @@ * ``` | ||
* ``` | ||
* const { Trait } = require('ferrum'); | ||
* | ||
* // Declaring a trait | ||
@@ -118,3 +120,3 @@ * const Size = new Trait('Size'); | ||
* // implements the magnitude trait | ||
* Size.implDerived([Magnitude], ([magnitude], v) => magnitude(v)); | ||
* //Size.implDerived([Magnitude], ([magnitude], v) => magnitude(v)); | ||
* | ||
@@ -141,8 +143,8 @@ * // This will be called as a last resort, so this must be very fast! | ||
* // Using all the implementations | ||
* size([1,2,3]) # => 3 | ||
* size({foo: 42}) # => 1 | ||
* size(new Set([1,2,3])) # => 3 | ||
* size(new MyType()) # => 42 | ||
* size(null) # => 0 | ||
* size(document.body) # => 1 | ||
* size([1,2,3]); // => 3 | ||
* size({foo: 42}); // => 1 | ||
* size(new Set([1,2,3])); // => 3 | ||
* size(new MyType()); // => 42 | ||
* size(null); // => 0 | ||
* //size(document.body); // => 1 | ||
* ``` | ||
@@ -149,0 +151,0 @@ * |
@@ -26,6 +26,6 @@ /* | ||
* | ||
* isdef(null) # => false | ||
* isdef(undefined) # => false | ||
* isdef(0) # => true | ||
* isdef(false) # => true | ||
* isdef(null); // => false | ||
* isdef(undefined); // => false | ||
* isdef(0); // => true | ||
* isdef(false); // => true | ||
* ``` | ||
@@ -50,3 +50,3 @@ * | ||
* ``` | ||
* const {plus, pipe, isdef, ifdef} = require('ferrum'); | ||
* const { plus, pipe, isdef, ifdef, map, list } = require('ferrum'); | ||
* | ||
@@ -63,3 +63,3 @@ * const o = { | ||
* [1,2,null,3], | ||
* map(ifdef(x => x*3)) | ||
* map(ifdef(x => x*3)), | ||
* list); | ||
@@ -72,3 +72,3 @@ * // yields [3,6,null,9] | ||
* [1,2,null,3], | ||
* map(x => isdef(x) ? x : x*3) | ||
* map(x => isdef(x) ? x : x*3), | ||
* list); | ||
@@ -88,11 +88,11 @@ * ``` | ||
* ``` | ||
* const {type} = require('ferrum');a | ||
* const { type } = require('ferrum'); | ||
* | ||
* class Bar {}; | ||
* | ||
* type(null) # => null | ||
* type(undefined) # => undefined | ||
* type(42) # => Number | ||
* type(new Number(42)) # => Number | ||
* type(new Bar()) # => Bar | ||
* type(null); // => null | ||
* type(undefined); // => undefined | ||
* type(42); // => Number | ||
* type(new Number(42)); // => Number | ||
* type(new Bar()); // => Bar | ||
* | ||
@@ -103,3 +103,3 @@ * // The usual strategy to get the type is this | ||
* // Which fails for null and undefined... | ||
* null.constructor | ||
* //null.constructor | ||
* // Thrown: | ||
@@ -129,6 +129,6 @@ * // TypeError: Cannot read property 'constructor' of null | ||
* | ||
* typename(type(null)) # => "null" | ||
* typename(type(undefined)) # => "undefined" | ||
* typename(type(42)) # => "Number" | ||
* typename(Bar) # => "Bar" | ||
* typename(type(null)); // => "null" | ||
* typename(type(undefined)); // => "undefined" | ||
* typename(type(42)); // => "Number" | ||
* typename(Bar); // => "Bar" | ||
* | ||
@@ -139,4 +139,4 @@ * // The usual strategy to get the name of a value's type is this | ||
* // But this obviously fails for null & undefined | ||
* null.constructor.name | ||
* null.name // still throws | ||
* //null.constructor.name | ||
* //null.name // still throws | ||
* ``` | ||
@@ -159,7 +159,7 @@ * | ||
* | ||
* isPrimitive(null) # => true | ||
* isPrimitive(undefined) # => true | ||
* isPrimitive(42) # => true | ||
* isPrimitive({}) # => false | ||
* isPrimitive(new Number(42)) # => false | ||
* isPrimitive(null); // => true | ||
* isPrimitive(undefined); // => true | ||
* isPrimitive(42); // => true | ||
* isPrimitive({}); // => false | ||
* isPrimitive(new Number(42)); // => false | ||
* ``` | ||
@@ -166,0 +166,0 @@ * |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
160232
15
4054
633
28