Comparing version
@@ -8,3 +8,3 @@ export declare function setEquals(equals: (a: any, b: any) => boolean): void; | ||
} | ||
export declare function nth<A>(index: number, l: List<A>): A; | ||
export declare function nth<A>(index: number, l: List<A>): A | undefined; | ||
export declare class List<A> { | ||
@@ -11,0 +11,0 @@ bits: number; |
@@ -145,2 +145,5 @@ var branchingFactor = 32; | ||
export function nth(index, l) { | ||
if (index < 0 || l.length <= index) { | ||
return undefined; | ||
} | ||
var prefixSize = getPrefixSize(l); | ||
@@ -1217,2 +1220,5 @@ var suffixSize = getSuffixSize(l); | ||
export function update(index, a, l) { | ||
if (index < 0 || l.length <= index) { | ||
return l; | ||
} | ||
var prefixSize = getPrefixSize(l); | ||
@@ -1237,2 +1243,5 @@ var suffixSize = getSuffixSize(l); | ||
export function adjust(f, index, l) { | ||
if (index < 0 || l.length <= index) { | ||
return l; | ||
} | ||
return update(index, f(nth(index, l)), l); | ||
@@ -1239,0 +1248,0 @@ } |
@@ -8,3 +8,3 @@ export declare function setEquals(equals: (a: any, b: any) => boolean): void; | ||
} | ||
export declare function nth<A>(index: number, l: List<A>): A; | ||
export declare function nth<A>(index: number, l: List<A>): A | undefined; | ||
export declare class List<A> { | ||
@@ -11,0 +11,0 @@ bits: number; |
@@ -148,2 +148,5 @@ "use strict"; | ||
function nth(index, l) { | ||
if (index < 0 || l.length <= index) { | ||
return undefined; | ||
} | ||
var prefixSize = getPrefixSize(l); | ||
@@ -1254,2 +1257,5 @@ var suffixSize = getSuffixSize(l); | ||
function update(index, a, l) { | ||
if (index < 0 || l.length <= index) { | ||
return l; | ||
} | ||
var prefixSize = getPrefixSize(l); | ||
@@ -1275,2 +1281,5 @@ var suffixSize = getSuffixSize(l); | ||
function adjust(f, index, l) { | ||
if (index < 0 || l.length <= index) { | ||
return l; | ||
} | ||
return update(index, f(nth(index, l)), l); | ||
@@ -1277,0 +1286,0 @@ } |
{ | ||
"name": "list", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "Fast purely functional immutable lists.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -486,2 +486,5 @@ <h3 align="center"> | ||
If the index is out of bounds the given list is | ||
returned unchanged. | ||
**Complexity**: `O(log(n))` | ||
@@ -500,2 +503,5 @@ | ||
If the index is out of bounds the given list is | ||
returned unchanged. | ||
**Complexity**: `O(log(n))` | ||
@@ -836,3 +842,4 @@ | ||
Gets the `n`th element of the list. | ||
Gets the `n`th element of the list. If `n` is out of bounds | ||
`undefined` is returned. | ||
@@ -839,0 +846,0 @@ **Complexity**: `O(log(n))`, practically constant |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
316967
0.42%4186
0.43%1078
0.65%