@pacote/linked-list
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.5.1](https://github.com/PacoteJS/pacote/compare/@pacote/linked-list@0.5.0...@pacote/linked-list@0.5.1) (2022-05-19) | ||
**Note:** Version bump only for package @pacote/linked-list | ||
# [0.5.0](https://github.com/PacoteJS/pacote/compare/@pacote/linked-list@0.4.8...@pacote/linked-list@0.5.0) (2021-08-13) | ||
@@ -8,0 +16,0 @@ |
@@ -12,7 +12,7 @@ "use strict"; | ||
.reverse() | ||
.reduce(function (list, value) { return core_1.prepend(value, list); }, core_1.emptyList()); | ||
.reduce(function (list, value) { return (0, core_1.prepend)(value, list); }, (0, core_1.emptyList)()); | ||
} | ||
exports.listOf = listOf; | ||
function toArray(list) { | ||
return core_1.reduce(function (acc, value) { | ||
return (0, core_1.reduce)(function (acc, value) { | ||
acc.push(value); | ||
@@ -19,0 +19,0 @@ return acc; |
@@ -5,7 +5,2 @@ "use strict"; | ||
var option_1 = require("@pacote/option"); | ||
var Step; | ||
(function (Step) { | ||
Step[Step["Increment"] = 1] = "Increment"; | ||
Step[Step["Decrement"] = -1] = "Decrement"; | ||
})(Step || (Step = {})); | ||
function car(cons) { | ||
@@ -37,3 +32,3 @@ return cons[0]; | ||
function reduce(callback, initial, list) { | ||
return recursiveReduce(initial, callback, list, Step.Increment, 0, list); | ||
return recursiveReduce(initial, callback, list, 1, 0, list); | ||
} | ||
@@ -59,3 +54,3 @@ exports.reduce = reduce; | ||
var lastIndex = length(list) - 1; | ||
return recursiveReduce(initial, callback, reverse(list), Step.Decrement, lastIndex, list); | ||
return recursiveReduce(initial, callback, reverse(list), -1, lastIndex, list); | ||
} | ||
@@ -82,8 +77,8 @@ exports.reduceRight = reduceRight; | ||
function head(list) { | ||
return isEmpty(list) ? option_1.None : option_1.Some(car(list)); | ||
return isEmpty(list) ? option_1.None : (0, option_1.Some)(car(list)); | ||
} | ||
exports.head = head; | ||
function tail(list) { | ||
return reduce(function (_, value) { return option_1.Some(value); }, option_1.None, list); | ||
return reduce(function (_, value) { return (0, option_1.Some)(value); }, option_1.None, list); | ||
} | ||
exports.tail = tail; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -14,8 +14,8 @@ "use strict"; | ||
_a.next = function () { | ||
if (core_1.isEmpty(current)) { | ||
if ((0, core_1.isEmpty)(current)) { | ||
return { done: true, value: undefined }; | ||
} | ||
else { | ||
var value = result(key++, core_1.car(current)); | ||
current = core_1.cdr(current); | ||
var value = result(key++, (0, core_1.car)(current)); | ||
current = (0, core_1.cdr)(current); | ||
return { done: false, value: value }; | ||
@@ -22,0 +22,0 @@ } |
@@ -7,7 +7,7 @@ "use strict"; | ||
function recursiveFind(predicate, whenFound, whenFinished, current, index) { | ||
return core_1.isEmpty(current) | ||
return (0, core_1.isEmpty)(current) | ||
? whenFinished() | ||
: predicate(core_1.car(current), index) | ||
? whenFound(core_1.car(current), index) | ||
: recursiveFind(predicate, whenFound, whenFinished, core_1.cdr(current), index + 1); | ||
: predicate((0, core_1.car)(current), index) | ||
? whenFound((0, core_1.car)(current), index) | ||
: recursiveFind(predicate, whenFound, whenFinished, (0, core_1.cdr)(current), index + 1); | ||
} | ||
@@ -25,3 +25,3 @@ function find(predicate, list) { | ||
var intIndex = Math.trunc(index); | ||
return get(intIndex >= 0 ? intIndex : core_1.length(list) + intIndex, list); | ||
return get(intIndex >= 0 ? intIndex : (0, core_1.length)(list) + intIndex, list); | ||
} | ||
@@ -49,12 +49,12 @@ exports.at = at; | ||
function indexOf(value, list) { | ||
return recursiveFind(function (current) { return current === value; }, function (_, index) { return option_1.Some(index); }, function () { return option_1.None; }, list, 0); | ||
return recursiveFind(function (current) { return current === value; }, function (_, index) { return (0, option_1.Some)(index); }, function () { return option_1.None; }, list, 0); | ||
} | ||
exports.indexOf = indexOf; | ||
function lastIndexOf(value, list) { | ||
return option_1.map(function (lastIndex) { return core_1.length(list) - lastIndex - 1; })(recursiveFind(function (current) { return current === value; }, function (_, index) { return option_1.Some(index); }, function () { return option_1.None; }, core_1.reverse(list), 0)); | ||
return (0, option_1.map)(function (lastIndex) { return (0, core_1.length)(list) - lastIndex - 1; })(recursiveFind(function (current) { return current === value; }, function (_, index) { return (0, option_1.Some)(index); }, function () { return option_1.None; }, (0, core_1.reverse)(list), 0)); | ||
} | ||
exports.lastIndexOf = lastIndexOf; | ||
function findIndex(predicate, list) { | ||
return recursiveFind(function (current, index) { return predicate(current, index, list); }, function (_, index) { return option_1.Some(index); }, function () { return option_1.None; }, list, 0); | ||
return recursiveFind(function (current, index) { return predicate(current, index, list); }, function (_, index) { return (0, option_1.Some)(index); }, function () { return option_1.None; }, list, 0); | ||
} | ||
exports.findIndex = findIndex; |
@@ -37,14 +37,14 @@ "use strict"; | ||
function merge(compare, result, left, right) { | ||
return core_1.isEmpty(left) || core_1.isEmpty(right) | ||
? core_1.concat(core_1.reverse(result), core_1.concat(left, right)) | ||
: compare(core_1.car(left), core_1.car(right)) > 0 | ||
? merge(compare, core_1.prepend(core_1.car(right), result), left, core_1.cdr(right)) | ||
: merge(compare, core_1.prepend(core_1.car(left), result), core_1.cdr(left), right); | ||
return (0, core_1.isEmpty)(left) || (0, core_1.isEmpty)(right) | ||
? (0, core_1.concat)((0, core_1.reverse)(result), (0, core_1.concat)(left, right)) | ||
: compare((0, core_1.car)(left), (0, core_1.car)(right)) > 0 | ||
? merge(compare, (0, core_1.prepend)((0, core_1.car)(right), result), left, (0, core_1.cdr)(right)) | ||
: merge(compare, (0, core_1.prepend)((0, core_1.car)(left), result), (0, core_1.cdr)(left), right); | ||
} | ||
function mergeSort(compare, list) { | ||
if (core_1.isEmpty(core_1.cdr(list))) { | ||
if ((0, core_1.isEmpty)((0, core_1.cdr)(list))) { | ||
return list; | ||
} | ||
var middle = Math.ceil(core_1.length(list) / 2); | ||
return merge(compare, array_1.listOf(), mergeSort(compare, sublists_1.take(middle, list)), mergeSort(compare, sublists_1.drop(middle, list))); | ||
var middle = Math.ceil((0, core_1.length)(list) / 2); | ||
return merge(compare, (0, array_1.listOf)(), mergeSort(compare, (0, sublists_1.take)(middle, list)), mergeSort(compare, (0, sublists_1.drop)(middle, list))); | ||
} | ||
@@ -51,0 +51,0 @@ function sort(compareOrList, listOrNothing) { |
@@ -7,12 +7,12 @@ "use strict"; | ||
function drop(offset, list) { | ||
return offset > 0 ? drop(offset - 1, core_1.cdr(list)) : list; | ||
return offset > 0 ? drop(offset - 1, (0, core_1.cdr)(list)) : list; | ||
} | ||
exports.drop = drop; | ||
function recursiveTake(acc, offset, list) { | ||
return offset > 0 && !core_1.isEmpty(list) | ||
? recursiveTake(core_1.prepend(core_1.car(list), acc), offset - 1, core_1.cdr(list)) | ||
: core_1.reverse(acc); | ||
return offset > 0 && !(0, core_1.isEmpty)(list) | ||
? recursiveTake((0, core_1.prepend)((0, core_1.car)(list), acc), offset - 1, (0, core_1.cdr)(list)) | ||
: (0, core_1.reverse)(acc); | ||
} | ||
function take(offset, list) { | ||
return recursiveTake(core_1.emptyList(), offset, list); | ||
return recursiveTake((0, core_1.emptyList)(), offset, list); | ||
} | ||
@@ -28,12 +28,12 @@ exports.take = take; | ||
function remove(index, list) { | ||
return core_1.concat(take(index, list), drop(index + 1, list)); | ||
return (0, core_1.concat)(take(index, list), drop(index + 1, list)); | ||
} | ||
exports.remove = remove; | ||
function unique(list) { | ||
return core_1.reverse(core_1.reduce(function (uniqueValues, value) { | ||
return search_1.includes(value, uniqueValues) | ||
return (0, core_1.reverse)((0, core_1.reduce)(function (uniqueValues, value) { | ||
return (0, search_1.includes)(value, uniqueValues) | ||
? uniqueValues | ||
: core_1.prepend(value, uniqueValues); | ||
}, core_1.emptyList(), list)); | ||
: (0, core_1.prepend)(value, uniqueValues); | ||
}, (0, core_1.emptyList)(), list)); | ||
} | ||
exports.unique = unique; |
import { None, Some } from '@pacote/option'; | ||
var Step; | ||
(function (Step) { | ||
Step[Step["Increment"] = 1] = "Increment"; | ||
Step[Step["Decrement"] = -1] = "Decrement"; | ||
})(Step || (Step = {})); | ||
export function car(cons) { | ||
@@ -28,3 +23,3 @@ return cons[0]; | ||
export function reduce(callback, initial, list) { | ||
return recursiveReduce(initial, callback, list, Step.Increment, 0, list); | ||
return recursiveReduce(initial, callback, list, 1, 0, list); | ||
} | ||
@@ -45,3 +40,3 @@ export function reverse(list) { | ||
const lastIndex = length(list) - 1; | ||
return recursiveReduce(initial, callback, reverse(list), Step.Decrement, lastIndex, list); | ||
return recursiveReduce(initial, callback, reverse(list), -1, lastIndex, list); | ||
} | ||
@@ -48,0 +43,0 @@ export function map(callback, list) { |
{ | ||
"name": "@pacote/linked-list", | ||
"description": "Immutable linked lists.", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"sideEffects": false, | ||
@@ -39,3 +39,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "7cb88d9866ea608a24cdb6871284f4235f89750e" | ||
"gitHead": "5b86957bf3ec6c153ff35ccad12ac0c2e2454212" | ||
} |
@@ -12,7 +12,2 @@ import { None, Option, Some } from '@pacote/option' | ||
enum Step { | ||
Increment = 1, | ||
Decrement = -1, | ||
} | ||
export function car<T>(cons: Cons<T>): T { | ||
@@ -42,3 +37,3 @@ return cons[0] | ||
current: LinkedList<T>, | ||
step: Step, | ||
step: -1 | 1, | ||
index: number, | ||
@@ -64,3 +59,3 @@ collection: LinkedList<T> | ||
): R { | ||
return recursiveReduce(initial, callback, list, Step.Increment, 0, list) | ||
return recursiveReduce(initial, callback, list, 1, 0, list) | ||
} | ||
@@ -93,10 +88,3 @@ | ||
const lastIndex = length(list) - 1 | ||
return recursiveReduce( | ||
initial, | ||
callback, | ||
reverse(list), | ||
Step.Decrement, | ||
lastIndex, | ||
list | ||
) | ||
return recursiveReduce(initial, callback, reverse(list), -1, lastIndex, list) | ||
} | ||
@@ -103,0 +91,0 @@ |
83803
1881