Comparing version 2.0.16 to 2.0.17
import * as L from "./index"; | ||
import { List } from "./index"; | ||
export { Node, List, list, isList, length, of, empty, first, last, flatten, pop, init, tail, from, toArray, reverse, sort, group, dropRepeats, isEmpty } from "./index"; | ||
export { Node, List, list, isList, length, of, empty, first, last, flatten, pop, init, tail, from, toArray, reverse, backwards, sort, group, dropRepeats, isEmpty } from "./index"; | ||
export interface Curried2<A, B, R> { | ||
(t1: A): (t2: B) => R; | ||
(t1: A, t2: B): R; | ||
(a: A): (b: B) => R; | ||
(a: A, b: B): R; | ||
} | ||
export interface Curried3<A, B, C, R> { | ||
(a: A, b: B, c: C): R; | ||
(a: A, b: B): (c: C) => R; | ||
(a: A): Curried2<B, C, R>; | ||
} | ||
export declare const prepend: typeof L.prepend & (<A>(value: A) => (l: List<A>) => List<A>); | ||
@@ -84,3 +89,3 @@ export declare const append: typeof prepend; | ||
<A>(index: number, f: (value: A) => A): (l: List<A>) => List<A>; | ||
(index: number): (<A>(f: (value: A) => A, l: List<A>) => List<A> & (<A>(f: (value: A) => A) => (l: List<A>) => List<A>)); | ||
(index: number): <A>(f: (value: A) => A, l: List<A>) => List<A> & (<A>(f: (value: A) => A) => (l: List<A>) => List<A>); | ||
}; | ||
@@ -101,1 +106,7 @@ export declare const slice: typeof L.slice & { | ||
}; | ||
export declare const foldlWhile: typeof L.foldlWhile & { | ||
<A, B>(predicate: (acc: B, value: A) => boolean, f: (acc: B, value: A) => B, initial: B): (l: List<A>) => B; | ||
<A, B>(predicate: (acc: B, value: A) => boolean, f: (acc: B, value: A) => B): Curried2<B, List<A>, B>; | ||
<A, B>(predicate: (acc: B, value: A) => boolean): Curried3<(acc: B, value: A) => B, B, List<A>, B>; | ||
}; | ||
export declare const reduceWhile: typeof foldlWhile; |
@@ -22,2 +22,3 @@ "use strict"; | ||
exports.reverse = index_1.reverse; | ||
exports.backwards = index_1.backwards; | ||
exports.sort = index_1.sort; | ||
@@ -50,2 +51,22 @@ exports.group = index_1.group; | ||
} | ||
function curry4(f) { | ||
return function curried(a, b, c, d) { | ||
switch (arguments.length) { | ||
case 4: | ||
return f(a, b, c, d); | ||
case 3: | ||
return function (d) { | ||
return f(a, b, c, d); | ||
}; | ||
case 2: | ||
return curry2(function (c, d) { | ||
return f(a, b, c, d); | ||
}); | ||
default: | ||
return curry3(function (b, c, d) { | ||
return f(a, b, c, d); | ||
}); | ||
} | ||
}; | ||
} | ||
exports.prepend = /*#__PURE__*/curry2(L.prepend); | ||
@@ -112,2 +133,4 @@ exports.append = /*#__PURE__*/curry2(L.append); | ||
exports.insertAll = /*#__PURE__*/curry3(L.insertAll); | ||
exports.zipWith = /*#__PURE__*/curry3(L.zipWith); | ||
exports.zipWith = /*#__PURE__*/curry3(L.zipWith); | ||
exports.foldlWhile = /*#__PURE__*/curry4(L.foldlWhile); | ||
exports.reduceWhile = exports.foldlWhile; |
import * as L from "./index"; | ||
import { List } from "./index"; | ||
export { Node, List, list, isList, length, of, empty, first, last, flatten, pop, init, tail, from, toArray, reverse, sort, group, dropRepeats, isEmpty } from "./index"; | ||
export { Node, List, list, isList, length, of, empty, first, last, flatten, pop, init, tail, from, toArray, reverse, backwards, sort, group, dropRepeats, isEmpty } from "./index"; | ||
export interface Curried2<A, B, R> { | ||
(t1: A): (t2: B) => R; | ||
(t1: A, t2: B): R; | ||
(a: A): (b: B) => R; | ||
(a: A, b: B): R; | ||
} | ||
export interface Curried3<A, B, C, R> { | ||
(a: A, b: B, c: C): R; | ||
(a: A, b: B): (c: C) => R; | ||
(a: A): Curried2<B, C, R>; | ||
} | ||
export declare const prepend: typeof L.prepend & (<A>(value: A) => (l: List<A>) => List<A>); | ||
@@ -84,3 +89,3 @@ export declare const append: typeof prepend; | ||
<A>(index: number, f: (value: A) => A): (l: List<A>) => List<A>; | ||
(index: number): (<A>(f: (value: A) => A, l: List<A>) => List<A> & (<A>(f: (value: A) => A) => (l: List<A>) => List<A>)); | ||
(index: number): <A>(f: (value: A) => A, l: List<A>) => List<A> & (<A>(f: (value: A) => A) => (l: List<A>) => List<A>); | ||
}; | ||
@@ -101,1 +106,7 @@ export declare const slice: typeof L.slice & { | ||
}; | ||
export declare const foldlWhile: typeof L.foldlWhile & { | ||
<A, B>(predicate: (acc: B, value: A) => boolean, f: (acc: B, value: A) => B, initial: B): (l: List<A>) => B; | ||
<A, B>(predicate: (acc: B, value: A) => boolean, f: (acc: B, value: A) => B): Curried2<B, List<A>, B>; | ||
<A, B>(predicate: (acc: B, value: A) => boolean): Curried3<(acc: B, value: A) => B, B, List<A>, B>; | ||
}; | ||
export declare const reduceWhile: typeof foldlWhile; |
import * as L from "./index"; | ||
export { Node, List, list, isList, length, of, empty, first, last, flatten, pop, init, tail, from, toArray, reverse, sort, group, dropRepeats, isEmpty } from "./index"; | ||
export { Node, List, list, isList, length, of, empty, first, last, flatten, pop, init, tail, from, toArray, reverse, backwards, sort, group, dropRepeats, isEmpty } from "./index"; | ||
function curry2(f) { | ||
@@ -26,2 +26,22 @@ return function curried(a, b) { | ||
} | ||
function curry4(f) { | ||
return function curried(a, b, c, d) { | ||
switch (arguments.length) { | ||
case 4: | ||
return f(a, b, c, d); | ||
case 3: | ||
return function (d) { | ||
return f(a, b, c, d); | ||
}; | ||
case 2: | ||
return curry2(function (c, d) { | ||
return f(a, b, c, d); | ||
}); | ||
default: | ||
return curry3(function (b, c, d) { | ||
return f(a, b, c, d); | ||
}); | ||
} | ||
}; | ||
} | ||
export var prepend = /*#__PURE__*/curry2(L.prepend); | ||
@@ -88,2 +108,4 @@ export var append = /*#__PURE__*/curry2(L.append); | ||
export var insertAll = /*#__PURE__*/curry3(L.insertAll); | ||
export var zipWith = /*#__PURE__*/curry3(L.zipWith); | ||
export var zipWith = /*#__PURE__*/curry3(L.zipWith); | ||
export var foldlWhile = /*#__PURE__*/curry4(L.foldlWhile); | ||
export var reduceWhile = foldlWhile; |
@@ -7,3 +7,3 @@ export declare type Sizes = number[] | undefined; | ||
} | ||
export declare class List<A> { | ||
export declare class List<A> implements Iterable<A> { | ||
readonly bits: number; | ||
@@ -18,2 +18,3 @@ readonly offset: number; | ||
} | ||
export declare function backwards<A>(l: List<A>): Iterable<A>; | ||
export declare function list<A>(...elements: A[]): List<A>; | ||
@@ -60,2 +61,4 @@ export declare function empty<A = any>(): List<A>; | ||
export declare const chain: typeof flatMap; | ||
export declare function foldlWhile<A, B>(predicate: (acc: B, value: A) => boolean, f: (acc: B, value: A) => B, initial: B, l: List<A>): B; | ||
export declare const reduceWhile: typeof foldlWhile; | ||
export declare function every<A>(predicate: (a: A) => boolean, l: List<A>): boolean; | ||
@@ -62,0 +65,0 @@ export declare const all: typeof every; |
@@ -0,1 +1,18 @@ | ||
var __extends = this && this.__extends || /*#__PURE__*/function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) { | ||
d.__proto__ = b; | ||
} || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
}; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { | ||
this.constructor = d; | ||
} | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
}(); | ||
var branchingFactor = 32; | ||
@@ -142,3 +159,3 @@ var branchBits = 5; | ||
List.prototype[Symbol.iterator] = function () { | ||
return new ListIterator(this); | ||
return new ForwardListIterator(this); | ||
}; | ||
@@ -152,6 +169,6 @@ return List; | ||
var ListIterator = /*#__PURE__*/function () { | ||
function ListIterator(l) { | ||
function ListIterator(l, direction) { | ||
this.l = l; | ||
this.result = { done: false, value: undefined }; | ||
this.idx = -1; | ||
this.idx = direction === 1 ? -1 : l.length; | ||
this.prefixSize = getPrefixSize(l); | ||
@@ -166,13 +183,19 @@ this.middleSize = l.length - getSuffixSize(l); | ||
this.stack[i] = currentNode; | ||
this.indices[i] = 0; | ||
currentNode = currentNode[0].array; | ||
var idx = direction === 1 ? 0 : currentNode.length - 1; | ||
this.indices[i] = idx; | ||
currentNode = currentNode[idx].array; | ||
} | ||
this.indices[0] = -1; | ||
this.indices[0] -= direction; | ||
} | ||
} | ||
ListIterator.prototype.nextInTree = function () { | ||
var i = 0; | ||
while (++this.indices[i] === this.stack[i].length) { | ||
return ListIterator; | ||
}(); | ||
var ForwardListIterator = /*#__PURE__*/function (_super) { | ||
__extends(ForwardListIterator, _super); | ||
function ForwardListIterator(l) { | ||
return _super.call(this, l, 1) || this; | ||
} | ||
ForwardListIterator.prototype.nextInTree = function () { | ||
for (var i = 0; ++this.indices[i] === this.stack[i].length; ++i) { | ||
this.indices[i] = 0; | ||
++i; | ||
} | ||
@@ -183,3 +206,3 @@ for (; 0 < i; --i) { | ||
}; | ||
ListIterator.prototype.next = function () { | ||
ForwardListIterator.prototype.next = function () { | ||
var newVal; | ||
@@ -200,4 +223,42 @@ var idx = ++this.idx; | ||
}; | ||
return ListIterator; | ||
}(); | ||
return ForwardListIterator; | ||
}(ListIterator); | ||
var BackwardsListIterator = /*#__PURE__*/function (_super) { | ||
__extends(BackwardsListIterator, _super); | ||
function BackwardsListIterator(l) { | ||
return _super.call(this, l, -1) || this; | ||
} | ||
BackwardsListIterator.prototype.prevInTree = function () { | ||
for (var i = 0; this.indices[i] === 0; ++i) {} | ||
--this.indices[i]; | ||
for (; 0 < i; --i) { | ||
var n = this.stack[i][this.indices[i]].array; | ||
this.stack[i - 1] = n; | ||
this.indices[i - 1] = n.length - 1; | ||
} | ||
}; | ||
BackwardsListIterator.prototype.next = function () { | ||
var newVal; | ||
var idx = --this.idx; | ||
if (this.middleSize <= idx) { | ||
newVal = this.l.suffix[idx - this.middleSize]; | ||
} else if (this.prefixSize <= idx) { | ||
this.prevInTree(); | ||
newVal = this.stack[0][this.indices[0]]; | ||
} else if (0 <= idx) { | ||
newVal = this.l.prefix[this.prefixSize - idx - 1]; | ||
} else { | ||
this.result.done = true; | ||
} | ||
this.result.value = newVal; | ||
return this.result; | ||
}; | ||
return BackwardsListIterator; | ||
}(ListIterator); | ||
export function backwards(l) { | ||
var _a; | ||
return _a = {}, _a[Symbol.iterator] = function () { | ||
return new BackwardsListIterator(l); | ||
}, _a; | ||
} | ||
function emptyPushable() { | ||
@@ -756,2 +817,13 @@ return new List(0, 0, 0, [], undefined, []); | ||
} | ||
function foldlWhileCb(a, state) { | ||
if (state.predicate(state.result, a) === false) { | ||
return false; | ||
} | ||
state.result = state.f(state.result, a); | ||
return true; | ||
} | ||
export function foldlWhile(predicate, f, initial, l) { | ||
return foldlCb(foldlWhileCb, { predicate: predicate, f: f, result: initial }, l).result; | ||
} | ||
export var reduceWhile = foldlWhile; | ||
function everyCb(value, state) { | ||
@@ -758,0 +830,0 @@ return state.result = state.predicate(value); |
@@ -20,2 +20,4 @@ export * from "./index"; | ||
reduceRight<B>(f: (value: A, acc: B) => B, initial: B): B; | ||
foldlWhile<B>(predicate: (acc: B, value: A) => boolean, f: (value: A, acc: B) => B, initial: B): B; | ||
reduceWhile<B>(predicate: (acc: B, value: A) => boolean, f: (value: A, acc: B) => B, initial: B): B; | ||
traverse<A, B>(of: Of, f: (a: A) => Applicative<B>): any; | ||
@@ -67,2 +69,3 @@ sequence<A, B>(this: List<Applicative<A>>, of: Of): any; | ||
reverse(): List<A>; | ||
backwards(): Iterable<A>; | ||
zipWith<B, C>(f: (a: A, b: B) => C, bs: List<B>): List<C>; | ||
@@ -69,0 +72,0 @@ zip<B>(bs: List<B>): List<[A, B]>; |
@@ -48,2 +48,6 @@ import { List } from "./fantasy-land"; | ||
List.prototype.reduceRight = List.prototype.foldr; | ||
List.prototype.foldlWhile = function foldlWhile(predicate, f, initial) { | ||
return L.foldlWhile(predicate, f, initial, this); | ||
}; | ||
List.prototype.reduceWhile = List.prototype.foldlWhile; | ||
List.prototype.traverse = function (of, f) { | ||
@@ -182,2 +186,5 @@ return L.traverse(of, f, this); | ||
}; | ||
List.prototype.backwards = function () { | ||
return L.backwards(this); | ||
}; | ||
List.prototype.zipWith = function (f, bs) { | ||
@@ -184,0 +191,0 @@ return L.zipWith(f, this, bs); |
@@ -7,3 +7,3 @@ export declare type Sizes = number[] | undefined; | ||
} | ||
export declare class List<A> { | ||
export declare class List<A> implements Iterable<A> { | ||
readonly bits: number; | ||
@@ -18,2 +18,3 @@ readonly offset: number; | ||
} | ||
export declare function backwards<A>(l: List<A>): Iterable<A>; | ||
export declare function list<A>(...elements: A[]): List<A>; | ||
@@ -60,2 +61,4 @@ export declare function empty<A = any>(): List<A>; | ||
export declare const chain: typeof flatMap; | ||
export declare function foldlWhile<A, B>(predicate: (acc: B, value: A) => boolean, f: (acc: B, value: A) => B, initial: B, l: List<A>): B; | ||
export declare const reduceWhile: typeof foldlWhile; | ||
export declare function every<A>(predicate: (a: A) => boolean, l: List<A>): boolean; | ||
@@ -62,0 +65,0 @@ export declare const all: typeof every; |
"use strict"; | ||
var __extends = this && this.__extends || /*#__PURE__*/function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) { | ||
d.__proto__ = b; | ||
} || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
}; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { | ||
this.constructor = d; | ||
} | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
}(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -145,3 +162,3 @@ var branchingFactor = 32; | ||
List.prototype[Symbol.iterator] = function () { | ||
return new ListIterator(this); | ||
return new ForwardListIterator(this); | ||
}; | ||
@@ -155,6 +172,6 @@ return List; | ||
var ListIterator = /*#__PURE__*/function () { | ||
function ListIterator(l) { | ||
function ListIterator(l, direction) { | ||
this.l = l; | ||
this.result = { done: false, value: undefined }; | ||
this.idx = -1; | ||
this.idx = direction === 1 ? -1 : l.length; | ||
this.prefixSize = getPrefixSize(l); | ||
@@ -169,13 +186,19 @@ this.middleSize = l.length - getSuffixSize(l); | ||
this.stack[i] = currentNode; | ||
this.indices[i] = 0; | ||
currentNode = currentNode[0].array; | ||
var idx = direction === 1 ? 0 : currentNode.length - 1; | ||
this.indices[i] = idx; | ||
currentNode = currentNode[idx].array; | ||
} | ||
this.indices[0] = -1; | ||
this.indices[0] -= direction; | ||
} | ||
} | ||
ListIterator.prototype.nextInTree = function () { | ||
var i = 0; | ||
while (++this.indices[i] === this.stack[i].length) { | ||
return ListIterator; | ||
}(); | ||
var ForwardListIterator = /*#__PURE__*/function (_super) { | ||
__extends(ForwardListIterator, _super); | ||
function ForwardListIterator(l) { | ||
return _super.call(this, l, 1) || this; | ||
} | ||
ForwardListIterator.prototype.nextInTree = function () { | ||
for (var i = 0; ++this.indices[i] === this.stack[i].length; ++i) { | ||
this.indices[i] = 0; | ||
++i; | ||
} | ||
@@ -186,3 +209,3 @@ for (; 0 < i; --i) { | ||
}; | ||
ListIterator.prototype.next = function () { | ||
ForwardListIterator.prototype.next = function () { | ||
var newVal; | ||
@@ -203,4 +226,43 @@ var idx = ++this.idx; | ||
}; | ||
return ListIterator; | ||
}(); | ||
return ForwardListIterator; | ||
}(ListIterator); | ||
var BackwardsListIterator = /*#__PURE__*/function (_super) { | ||
__extends(BackwardsListIterator, _super); | ||
function BackwardsListIterator(l) { | ||
return _super.call(this, l, -1) || this; | ||
} | ||
BackwardsListIterator.prototype.prevInTree = function () { | ||
for (var i = 0; this.indices[i] === 0; ++i) {} | ||
--this.indices[i]; | ||
for (; 0 < i; --i) { | ||
var n = this.stack[i][this.indices[i]].array; | ||
this.stack[i - 1] = n; | ||
this.indices[i - 1] = n.length - 1; | ||
} | ||
}; | ||
BackwardsListIterator.prototype.next = function () { | ||
var newVal; | ||
var idx = --this.idx; | ||
if (this.middleSize <= idx) { | ||
newVal = this.l.suffix[idx - this.middleSize]; | ||
} else if (this.prefixSize <= idx) { | ||
this.prevInTree(); | ||
newVal = this.stack[0][this.indices[0]]; | ||
} else if (0 <= idx) { | ||
newVal = this.l.prefix[this.prefixSize - idx - 1]; | ||
} else { | ||
this.result.done = true; | ||
} | ||
this.result.value = newVal; | ||
return this.result; | ||
}; | ||
return BackwardsListIterator; | ||
}(ListIterator); | ||
function backwards(l) { | ||
var _a; | ||
return _a = {}, _a[Symbol.iterator] = function () { | ||
return new BackwardsListIterator(l); | ||
}, _a; | ||
} | ||
exports.backwards = backwards; | ||
function emptyPushable() { | ||
@@ -788,2 +850,14 @@ return new List(0, 0, 0, [], undefined, []); | ||
} | ||
function foldlWhileCb(a, state) { | ||
if (state.predicate(state.result, a) === false) { | ||
return false; | ||
} | ||
state.result = state.f(state.result, a); | ||
return true; | ||
} | ||
function foldlWhile(predicate, f, initial, l) { | ||
return foldlCb(foldlWhileCb, { predicate: predicate, f: f, result: initial }, l).result; | ||
} | ||
exports.foldlWhile = foldlWhile; | ||
exports.reduceWhile = foldlWhile; | ||
function everyCb(value, state) { | ||
@@ -790,0 +864,0 @@ return state.result = state.predicate(value); |
@@ -20,2 +20,4 @@ export * from "./index"; | ||
reduceRight<B>(f: (value: A, acc: B) => B, initial: B): B; | ||
foldlWhile<B>(predicate: (acc: B, value: A) => boolean, f: (value: A, acc: B) => B, initial: B): B; | ||
reduceWhile<B>(predicate: (acc: B, value: A) => boolean, f: (value: A, acc: B) => B, initial: B): B; | ||
traverse<A, B>(of: Of, f: (a: A) => Applicative<B>): any; | ||
@@ -67,2 +69,3 @@ sequence<A, B>(this: List<Applicative<A>>, of: Of): any; | ||
reverse(): List<A>; | ||
backwards(): Iterable<A>; | ||
zipWith<B, C>(f: (a: A, b: B) => C, bs: List<B>): List<C>; | ||
@@ -69,0 +72,0 @@ zip<B>(bs: List<B>): List<[A, B]>; |
@@ -54,2 +54,6 @@ "use strict"; | ||
fantasy_land_1.List.prototype.reduceRight = fantasy_land_1.List.prototype.foldr; | ||
fantasy_land_1.List.prototype.foldlWhile = function foldlWhile(predicate, f, initial) { | ||
return L.foldlWhile(predicate, f, initial, this); | ||
}; | ||
fantasy_land_1.List.prototype.reduceWhile = fantasy_land_1.List.prototype.foldlWhile; | ||
fantasy_land_1.List.prototype.traverse = function (of, f) { | ||
@@ -188,2 +192,5 @@ return L.traverse(of, f, this); | ||
}; | ||
fantasy_land_1.List.prototype.backwards = function () { | ||
return L.backwards(this); | ||
}; | ||
fantasy_land_1.List.prototype.zipWith = function (f, bs) { | ||
@@ -190,0 +197,0 @@ return L.zipWith(f, this, bs); |
{ | ||
"name": "list", | ||
"version": "2.0.16", | ||
"version": "2.0.17", | ||
"description": "Fast purely functional immutable lists.", | ||
@@ -42,22 +42,22 @@ "author": "Simon Friis Vindum", | ||
"devDependencies": { | ||
"@types/chai": "^4.1.4", | ||
"@types/chai": "^4.1.7", | ||
"@types/mocha": "^5.2.5", | ||
"@types/ramda": "^0.25.38", | ||
"@types/ramda": "^0.25.48", | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.3", | ||
"babel-plugin-annotate-pure-calls": "^0.3.0", | ||
"chai": "4.1.2", | ||
"cherry-pick": "^0.2.1", | ||
"babel-plugin-annotate-pure-calls": "^0.4.0", | ||
"chai": "4.2.0", | ||
"cherry-pick": "^0.3.0", | ||
"codecov": "^3.1.0", | ||
"fast-check": "^1.5.0", | ||
"fast-check": "^1.10.1", | ||
"mocha": "^5.2.0", | ||
"np": "^3.0.4", | ||
"nyc": "^13.0.1", | ||
"prettier": "1.14.2", | ||
"np": "^4.0.2", | ||
"nyc": "^13.2.0", | ||
"prettier": "1.16.4", | ||
"proptest": "0.0.4", | ||
"ramda": "0.25.0", | ||
"source-map-support": "^0.5.9", | ||
"ts-node": "^7.0.1", | ||
"tslint": "^5.11.0", | ||
"typescript": "^3.0.3" | ||
"ramda": "0.26.1", | ||
"source-map-support": "^0.5.10", | ||
"ts-node": "^8.0.2", | ||
"tslint": "^5.12.1", | ||
"typescript": "^3.3.3" | ||
}, | ||
@@ -64,0 +64,0 @@ "files": [ |
107
README.md
@@ -66,3 +66,3 @@ <h3 align="center"> | ||
Land specification. | ||
| Package | Version | Downloads | Dependencies | Dev Deps | Install size | GZIP size | | ||
@@ -121,7 +121,7 @@ | ------- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
You'll probably also end up needing to convert between arrays and | ||
List. You can do that with the functions `fromArray` and `toArray`. | ||
List. You can do that with the functions `from` and `toArray`. | ||
```js | ||
L.toArray(L.list("foo", "bar")); //=> ["foo", "bar"]; | ||
L.fromArray(["foo", "bar"]); //=> L.list("foo", "bar"); | ||
L.from(["foo", "bar"]); //=> L.list("foo", "bar"); | ||
``` | ||
@@ -193,4 +193,4 @@ | ||
And they can be passed to any function that takes an iterable as its | ||
argument. As an example a list can be converted into a native | ||
And they can be passed to any function that takes an iterable as its argument. | ||
As an example a list can be converted into a native | ||
[`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set). | ||
@@ -206,3 +206,5 @@ | ||
Lists also work with [spread syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax). For instance, you can call a function like this. | ||
Lists also work with [spread | ||
syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax). | ||
For instance, you can call a function like this. | ||
@@ -213,4 +215,9 @@ ```js | ||
And each element of the list will be passed as an argument to `console.log`. | ||
Then each element of the list will be passed as an argument to `console.log`. | ||
List also suports iterating backwards over lists through the | ||
[`backwards`](#backwards) function. | ||
### Iterator anti-patterns | ||
The iterable protocol allows for some very convenient patterns and | ||
@@ -276,20 +283,18 @@ means that lists can integrate nicely with JavaScript syntax. But, | ||
List. The list below keeps track of how many of Ramda functions that | ||
are missing and of how many that are already implemented. Currently 60 | ||
are missing and of how many that are already implemented. Currently 61 | ||
out of 76 functions have been implemented. | ||
Implemented: `adjust`, `all`, `any`, `append`, `chain`, `concat`, | ||
`contains`, `drop`, `dropLast`, `dropRepeats`, `dropRepeatsWith`, | ||
`dropWhile`, `filter`, `find`, `findIndex`, `findLast`, `group`, | ||
`groupWith`, `head`, `flatten`, `indexOf`, `intersperse`, `init`, | ||
`insert`, `insertAll`, `last`, `lastIndexOf`, `length`, `join`, `map`, | ||
`none`, `nth`, `pair`, `partition`, `pluck`, `prepend`, `range`, | ||
`reduce`, `reduceRight`, `reject`, `remove`, `reverse`, `repeat`, | ||
`scan`, `sequence`, `slice`, `sort`, `splitAt`, `splitEvery`, | ||
`splitWhen`, `take`, `takeWhile`, `tail`, `takeLast`,`takeLastWhile`, | ||
`traverse`, `times`, `update`, `zip`, `zipWith`. | ||
Implemented: `adjust`, `all`, `any`, `append`, `chain`, `concat`, `contains`, | ||
`drop`, `dropLast`, `dropRepeats`, `dropRepeatsWith`, `dropWhile`, `filter`, | ||
`find`, `findIndex`, `findLast`, `group`, `groupWith`, `head`, `flatten`, | ||
`indexOf`, `intersperse`, `init`, `insert`, `insertAll`, `last`, `lastIndexOf`, | ||
`length`, `join`, `map`, `none`, `nth`, `pair`, `partition`, `pluck`, | ||
`prepend`, `range`, `reduce`, `reduceRight`, `reduceWhile`, `reject`, `remove`, | ||
`reverse`, `repeat`, `scan`, `sequence`, `slice`, `sort`, `splitAt`, | ||
`splitEvery`, `splitWhen`, `take`, `takeWhile`, `tail`, | ||
`takeLast`,`takeLastWhile`, `traverse`, `times`, `update`, `zip`, `zipWith`. | ||
Not implemented: `aperture`, `dropLastWhile`, `endsWith`, | ||
`findLastIndex`, `indexBy`, `mapAccum`, `mapAccumRight`, | ||
`reduceWhile`, `startsWith`, `transpose`, `unfold`, `uniq`, `uniqBy`, | ||
`uniqWith`, `unnest` `without`, `xprod`. | ||
Not implemented: `aperture`, `dropLastWhile`, `endsWith`, `findLastIndex`, | ||
`indexBy`, `mapAccum`, `mapAccumRight`, `startsWith`, `transpose`, `unfold`, | ||
`uniq`, `uniqBy`, `uniqWith`, `unnest` `without`, `xprod`. | ||
@@ -392,5 +397,5 @@ ### Differences compared to Ramda | ||
### `fromArray` | ||
### `from` | ||
Converts an array or anything that is array-like into a list. | ||
Converts an array, an array-like or an itearble into a list. | ||
@@ -402,17 +407,5 @@ **Complexity**: `O(n)` | ||
```js | ||
fromArray([0, 1, 2, 3, 4]); //=> list(0, 1, 2, 3, 4) | ||
from([0, 1, 2, 3, 4]); //=> list(0, 1, 2, 3, 4) | ||
``` | ||
### `fromIterable` | ||
Converts any iterable into a list. | ||
**Complexity**: `O(n)` | ||
**Example** | ||
```js | ||
fromIterable(new Set([0, 1, 2, 3]); //=> list(0, 1, 2, 3) | ||
``` | ||
### `range` | ||
@@ -1093,2 +1086,21 @@ | ||
### `backwards` | ||
Returns an iterable that iterates backwards over the given list. | ||
**Complexity**: `O(1)` | ||
**Example** | ||
```js | ||
const l = list(0, 1, 2, 3, 4) | ||
for (const n of backwards(l)) { | ||
if (l < 2) { | ||
break; | ||
} | ||
console.log(l); | ||
} | ||
// => logs 4, 3, and then 2 | ||
``` | ||
### `nth` | ||
@@ -1181,2 +1193,23 @@ | ||
### `foldlWhile` | ||
Similar to `foldl`. But, for each element it calls the predicate function | ||
_before_ the folding function and stops folding if it returns `false`. | ||
**Aliases**: `reduceWhile` | ||
**Complexity**: `O(n)` | ||
**Example** | ||
```js | ||
const isOdd = (_acc:, x) => x % 2 === 1; | ||
const xs = L.list(1, 3, 5, 60, 777, 800); | ||
foldlWhile(isOdd, (n, m) => n + m, 0, xs) //=> 9 | ||
const ys = L.list(2, 4, 6); | ||
foldlWhile(isOdd, (n, m) => n + m, 111, ys) //=> 111 | ||
``` | ||
### `scan` | ||
@@ -1183,0 +1216,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
223588
4941
1435