@pacote/linked-list
Advanced tools
Comparing version 0.4.8 to 0.5.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [0.5.0](https://github.com/PacoteJS/pacote/compare/@pacote/linked-list@0.4.8...@pacote/linked-list@0.5.0) (2021-08-13) | ||
### Features | ||
* 🎸 adds at() for consistency with Array method proposal ([0fe27e4](https://github.com/PacoteJS/pacote/commit/0fe27e4b17e23bbcf43afff7c2a50a1d82af7166)) | ||
## [0.4.8](https://github.com/PacoteJS/pacote/compare/@pacote/linked-list@0.4.7...@pacote/linked-list@0.4.8) (2021-04-23) | ||
@@ -8,0 +19,0 @@ |
export { append, cdr as rest, concat, filter, flatMap, head, isEmpty, length, map, prepend, reduce, reduceRight, reverse, tail, } from './core'; | ||
export { listOf, toArray } from './array'; | ||
export { entries, keys, values } from './iterator'; | ||
export { every, find, findIndex, get, includes, item, indexOf, lastIndexOf, some, } from './search'; | ||
export { at, every, find, findIndex, get, includes, item, indexOf, lastIndexOf, some, } from './search'; | ||
export { slice, remove, drop, take, unique } from './sublists'; | ||
export { sort } from './sort'; |
@@ -10,3 +10,3 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports.sort = exports.unique = exports.take = exports.drop = exports.remove = exports.slice = exports.some = exports.lastIndexOf = exports.indexOf = exports.item = exports.includes = exports.get = exports.findIndex = exports.find = exports.every = exports.values = exports.keys = exports.entries = exports.toArray = exports.listOf = exports.tail = exports.reverse = exports.reduceRight = exports.reduce = exports.prepend = exports.map = exports.length = exports.isEmpty = exports.head = exports.flatMap = exports.filter = exports.concat = exports.rest = exports.append = void 0; | ||
exports.sort = exports.unique = exports.take = exports.drop = exports.remove = exports.slice = exports.some = exports.lastIndexOf = exports.indexOf = exports.item = exports.includes = exports.get = exports.findIndex = exports.find = exports.every = exports.at = exports.values = exports.keys = exports.entries = exports.toArray = exports.listOf = exports.tail = exports.reverse = exports.reduceRight = exports.reduce = exports.prepend = exports.map = exports.length = exports.isEmpty = exports.head = exports.flatMap = exports.filter = exports.concat = exports.rest = exports.append = void 0; | ||
var core_1 = require("./core"); | ||
@@ -35,2 +35,3 @@ __createBinding(exports, core_1, "append"); | ||
var search_1 = require("./search"); | ||
__createBinding(exports, search_1, "at"); | ||
__createBinding(exports, search_1, "every"); | ||
@@ -37,0 +38,0 @@ __createBinding(exports, search_1, "find"); |
@@ -5,2 +5,6 @@ import { Option } from '@pacote/option'; | ||
export declare function get<T>(index: number, list: LinkedList<T>): Option<T>; | ||
export declare function at<T>(index: number, list: LinkedList<T>): Option<T>; | ||
/** | ||
* @deprecated Use `at()`. | ||
*/ | ||
export declare function item<T>(index: number, list: LinkedList<T>): Option<T>; | ||
@@ -7,0 +11,0 @@ export declare function every<T>(predicate: PredicateFunction<T>, list: LinkedList<T>): boolean; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.findIndex = exports.lastIndexOf = exports.indexOf = exports.includes = exports.some = exports.every = exports.item = exports.get = exports.find = void 0; | ||
exports.findIndex = exports.lastIndexOf = exports.indexOf = exports.includes = exports.some = exports.every = exports.item = exports.at = exports.get = exports.find = void 0; | ||
var option_1 = require("@pacote/option"); | ||
@@ -22,6 +22,13 @@ var core_1 = require("./core"); | ||
exports.get = get; | ||
function item(index, list) { | ||
function at(index, list) { | ||
var intIndex = Math.trunc(index); | ||
return get(intIndex >= 0 ? intIndex : core_1.length(list) + intIndex, list); | ||
} | ||
exports.at = at; | ||
/** | ||
* @deprecated Use `at()`. | ||
*/ | ||
function item(index, list) { | ||
return at(index, list); | ||
} | ||
exports.item = item; | ||
@@ -28,0 +35,0 @@ function every(predicate, list) { |
export { append, cdr as rest, concat, filter, flatMap, head, isEmpty, length, map, prepend, reduce, reduceRight, reverse, tail, } from './core'; | ||
export { listOf, toArray } from './array'; | ||
export { entries, keys, values } from './iterator'; | ||
export { every, find, findIndex, get, includes, item, indexOf, lastIndexOf, some, } from './search'; | ||
export { at, every, find, findIndex, get, includes, item, indexOf, lastIndexOf, some, } from './search'; | ||
export { slice, remove, drop, take, unique } from './sublists'; | ||
export { sort } from './sort'; |
export { append, cdr as rest, concat, filter, flatMap, head, isEmpty, length, map, prepend, reduce, reduceRight, reverse, tail, } from './core'; | ||
export { listOf, toArray } from './array'; | ||
export { entries, keys, values } from './iterator'; | ||
export { every, find, findIndex, get, includes, item, indexOf, lastIndexOf, some, } from './search'; | ||
export { at, every, find, findIndex, get, includes, item, indexOf, lastIndexOf, some, } from './search'; | ||
export { slice, remove, drop, take, unique } from './sublists'; | ||
export { sort } from './sort'; |
@@ -5,2 +5,6 @@ import { Option } from '@pacote/option'; | ||
export declare function get<T>(index: number, list: LinkedList<T>): Option<T>; | ||
export declare function at<T>(index: number, list: LinkedList<T>): Option<T>; | ||
/** | ||
* @deprecated Use `at()`. | ||
*/ | ||
export declare function item<T>(index: number, list: LinkedList<T>): Option<T>; | ||
@@ -7,0 +11,0 @@ export declare function every<T>(predicate: PredicateFunction<T>, list: LinkedList<T>): boolean; |
@@ -17,6 +17,12 @@ import { None, Some, map } from '@pacote/option'; | ||
} | ||
export function item(index, list) { | ||
export function at(index, list) { | ||
const intIndex = Math.trunc(index); | ||
return get(intIndex >= 0 ? intIndex : length(list) + intIndex, list); | ||
} | ||
/** | ||
* @deprecated Use `at()`. | ||
*/ | ||
export function item(index, list) { | ||
return at(index, list); | ||
} | ||
export function every(predicate, list) { | ||
@@ -23,0 +29,0 @@ return recursiveFind((current, index) => !predicate(current, index, list), () => false, () => true, list, 0); |
{ | ||
"name": "@pacote/linked-list", | ||
"description": "Immutable linked lists.", | ||
"version": "0.4.8", | ||
"version": "0.5.0", | ||
"sideEffects": false, | ||
@@ -37,5 +37,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"@pacote/option": "^2.0.1" | ||
"@pacote/option": "^2.0.2" | ||
}, | ||
"gitHead": "0cea5c17616f55bca656ed02f62c5bd52073c266" | ||
"gitHead": "7cb88d9866ea608a24cdb6871284f4235f89750e" | ||
} |
@@ -134,5 +134,5 @@ # @pacote/linked-list | ||
#### `item<T>(index: number, list: LinkedList<T>): Option<T>` | ||
#### `at<T>(index: number, list: LinkedList<T>): Option<T>` | ||
`item()` behaves like `get()`, except when a negative `index` is | ||
`at()` behaves like `get()`, except when a negative `index` is | ||
provided, in which case it returns an `Option` with the element at the | ||
@@ -139,0 +139,0 @@ provided `index` starting from the end of the list. |
@@ -20,2 +20,3 @@ export { | ||
export { | ||
at, | ||
every, | ||
@@ -22,0 +23,0 @@ find, |
@@ -44,3 +44,3 @@ import { None, Option, Some, map } from '@pacote/option' | ||
export function item<T>(index: number, list: LinkedList<T>): Option<T> { | ||
export function at<T>(index: number, list: LinkedList<T>): Option<T> { | ||
const intIndex = Math.trunc(index) | ||
@@ -50,2 +50,9 @@ return get(intIndex >= 0 ? intIndex : length(list) + intIndex, list) | ||
/** | ||
* @deprecated Use `at()`. | ||
*/ | ||
export function item<T>(index: number, list: LinkedList<T>): Option<T> { | ||
return at(index, list) | ||
} | ||
export function every<T>( | ||
@@ -52,0 +59,0 @@ predicate: PredicateFunction<T>, |
@@ -158,6 +158,6 @@ import * as fc from 'fast-check' | ||
describe('item()', () => { | ||
describe('at()', () => { | ||
test('returns None for empty lists', () => { | ||
const list = L.listOf() | ||
expect(L.item(0, list)).toEqual(None) | ||
expect(L.at(0, list)).toEqual(None) | ||
}) | ||
@@ -167,3 +167,3 @@ | ||
const list = L.listOf(1, 2, 3) | ||
expect(L.item(3, list)).toEqual(None) | ||
expect(L.at(3, list)).toEqual(None) | ||
}) | ||
@@ -173,3 +173,3 @@ | ||
const list = L.listOf(1, 2, 3) | ||
expect(L.item(2, list)).toEqual(Some(3)) | ||
expect(L.at(2, list)).toEqual(Some(3)) | ||
}) | ||
@@ -179,3 +179,3 @@ | ||
const list = L.listOf(1, 2, 3) | ||
expect(L.item(-1, list)).toEqual(Some(3)) | ||
expect(L.at(-1, list)).toEqual(Some(3)) | ||
}) | ||
@@ -185,4 +185,4 @@ | ||
const list = L.listOf(1, 2, 3) | ||
expect(L.item(2.5, list)).toEqual(Some(3)) | ||
expect(L.item(-1.5, list)).toEqual(Some(3)) | ||
expect(L.at(2.5, list)).toEqual(Some(3)) | ||
expect(L.at(-1.5, list)).toEqual(Some(3)) | ||
}) | ||
@@ -189,0 +189,0 @@ }) |
83641
45
1897
Updated@pacote/option@^2.0.2