From c4769b6911453b0cee3c6da9f2c865eb04add9ea Mon Sep 17 00:00:00 2001 From: Michael Arnaldi Date: Wed, 28 Sep 2022 17:27:53 +0000 Subject: [PATCH 1/2] chore: cleanup array and fix mutable comparison --- .changeset/short-berries-raise.md | 6 ++++ packages/stdlib/_examples/main.ts | 2 +- .../_src/collections/Chunk/definition.ts | 16 +++++------ .../_src/collections/Collection/definition.ts | 28 ++++++++++++++++++- .../_src/collections/Collection/functions.ts | 7 +++++ .../collections/HashMap/_internal/array.ts | 6 ++-- .../collections/HashMap/_internal/node.ts | 2 +- .../stdlib/_src/collections/ImmutableArray.ts | 1 - .../collections/ImmutableArray/immutable.ts | 6 ---- .../stdlib/_src/collections/List/sortWith.ts | 2 +- .../collections/RedBlackTree/removeFirst.ts | 2 +- packages/stdlib/_src/collections/mutable.ts | 1 - .../stdlib/_src/collections/mutable/Array.ts | 7 ----- .../_src/collections/mutable/Array/alloc.ts | 6 ---- .../collections/mutable/Array/definition.ts | 11 -------- .../_src/collections/mutable/Array/empty.ts | 6 ---- .../_src/collections/mutable/Array/from.ts | 6 ---- .../_src/collections/mutable/Array/make.ts | 9 ------ .../collections/mutable/DoublyLinkedList.ts | 10 ++++++- .../_src/collections/mutable/ListBuffer.ts | 10 ++++++- .../mutable/MutableHashMap/definition.ts | 10 ++++++- .../mutable/MutableHashSet/definition.ts | 10 ++++++- .../mutable/MutableQueue/_internal/Bounded.ts | 8 ++++++ .../MutableQueue/_internal/Unbounded.ts | 10 ++++++- .../mutable/MutableQueue/definition.ts | 2 +- packages/stdlib/_src/structure/Hash.ts | 12 ++++++++ packages/stdlib/_test/ImmutableArray.test.ts | 4 +-- 27 files changed, 123 insertions(+), 77 deletions(-) create mode 100644 .changeset/short-berries-raise.md delete mode 100644 packages/stdlib/_src/collections/ImmutableArray/immutable.ts delete mode 100644 packages/stdlib/_src/collections/mutable/Array.ts delete mode 100644 packages/stdlib/_src/collections/mutable/Array/alloc.ts delete mode 100644 packages/stdlib/_src/collections/mutable/Array/definition.ts delete mode 100644 packages/stdlib/_src/collections/mutable/Array/empty.ts delete mode 100644 packages/stdlib/_src/collections/mutable/Array/from.ts delete mode 100644 packages/stdlib/_src/collections/mutable/Array/make.ts diff --git a/.changeset/short-berries-raise.md b/.changeset/short-berries-raise.md new file mode 100644 index 00000000..a86739bf --- /dev/null +++ b/.changeset/short-berries-raise.md @@ -0,0 +1,6 @@ +--- +"@tsplus/stdlib": patch +"@tsplus/runtime": patch +--- + +Cleanup Array and fix mutable comparison diff --git a/packages/stdlib/_examples/main.ts b/packages/stdlib/_examples/main.ts index 918e4886..fd66b371 100644 --- a/packages/stdlib/_examples/main.ts +++ b/packages/stdlib/_examples/main.ts @@ -1,5 +1,5 @@ console.log(ImmutableArray.from(List(0, 1, 2)) == ImmutableArray(0, 1, 2)) -console.log([0, 1, 2].immutable == ImmutableArray(0, 1, 2)) +console.log(ImmutableArray.from([0, 1, 2]) == ImmutableArray(0, 1, 2)) console.log( pipe( Maybe(0), diff --git a/packages/stdlib/_src/collections/Chunk/definition.ts b/packages/stdlib/_src/collections/Chunk/definition.ts index 3f5640de..91747af4 100644 --- a/packages/stdlib/_src/collections/Chunk/definition.ts +++ b/packages/stdlib/_src/collections/Chunk/definition.ts @@ -85,7 +85,7 @@ export abstract class ChunkInternal implements Chunk, Equals { if (this.arrayLikeCache) { return this.arrayLikeCache as IterableArrayLike } - const arr = this.binary ? alloc(this.length) : Array.alloc(this.length) + const arr = this.binary ? alloc(this.length) : new Array(this.length) this._copyToArray(0, arr) this.arrayLikeCache = arr @@ -98,7 +98,7 @@ export abstract class ChunkInternal implements Chunk, Equals { if (this.arrayCache) { return this.arrayCache as readonly A[] } - const arr = Array.alloc(this.length) + const arr = new Array(this.length) this._copyToArray(0, arr) this.arrayCache = arr return arr @@ -178,14 +178,14 @@ export abstract class ChunkInternal implements Chunk, Equals { _append(a1: A1): ChunkInternal { const binary = this.binary && isByte(a1) - const buffer = this.binary && binary ? alloc(BufferSize) : Array.alloc(BufferSize) + const buffer = this.binary && binary ? alloc(BufferSize) : new Array(BufferSize) buffer[0] = a1 return new AppendN(this, buffer, 1, new AtomicNumber(1), this.binary && binary) } _prepend(a1: A1): ChunkInternal { const binary = this.binary && isByte(a1) - const buffer = this.binary && binary ? alloc(BufferSize) : Array.alloc(BufferSize) + const buffer = this.binary && binary ? alloc(BufferSize) : new Array(BufferSize) buffer[BufferSize - 1] = a1 return new PrependN(this, buffer, 1, new AtomicNumber(1), this.binary && binary) } @@ -409,7 +409,7 @@ export class AppendN extends ChunkInternal { this.chain.compareAndSet(this.bufferUsed, this.bufferUsed + 1) ) { if (this.binary && !binary) { - const buffer = Array.alloc(BufferSize) + const buffer = new Array(BufferSize) for (let i = 0; i < BufferSize; i++) { buffer[i] = this.buffer[i] } @@ -431,7 +431,7 @@ export class AppendN extends ChunkInternal { this.binary && binary ) } else { - const buffer = this.binary && binary ? alloc(BufferSize) : Array.alloc(BufferSize) + const buffer = this.binary && binary ? alloc(BufferSize) : new Array(BufferSize) buffer[0] = a1 const chunk = array_(this.buffer as A1[])._take(this.bufferUsed) return new AppendN( @@ -901,7 +901,7 @@ export class PrependN extends ChunkInternal { this.chain.compareAndSet(this.bufferUsed, this.bufferUsed + 1) ) { if (this.binary && !binary) { - const buffer = Array.alloc(BufferSize) + const buffer = new Array(BufferSize) for (let i = 0; i < BufferSize; i++) { buffer[i] = this.buffer[i] } @@ -917,7 +917,7 @@ export class PrependN extends ChunkInternal { this.binary && binary ) } else { - const buffer = binary ? alloc(BufferSize) : Array.alloc(BufferSize) + const buffer = binary ? alloc(BufferSize) : new Array(BufferSize) buffer[BufferSize - 1] = a1 const chunk = array_( "subarray" in this.buffer diff --git a/packages/stdlib/_src/collections/Collection/definition.ts b/packages/stdlib/_src/collections/Collection/definition.ts index 87fe7e56..c2063d24 100644 --- a/packages/stdlib/_src/collections/Collection/definition.ts +++ b/packages/stdlib/_src/collections/Collection/definition.ts @@ -3,11 +3,37 @@ declare global { * @tsplus type Collection */ export interface Iterable {} - + /** + * @tsplus type Map + */ export interface Map extends Iterable<[K, V]> {} + /** + * @tsplus type Set + */ export interface Set extends Iterable {} + /** + * @tsplus type Array + */ export interface Array extends Iterable {} + /** + * @tsplus type ReadonlyArray + */ export interface ReadonlyArray extends Iterable {} + /** + * @tsplus type Array.Ops + */ + export interface ArrayConstructor { + } + /** + * @tsplus type Set.Ops + */ + export interface SetConstructor { + } + /** + * @tsplus type Map.Ops + */ + export interface MapConstructor { + } } export type Collection = ESIterable diff --git a/packages/stdlib/_src/collections/Collection/functions.ts b/packages/stdlib/_src/collections/Collection/functions.ts index 8e371c26..94f72f44 100644 --- a/packages/stdlib/_src/collections/Collection/functions.ts +++ b/packages/stdlib/_src/collections/Collection/functions.ts @@ -457,3 +457,10 @@ export function equals(that: Collection) { export function make(...as: A): Collection { return as } + +/** + * @tsplus getter Collection toArray + */ +export function toArray(data: Collection): Array { + return Array.from(data) +} diff --git a/packages/stdlib/_src/collections/HashMap/_internal/array.ts b/packages/stdlib/_src/collections/HashMap/_internal/array.ts index 9e0b84c1..a46d7be0 100644 --- a/packages/stdlib/_src/collections/HashMap/_internal/array.ts +++ b/packages/stdlib/_src/collections/HashMap/_internal/array.ts @@ -2,7 +2,7 @@ export function arrayUpdate(mutate: boolean, at: number, v: A, arr: A[]) { let out = arr if (!mutate) { const len = arr.length - out = Array.alloc(len) + out = new Array(len) for (let i = 0; i < len; ++i) out[i] = arr[i]! } out[at] = v @@ -17,7 +17,7 @@ export function arraySpliceOut(mutate: boolean, at: number, arr: A[]) { if (mutate) { i = g = at } else { - out = Array.alloc(newLen) + out = new Array(newLen) while (i < at) out[g++] = arr[i++]! } ;++i @@ -38,7 +38,7 @@ export function arraySpliceIn(mutate: boolean, at: number, v: A, arr: A[]) { } let i = 0, g = 0 - const out = Array.alloc(len + 1) + const out = new Array(len + 1) while (i < at) out[g++] = arr[i++]! out[at] = v while (i < len) out[++g] = arr[i++]! diff --git a/packages/stdlib/_src/collections/HashMap/_internal/node.ts b/packages/stdlib/_src/collections/HashMap/_internal/node.ts index ba4be95f..0954a356 100644 --- a/packages/stdlib/_src/collections/HashMap/_internal/node.ts +++ b/packages/stdlib/_src/collections/HashMap/_internal/node.ts @@ -319,7 +319,7 @@ function pack( removed: number, elements: Node[] ) { - const children = Array.alloc>(count - 1) + const children = new Array>(count - 1) let g = 0 let bitmap = 0 for (let i = 0, len = elements.length; i < len; ++i) { diff --git a/packages/stdlib/_src/collections/ImmutableArray.ts b/packages/stdlib/_src/collections/ImmutableArray.ts index a911644e..863049a4 100644 --- a/packages/stdlib/_src/collections/ImmutableArray.ts +++ b/packages/stdlib/_src/collections/ImmutableArray.ts @@ -25,7 +25,6 @@ export * from "@tsplus/stdlib/collections/ImmutableArray/getAssociative" export * from "@tsplus/stdlib/collections/ImmutableArray/getAssociativeIdentity" export * from "@tsplus/stdlib/collections/ImmutableArray/getEquivalence" export * from "@tsplus/stdlib/collections/ImmutableArray/getOrd" -export * from "@tsplus/stdlib/collections/ImmutableArray/immutable" export * from "@tsplus/stdlib/collections/ImmutableArray/instances" export * from "@tsplus/stdlib/collections/ImmutableArray/intersection" export * from "@tsplus/stdlib/collections/ImmutableArray/isEmpty" diff --git a/packages/stdlib/_src/collections/ImmutableArray/immutable.ts b/packages/stdlib/_src/collections/ImmutableArray/immutable.ts deleted file mode 100644 index 849e52a2..00000000 --- a/packages/stdlib/_src/collections/ImmutableArray/immutable.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @tsplus getter Array immutable - */ -export function immutable(self: Array): ImmutableArray { - return new ImmutableArray(self.slice(0, self.length)) -} diff --git a/packages/stdlib/_src/collections/List/sortWith.ts b/packages/stdlib/_src/collections/List/sortWith.ts index 34b0314c..8dde922e 100644 --- a/packages/stdlib/_src/collections/List/sortWith.ts +++ b/packages/stdlib/_src/collections/List/sortWith.ts @@ -9,7 +9,7 @@ export function sortWith(ord: Ord) { if (len === 1) { b.append(self.unsafeHead!) } else if (len > 1) { - const arr = Array.alloc<[number, A]>(len) + const arr = new Array<[number, A]>(len) copyToArrayWithIndex(self, arr) arr.sort(([i, x], [j, y]) => { const c = ord.compare(x, y) diff --git a/packages/stdlib/_src/collections/RedBlackTree/removeFirst.ts b/packages/stdlib/_src/collections/RedBlackTree/removeFirst.ts index 928f05c1..1a6b811c 100644 --- a/packages/stdlib/_src/collections/RedBlackTree/removeFirst.ts +++ b/packages/stdlib/_src/collections/RedBlackTree/removeFirst.ts @@ -31,7 +31,7 @@ export function removeFirst(key: K) { return self } - const cstack = Array.alloc>(stack.length) + const cstack = new Array>(stack.length) let n = stack[stack.length - 1]! diff --git a/packages/stdlib/_src/collections/mutable.ts b/packages/stdlib/_src/collections/mutable.ts index fdc26abf..837662ef 100644 --- a/packages/stdlib/_src/collections/mutable.ts +++ b/packages/stdlib/_src/collections/mutable.ts @@ -1,4 +1,3 @@ -export * as array from "@tsplus/stdlib/collections/mutable/Array" export * as doublyLinkedList from "@tsplus/stdlib/collections/mutable/DoublyLinkedList" export * as listBuffer from "@tsplus/stdlib/collections/mutable/ListBuffer" export * as mutableHashMap from "@tsplus/stdlib/collections/mutable/MutableHashMap" diff --git a/packages/stdlib/_src/collections/mutable/Array.ts b/packages/stdlib/_src/collections/mutable/Array.ts deleted file mode 100644 index f8315e84..00000000 --- a/packages/stdlib/_src/collections/mutable/Array.ts +++ /dev/null @@ -1,7 +0,0 @@ -// codegen:start {preset: barrel, include: ./Array/*.ts, prefix: "@tsplus/stdlib/collections/mutable"} -export * from "@tsplus/stdlib/collections/mutable/Array/alloc" -export * from "@tsplus/stdlib/collections/mutable/Array/definition" -export * from "@tsplus/stdlib/collections/mutable/Array/empty" -export * from "@tsplus/stdlib/collections/mutable/Array/from" -export * from "@tsplus/stdlib/collections/mutable/Array/make" -// codegen:end diff --git a/packages/stdlib/_src/collections/mutable/Array/alloc.ts b/packages/stdlib/_src/collections/mutable/Array/alloc.ts deleted file mode 100644 index d5cb4187..00000000 --- a/packages/stdlib/_src/collections/mutable/Array/alloc.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @tsplus static Array.Ops alloc - */ -export function alloc(length: number): Array { - return new Array(length) -} diff --git a/packages/stdlib/_src/collections/mutable/Array/definition.ts b/packages/stdlib/_src/collections/mutable/Array/definition.ts deleted file mode 100644 index 789d99c6..00000000 --- a/packages/stdlib/_src/collections/mutable/Array/definition.ts +++ /dev/null @@ -1,11 +0,0 @@ -declare global { - /** - * @tsplus type Array - */ - export interface Array extends Collection {} - /** - * @tsplus type Array.Ops - */ - export interface ArrayConstructor { - } -} diff --git a/packages/stdlib/_src/collections/mutable/Array/empty.ts b/packages/stdlib/_src/collections/mutable/Array/empty.ts deleted file mode 100644 index fcda0856..00000000 --- a/packages/stdlib/_src/collections/mutable/Array/empty.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @tsplus static Array.Ops empty - */ -export function empty(): Array { - return Array() -} diff --git a/packages/stdlib/_src/collections/mutable/Array/from.ts b/packages/stdlib/_src/collections/mutable/Array/from.ts deleted file mode 100644 index 2fb6e61d..00000000 --- a/packages/stdlib/_src/collections/mutable/Array/from.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @tsplus getter Collection toArray - */ -export function from(data: Collection): Array { - return Array.from(data) -} diff --git a/packages/stdlib/_src/collections/mutable/Array/make.ts b/packages/stdlib/_src/collections/mutable/Array/make.ts deleted file mode 100644 index 6d848d58..00000000 --- a/packages/stdlib/_src/collections/mutable/Array/make.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Constructs a new `Array`. - * - * @tsplus static Array.Ops __call - * @tsplus static Array.Ops make - */ -export function make(...data: As): Array { - return Array.from(data) -} diff --git a/packages/stdlib/_src/collections/mutable/DoublyLinkedList.ts b/packages/stdlib/_src/collections/mutable/DoublyLinkedList.ts index 49266ceb..b8c228f1 100644 --- a/packages/stdlib/_src/collections/mutable/DoublyLinkedList.ts +++ b/packages/stdlib/_src/collections/mutable/DoublyLinkedList.ts @@ -14,11 +14,19 @@ type Node = LinkedListNode | undefined /** * @tsplus type DoublyLinkedList */ -export class DoublyLinkedList implements Collection { +export class DoublyLinkedList implements Collection, Equals { public get head(): T | undefined { return this.headN === undefined ? undefined : this.headN.value } + [Hash.sym]() { + return Hash.randomCached(this) + } + + [Equals.sym](that: unknown) { + return this === that + } + public get isEmpty(): boolean { return this.length === 0 } diff --git a/packages/stdlib/_src/collections/mutable/ListBuffer.ts b/packages/stdlib/_src/collections/mutable/ListBuffer.ts index 76edfcc0..7ab6156b 100644 --- a/packages/stdlib/_src/collections/mutable/ListBuffer.ts +++ b/packages/stdlib/_src/collections/mutable/ListBuffer.ts @@ -13,7 +13,7 @@ * @tsplus type ListBuffer * @tsplus companion ListBuffer.Ops */ -export class ListBuffer implements Collection { +export class ListBuffer implements Collection, Equals { private first: List = List.nil() private last0: List.Cons | undefined = undefined private len = 0; @@ -22,6 +22,14 @@ export class ListBuffer implements Collection { return this.first[Symbol.iterator]() } + [Hash.sym]() { + return Hash.randomCached(this) + } + + [Equals.sym](that: unknown) { + return this === that + } + static empty(): ListBuffer { return new ListBuffer() } diff --git a/packages/stdlib/_src/collections/mutable/MutableHashMap/definition.ts b/packages/stdlib/_src/collections/mutable/MutableHashMap/definition.ts index a69f8a3f..9df1ea01 100644 --- a/packages/stdlib/_src/collections/mutable/MutableHashMap/definition.ts +++ b/packages/stdlib/_src/collections/mutable/MutableHashMap/definition.ts @@ -13,7 +13,7 @@ export type _V = typeof _V * @tsplus type MutableHashMap * @tsplus companion MutableHashMap.Ops */ -export class MutableHashMap implements Collection> { +export class MutableHashMap implements Collection>, Equals { readonly [MutableHashMapSym]: MutableHashMapSym = MutableHashMapSym readonly [_K]!: () => K readonly [_V]!: () => V @@ -25,6 +25,14 @@ export class MutableHashMap implements Collection> { return this.length.get } + [Hash.sym]() { + return Hash.randomCached(this) + } + + [Equals.sym](that: unknown) { + return this === that + } + get(k: K): Maybe { const hash = Hash.unknown(k) const arr = this.backingMap.get(hash) diff --git a/packages/stdlib/_src/collections/mutable/MutableHashSet/definition.ts b/packages/stdlib/_src/collections/mutable/MutableHashSet/definition.ts index 596c7e32..0d09809e 100644 --- a/packages/stdlib/_src/collections/mutable/MutableHashSet/definition.ts +++ b/packages/stdlib/_src/collections/mutable/MutableHashSet/definition.ts @@ -2,13 +2,21 @@ * @tsplus type MutableHashSet * @tsplus companion MutableHashSet.Ops */ -export class MutableHashSet implements Collection { +export class MutableHashSet implements Collection, Equals { private backingMap: MutableHashMap constructor() { this.backingMap = MutableHashMap.empty() } + [Hash.sym]() { + return Hash.randomCached(this) + } + + [Equals.sym](that: unknown) { + return this === that + } + get size(): number { return this.backingMap.size } diff --git a/packages/stdlib/_src/collections/mutable/MutableQueue/_internal/Bounded.ts b/packages/stdlib/_src/collections/mutable/MutableQueue/_internal/Bounded.ts index a8956712..ab83c0ac 100644 --- a/packages/stdlib/_src/collections/mutable/MutableQueue/_internal/Bounded.ts +++ b/packages/stdlib/_src/collections/mutable/MutableQueue/_internal/Bounded.ts @@ -14,6 +14,14 @@ export class Bounded implements MutableQueue { this.max = max } + [Hash.sym]() { + return Hash.randomCached(this) + } + + [Equals.sym](that: unknown) { + return this === that + } + get size(): number { return this.queue.length } diff --git a/packages/stdlib/_src/collections/mutable/MutableQueue/_internal/Unbounded.ts b/packages/stdlib/_src/collections/mutable/MutableQueue/_internal/Unbounded.ts index 6010576d..56e7097d 100644 --- a/packages/stdlib/_src/collections/mutable/MutableQueue/_internal/Unbounded.ts +++ b/packages/stdlib/_src/collections/mutable/MutableQueue/_internal/Unbounded.ts @@ -6,7 +6,15 @@ import { export class Unbounded implements MutableQueue { readonly [MutableQueueSym]: MutableQueueSym = MutableQueueSym - private queue = new DoublyLinkedList() + private queue = new DoublyLinkedList(); + + [Hash.sym]() { + return Hash.randomCached(this) + } + + [Equals.sym](that: unknown) { + return this === that + } get size(): number { return this.queue.length diff --git a/packages/stdlib/_src/collections/mutable/MutableQueue/definition.ts b/packages/stdlib/_src/collections/mutable/MutableQueue/definition.ts index 9ceb0083..e674111e 100644 --- a/packages/stdlib/_src/collections/mutable/MutableQueue/definition.ts +++ b/packages/stdlib/_src/collections/mutable/MutableQueue/definition.ts @@ -7,7 +7,7 @@ export type EmptyMutableQueue = typeof EmptyMutableQueue /** * @tsplus type MutableQueue */ -export interface MutableQueue extends Collection { +export interface MutableQueue extends Collection, Equals { readonly [MutableQueueSym]: MutableQueueSym /** diff --git a/packages/stdlib/_src/structure/Hash.ts b/packages/stdlib/_src/structure/Hash.ts index e697617f..49fb772e 100644 --- a/packages/stdlib/_src/structure/Hash.ts +++ b/packages/stdlib/_src/structure/Hash.ts @@ -130,6 +130,18 @@ export function hashRandom(): number { return optimize(randomInt()) } +/** + * @tsplus static Hash.Ops randomCached + */ +export function hashRandomCached(o: object): number { + if (CACHE.has(o)) { + return CACHE.get(o)! + } + const h = optimize(randomInt()) + CACHE.set(o, h) + return h +} + function isZero(value: any): boolean { return value === null || value === void 0 || value === false } diff --git a/packages/stdlib/_test/ImmutableArray.test.ts b/packages/stdlib/_test/ImmutableArray.test.ts index 64b3c871..979d726b 100644 --- a/packages/stdlib/_test/ImmutableArray.test.ts +++ b/packages/stdlib/_test/ImmutableArray.test.ts @@ -86,11 +86,11 @@ describe.concurrent("ImmutableArray", () => { it("equals", () => { assert.isTrue( - [1, 2].immutable + ImmutableArray.from([1, 2]) == ImmutableArray(1, 2) ) assert.isFalse( - [1, 2].immutable + ImmutableArray.from([1, 2]) == ImmutableArray(1, 3) ) }) From 1eb501b2e0b604daa391934e7f74175011817d3d Mon Sep 17 00:00:00 2001 From: Michael Arnaldi Date: Wed, 28 Sep 2022 19:36:53 +0000 Subject: [PATCH 2/2] chore: sniper kill tuple --- .changeset/light-turkeys-taste.md | 5 + packages/stdlib/_examples/associative.ts | 4 +- packages/stdlib/_examples/recursive.ts | 14 +-- packages/stdlib/_src/collections.ts | 1 - .../Chunk/operations/forEachWithIndexF.ts | 2 +- .../collections/Chunk/operations/mapAccum.ts | 10 +- .../collections/Chunk/operations/partition.ts | 3 +- .../Chunk/operations/partitionMap.ts | 3 +- .../Chunk/operations/partitionMapWithIndex.ts | 4 +- .../Chunk/operations/partitionWithIndex.ts | 4 +- .../collections/Chunk/operations/separate.ts | 2 +- .../collections/Chunk/operations/separateF.ts | 2 +- .../Chunk/operations/separateWithIndexF.ts | 2 +- .../collections/Chunk/operations/splitAt.ts | 2 +- .../Chunk/operations/splitWhere.ts | 2 +- .../collections/Chunk/operations/unfold.ts | 2 +- .../collections/Chunk/operations/unzip.ts | 6 +- .../_src/collections/Chunk/operations/zip.ts | 2 +- .../collections/Chunk/operations/zipAll.ts | 8 +- .../Chunk/operations/zipWithIndex.ts | 2 +- .../Chunk/operations/zipWithIndexOffset.ts | 6 +- .../_src/collections/Collection/functions.ts | 3 +- .../collections/HashMap/_internal/hashMap.ts | 14 +-- .../_src/collections/HashMap/definition.ts | 6 +- .../HashMap/operations/collectWithIndex.ts | 2 +- .../HashMap/operations/filterWithIndex.ts | 2 +- .../collections/HashMap/operations/from.ts | 4 +- .../collections/HashMap/operations/keys.ts | 2 +- .../collections/HashMap/operations/make.ts | 6 +- .../HashMap/operations/toCollection.ts | 2 +- .../collections/HashMap/operations/values.ts | 2 +- .../HashMap/patch/operations/diff.ts | 12 +- .../HashSet/operations/partition.ts | 8 +- .../HashSet/patch/operations/diff.ts | 10 +- .../ImmutableArray/forEachWithIndexF.ts | 2 +- .../collections/ImmutableArray/partition.ts | 2 +- .../ImmutableArray/partitionMap.ts | 2 +- .../ImmutableArray/partitionMapWithIndex.ts | 4 +- .../ImmutableArray/partitionWithIndex.ts | 4 +- .../collections/ImmutableArray/separate.ts | 4 +- .../collections/ImmutableArray/separateF.ts | 2 +- .../ImmutableArray/separateWithIndexF.ts | 2 +- .../_src/collections/ImmutableArray/zip.ts | 4 +- .../collections/ImmutableMap/definition.ts | 8 +- .../_src/collections/ImmutableMap/from.ts | 4 +- .../_src/collections/ImmutableMap/make.ts | 6 +- .../collections/ImmutableQueue/dequeue.ts | 6 +- .../collections/ImmutableQueue/splitAt.ts | 7 +- .../stdlib/_src/collections/List/partition.ts | 4 +- .../_src/collections/List/partitionMap.ts | 4 +- .../stdlib/_src/collections/List/splitAt.ts | 2 +- packages/stdlib/_src/collections/Map.ts | 6 - .../stdlib/_src/collections/Map/definition.ts | 11 -- packages/stdlib/_src/collections/Map/empty.ts | 6 - packages/stdlib/_src/collections/Map/from.ts | 8 -- packages/stdlib/_src/collections/Map/make.ts | 14 --- .../_src/collections/ParSeq/definition.ts | 20 ++-- .../stdlib/_src/collections/ParSeq/zip.ts | 2 +- .../collections/RedBlackTree/definition.ts | 13 +-- .../_src/collections/RedBlackTree/first.ts | 4 +- .../_src/collections/RedBlackTree/from.ts | 6 +- .../_src/collections/RedBlackTree/getAt.ts | 4 +- .../_src/collections/RedBlackTree/last.ts | 4 +- .../_src/collections/RedBlackTree/make.ts | 6 +- .../RedBlackTree/reduceWithIndex.ts | 2 +- .../SortedMap/_internal/SortedMapInternal.ts | 2 +- .../_src/collections/SortedMap/definition.ts | 4 +- .../_src/collections/SortedMap/entries.ts | 2 +- .../stdlib/_src/collections/SortedMap/from.ts | 4 +- .../_src/collections/SortedMap/headMaybe.ts | 2 +- .../stdlib/_src/collections/SortedMap/make.ts | 8 +- .../stdlib/_src/collections/SortedSet/from.ts | 3 +- .../_src/collections/SortedSet/partition.ts | 8 +- .../stdlib/_src/collections/Tree/forEachF.ts | 2 +- .../stdlib/_src/collections/Tree/unfold.ts | 4 +- packages/stdlib/_src/collections/Tree/zip.ts | 2 +- .../mutable/MutableHashMap/definition.ts | 12 +- .../mutable/MutableHashMap/from.ts | 4 +- .../mutable/MutableHashMap/make.ts | 6 +- .../mutable/MutableHashSet/definition.ts | 2 +- packages/stdlib/_src/data.ts | 1 - .../stdlib/_src/data/Differ/operations/zip.ts | 37 +++--- packages/stdlib/_src/data/Either/separate.ts | 8 +- packages/stdlib/_src/data/Either/zip.ts | 4 +- .../stdlib/_src/data/Either/zipValidation.ts | 4 +- .../stdlib/_src/data/Maybe/dsl/separateF.ts | 6 +- packages/stdlib/_src/data/Maybe/partition.ts | 9 +- .../stdlib/_src/data/Maybe/partitionMap.ts | 2 +- packages/stdlib/_src/data/Maybe/separate.ts | 6 +- packages/stdlib/_src/data/Maybe/zip.ts | 3 +- packages/stdlib/_src/data/Tuple.ts | 12 -- packages/stdlib/_src/data/Tuple/append.ts | 9 -- packages/stdlib/_src/data/Tuple/at.ts | 9 -- packages/stdlib/_src/data/Tuple/concat.ts | 13 --- packages/stdlib/_src/data/Tuple/definition.ts | 64 ----------- packages/stdlib/_src/data/Tuple/fromNative.ts | 8 -- packages/stdlib/_src/data/Tuple/make.ts | 9 -- packages/stdlib/_src/data/Tuple/mergeTuple.ts | 19 --- packages/stdlib/_src/data/Tuple/prepend.ts | 9 -- packages/stdlib/_src/data/Tuple/toNative.ts | 8 -- packages/stdlib/_src/data/Tuple/update.ts | 29 ----- packages/stdlib/_src/global.ts | 5 - packages/stdlib/_src/io/Eval/tuple.ts | 4 +- packages/stdlib/_src/io/Eval/zip.ts | 2 +- .../stdlib/_src/prelude/AssociativeBoth.ts | 2 +- packages/stdlib/_src/prelude/DSL/apF.ts | 2 +- packages/stdlib/_src/prelude/DSL/getApplyF.ts | 4 +- .../stdlib/_src/prelude/DSL/getValidationF.ts | 4 +- packages/stdlib/_src/prelude/DSL/zip.ts | 4 +- .../stdlib/_src/prelude/Equivalence/tuple.ts | 4 +- .../stdlib/_src/prelude/Equivalence/zip.ts | 4 +- packages/stdlib/_src/prelude/Ord/tuple.ts | 10 +- packages/stdlib/_src/prelude/Partition.ts | 4 +- packages/stdlib/_src/prelude/PartitionMap.ts | 2 +- .../_src/prelude/PartitionMapWithIndex.ts | 2 +- .../stdlib/_src/prelude/PartitionWithIndex.ts | 4 +- packages/stdlib/_src/prelude/Selective.ts | 4 +- packages/stdlib/_src/prelude/Separate.ts | 2 +- packages/stdlib/_src/prelude/Wiltable.ts | 4 +- .../stdlib/_src/prelude/WiltableWithIndex.ts | 4 +- packages/stdlib/_src/utilities/Types.ts | 2 - packages/stdlib/_test/Chunk.test.ts | 108 +++++++++--------- packages/stdlib/_test/Differ.test.ts | 4 +- packages/stdlib/_test/Either.test.ts | 10 +- packages/stdlib/_test/Eval.test.ts | 4 +- packages/stdlib/_test/HashMap.test.ts | 74 ++++++------ packages/stdlib/_test/HashSet.test.ts | 4 +- packages/stdlib/_test/ImmutableArray.test.ts | 30 ++--- packages/stdlib/_test/ImmutableMap.test.ts | 54 ++++----- packages/stdlib/_test/ImmutableQueue.test.ts | 16 +-- packages/stdlib/_test/List.test.ts | 12 +- packages/stdlib/_test/Maybe.test.ts | 26 ++--- packages/stdlib/_test/MutableHashMap.test.ts | 6 +- packages/stdlib/_test/ParSeq.test.ts | 4 +- packages/stdlib/_test/Recursive.test.ts | 30 ++--- packages/stdlib/_test/RedBlackTree.test.ts | 34 +++--- packages/stdlib/_test/SortedMap.test.ts | 54 ++++----- packages/stdlib/_test/SortedSet.test.ts | 4 +- packages/stdlib/_test/Tree.test.ts | 14 +-- 139 files changed, 486 insertions(+), 741 deletions(-) create mode 100644 .changeset/light-turkeys-taste.md delete mode 100644 packages/stdlib/_src/collections/Map.ts delete mode 100644 packages/stdlib/_src/collections/Map/definition.ts delete mode 100644 packages/stdlib/_src/collections/Map/empty.ts delete mode 100644 packages/stdlib/_src/collections/Map/from.ts delete mode 100644 packages/stdlib/_src/collections/Map/make.ts delete mode 100644 packages/stdlib/_src/data/Tuple.ts delete mode 100644 packages/stdlib/_src/data/Tuple/append.ts delete mode 100644 packages/stdlib/_src/data/Tuple/at.ts delete mode 100644 packages/stdlib/_src/data/Tuple/concat.ts delete mode 100644 packages/stdlib/_src/data/Tuple/definition.ts delete mode 100644 packages/stdlib/_src/data/Tuple/fromNative.ts delete mode 100644 packages/stdlib/_src/data/Tuple/make.ts delete mode 100644 packages/stdlib/_src/data/Tuple/mergeTuple.ts delete mode 100644 packages/stdlib/_src/data/Tuple/prepend.ts delete mode 100644 packages/stdlib/_src/data/Tuple/toNative.ts delete mode 100644 packages/stdlib/_src/data/Tuple/update.ts diff --git a/.changeset/light-turkeys-taste.md b/.changeset/light-turkeys-taste.md new file mode 100644 index 00000000..607c7ed2 --- /dev/null +++ b/.changeset/light-turkeys-taste.md @@ -0,0 +1,5 @@ +--- +"@tsplus/stdlib": patch +--- + +Kill Tuple diff --git a/packages/stdlib/_examples/associative.ts b/packages/stdlib/_examples/associative.ts index aa584e47..ee7aa4e2 100644 --- a/packages/stdlib/_examples/associative.ts +++ b/packages/stdlib/_examples/associative.ts @@ -2,10 +2,10 @@ main() function main() { /* one namespace per module with "aliased" constructor! */ - const map0 = VoteMap(HashMap(Tuple("TsPlus", Votes(1)), Tuple("Effect", Votes(2)))) + const map0 = VoteMap(HashMap(["TsPlus", Votes(1)], ["Effect", Votes(2)])) /* configure global imports that are still tree-shakeable */ - const map1 = VoteMap(HashMap(Tuple("TsPlus", Votes(4)), Tuple("Effect-2", Votes(2)))) + const map1 = VoteMap(HashMap(["TsPlus", Votes(4)], ["Effect-2", Votes(2)])) /* custom binary operators */ console.assert(map0.sum(map1) == (map0 + map1)) diff --git a/packages/stdlib/_examples/recursive.ts b/packages/stdlib/_examples/recursive.ts index a8bc43db..94e6dae7 100644 --- a/packages/stdlib/_examples/recursive.ts +++ b/packages/stdlib/_examples/recursive.ts @@ -26,22 +26,22 @@ function main() { // use the string's length to lookup neighboring cells and the answer pops out at the head function editDistance(s: string, t: string) { return pipe( - Tuple(s, t), + [s, t], Recursive.unfold(Functor, substrings(s)), Recursive.$.foldAnnotated(Functor, editDistanceAnnotatedAlgebra(s.length)) ) } function substrings(s0: string): Unfolder.Fn { - return ({ tuple: [s, t] }) => { + return ([s, t]) => { const [, ...ss] = s const [, ...ts] = t switch (s.length) { case 0: return t.length == 0 ? - new Leaf(Tuple("", "")) : - new Node(Tuple("", t), Tuple(s0, ts.join(""))) + new Leaf(["", ""]) : + new Node(["", t], [s0, ts.join("")]) default: - return new Node(Tuple(s, t), Tuple(ss.join(""), t)) + return new Node([s, t], [ss.join(""), t]) } } } @@ -54,7 +54,7 @@ function editDistanceAnnotatedAlgebra(len: number): Annotated.Fn "cons": minDistance }) - function minDistance({ head: { tuple: [[a], [b]] }, tail }: AnnotatedNode): number { + function minDistance({ head: [[a], [b]], tail }: AnnotatedNode): number { return Math.min( lookup(0, tail) + 1, // insert lookup(len, tail) + 1, // delete @@ -72,7 +72,7 @@ function editDistanceAnnotatedAlgebra(len: number): Annotated.Fn } // Type definitions type MyNonEmptyList = Leaf | Node -type Carrier = Tuple<[string, string]> +type Carrier = readonly [string, string] interface ListF extends HKT { readonly type: MyNonEmptyList } diff --git a/packages/stdlib/_src/collections.ts b/packages/stdlib/_src/collections.ts index e1b11343..1c4b9c8b 100644 --- a/packages/stdlib/_src/collections.ts +++ b/packages/stdlib/_src/collections.ts @@ -6,7 +6,6 @@ export * as immutableArray from "@tsplus/stdlib/collections/ImmutableArray" export * as immutableMap from "@tsplus/stdlib/collections/ImmutableMap" export * as immutableQueue from "@tsplus/stdlib/collections/ImmutableQueue" export * as list from "@tsplus/stdlib/collections/List" -export * as map from "@tsplus/stdlib/collections/Map" export * as mutable from "@tsplus/stdlib/collections/mutable" export * as nonEmptyImmutableArray from "@tsplus/stdlib/collections/NonEmptyImmutableArray" export * as parSeq from "@tsplus/stdlib/collections/ParSeq" diff --git a/packages/stdlib/_src/collections/Chunk/operations/forEachWithIndexF.ts b/packages/stdlib/_src/collections/Chunk/operations/forEachWithIndexF.ts index 2646a584..87f2ac5f 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/forEachWithIndexF.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/forEachWithIndexF.ts @@ -10,7 +10,7 @@ export const forEachWithIndexF = ForEachWithIndex.implementForEachWithIndexF, typeof _.R, typeof _.E>(Chunk.empty()) for (let i = 0; i < fa.length; i = i + 1) { base = G.map( - ({ tuple: [bs, b] }: Tuple<[Chunk, typeof _.B]>) => bs.append(b) + ([bs, b]: readonly [Chunk, typeof _.B]) => bs.append(b) )(G.both(f(i, fa.unsafeGet(i)!))(base)) } return base diff --git a/packages/stdlib/_src/collections/Chunk/operations/mapAccum.ts b/packages/stdlib/_src/collections/Chunk/operations/mapAccum.ts index 9b631b93..806872b6 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/mapAccum.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/mapAccum.ts @@ -6,8 +6,8 @@ import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" * @tsplus static Chunk.Aspects mapAccum * @tsplus pipeable Chunk mapAccum */ -export function mapAccum(s: S, f: (s: S, a: A) => Tuple<[S, B]>) { - return (self: Chunk): Tuple<[S, Chunk]> => { +export function mapAccum(s: S, f: (s: S, a: A) => readonly [S, B]) { + return (self: Chunk): readonly [S, Chunk] => { const iterator = concreteChunkId(self)._arrayLikeIterator() let next let s1 = s @@ -20,12 +20,12 @@ export function mapAccum(s: S, f: (s: S, a: A) => Tuple<[S, B]>) { while (i < len) { const a = array[i]! const x = f(s1, a) - s1 = x.get(0) - builder = builder.append(x.get(1)) + s1 = x[0] + builder = builder.append(x[1]) i++ } } - return Tuple(s1, builder) + return [s1, builder] } } diff --git a/packages/stdlib/_src/collections/Chunk/operations/partition.ts b/packages/stdlib/_src/collections/Chunk/operations/partition.ts index b27d16dd..cb20ee29 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/partition.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/partition.ts @@ -5,5 +5,6 @@ * @tsplus pipeable Chunk partition */ export function partition(f: Predicate) { - return (self: Chunk): Tuple<[Chunk, Chunk]> => self.partitionWithIndex((_, a: A) => f(a)) + return (self: Chunk): readonly [Chunk, Chunk] => + self.partitionWithIndex((_, a: A) => f(a)) } diff --git a/packages/stdlib/_src/collections/Chunk/operations/partitionMap.ts b/packages/stdlib/_src/collections/Chunk/operations/partitionMap.ts index 572fe508..01d50f1f 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/partitionMap.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/partitionMap.ts @@ -6,5 +6,6 @@ * @tsplus pipeable Chunk partitionMap */ export function partitionMap(f: (a: A) => Either) { - return (self: Chunk): Tuple<[Chunk, Chunk]> => self.partitionMapWithIndex((_, a) => f(a)) + return (self: Chunk): readonly [Chunk, Chunk] => + self.partitionMapWithIndex((_, a) => f(a)) } diff --git a/packages/stdlib/_src/collections/Chunk/operations/partitionMapWithIndex.ts b/packages/stdlib/_src/collections/Chunk/operations/partitionMapWithIndex.ts index cf78c1e2..08498211 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/partitionMapWithIndex.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/partitionMapWithIndex.ts @@ -6,7 +6,7 @@ * @tsplus pipeable Chunk partitionMapWithIndex */ export function partitionMapWithIndex(f: (i: number, a: A) => Either) { - return (self: Chunk): Tuple<[Chunk, Chunk]> => { + return (self: Chunk): readonly [Chunk, Chunk] => { const left: Array = [] const right: Array = [] for (let i = 0; i < self.length; i++) { @@ -17,6 +17,6 @@ export function partitionMapWithIndex(f: (i: number, a: A) => Either(f: PredicateWithIndex) { - return (self: Chunk): Tuple<[Chunk, Chunk]> => { + return (self: Chunk): readonly [Chunk, Chunk] => { const left: Array = [] const right: Array = [] for (let i = 0; i < self.length; i++) { @@ -17,6 +17,6 @@ export function partitionWithIndex(f: PredicateWithIndex) { left.push(a) } } - return Tuple(Chunk.from(left), Chunk.from(right)) + return [Chunk.from(left), Chunk.from(right)] } } diff --git a/packages/stdlib/_src/collections/Chunk/operations/separate.ts b/packages/stdlib/_src/collections/Chunk/operations/separate.ts index 05dd8ceb..8d9216cf 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/separate.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/separate.ts @@ -3,6 +3,6 @@ * * @tsplus getter Chunk separate */ -export function separate(self: Chunk>): Tuple<[Chunk, Chunk]> { +export function separate(self: Chunk>): readonly [Chunk, Chunk] { return self.partitionMap(identity) } diff --git a/packages/stdlib/_src/collections/Chunk/operations/separateF.ts b/packages/stdlib/_src/collections/Chunk/operations/separateF.ts index d262a83f..dee43036 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/separateF.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/separateF.ts @@ -11,6 +11,6 @@ export const separateF = Wiltable.implementSeparateF()( }) => (G: Applicative) => (f: (a: A) => HKT.Kind>) => - (fa: Chunk): HKT.Kind, Chunk]>> => + (fa: Chunk): HKT.Kind, Chunk]> => G.map((self: Chunk>) => self.separate)(Chunk.forEachF(G)(f)(fa)) ) diff --git a/packages/stdlib/_src/collections/Chunk/operations/separateWithIndexF.ts b/packages/stdlib/_src/collections/Chunk/operations/separateWithIndexF.ts index a2ca234a..a0702349 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/separateWithIndexF.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/separateWithIndexF.ts @@ -14,6 +14,6 @@ export const separateWithIndexF = WiltableWithIndex.implementSeparateWithIndexF< }) => (G: Applicative) => (f: (k: number, a: A) => HKT.Kind>) => - (fa: Chunk): HKT.Kind, Chunk]>> => + (fa: Chunk): HKT.Kind, Chunk]> => G.map((self: Chunk>) => self.separate)(Chunk.forEachWithIndexF(G)(f)(fa)) ) diff --git a/packages/stdlib/_src/collections/Chunk/operations/splitAt.ts b/packages/stdlib/_src/collections/Chunk/operations/splitAt.ts index 079f562c..934df1db 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/splitAt.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/splitAt.ts @@ -5,5 +5,5 @@ * @tsplus pipeable Chunk splitAt */ export function splitAt(n: number) { - return (self: Chunk): Tuple<[Chunk, Chunk]> => Tuple(self.take(n), self.drop(n)) + return (self: Chunk): readonly [Chunk, Chunk] => [self.take(n), self.drop(n)] } diff --git a/packages/stdlib/_src/collections/Chunk/operations/splitWhere.ts b/packages/stdlib/_src/collections/Chunk/operations/splitWhere.ts index 37ae7ade..267dd1b4 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/splitWhere.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/splitWhere.ts @@ -6,7 +6,7 @@ import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" * @tsplus pipeable Chunk splitWhere */ export function splitWhere(f: Predicate) { - return (self: Chunk): Tuple<[Chunk, Chunk]> => { + return (self: Chunk): readonly [Chunk, Chunk] => { const iterator = concreteChunkId(self)._arrayLikeIterator() let next let cont = true diff --git a/packages/stdlib/_src/collections/Chunk/operations/unfold.ts b/packages/stdlib/_src/collections/Chunk/operations/unfold.ts index eab7a2fc..515ab8fa 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/unfold.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/unfold.ts @@ -4,7 +4,7 @@ * * @tsplus static Chunk.Ops unfold */ -export function unfold(s: S, f: (s: S) => Maybe>): Chunk { +export function unfold(s: S, f: (s: S) => Maybe): Chunk { let builder = Chunk.empty() let cont = true let s1 = s diff --git a/packages/stdlib/_src/collections/Chunk/operations/unzip.ts b/packages/stdlib/_src/collections/Chunk/operations/unzip.ts index e6b768d7..15538d02 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/unzip.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/unzip.ts @@ -4,14 +4,14 @@ * * @tsplus getter Chunk unzip */ -export function unzip(as: Chunk>): Tuple<[Chunk, Chunk]> { +export function unzip(as: Chunk): readonly [Chunk, Chunk] { let fa: Chunk = Chunk.empty() let fb: Chunk = Chunk.empty() - as.forEach(({ tuple: [a, b] }) => { + as.forEach(([a, b]) => { fa = fa.append(a) fb = fb.append(b) }) - return Tuple(fa, fb) + return [fa, fb] } diff --git a/packages/stdlib/_src/collections/Chunk/operations/zip.ts b/packages/stdlib/_src/collections/Chunk/operations/zip.ts index 6159fcff..dab3608d 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/zip.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/zip.ts @@ -5,5 +5,5 @@ * @tsplus pipeable Chunk zip */ export function zip(that: Chunk) { - return (self: Chunk): Chunk> => self.zipWith(that, (a, b) => Tuple(a, b)) + return (self: Chunk): Chunk<[A, B]> => self.zipWith(that, (a, b) => [a, b]) } diff --git a/packages/stdlib/_src/collections/Chunk/operations/zipAll.ts b/packages/stdlib/_src/collections/Chunk/operations/zipAll.ts index 862e13d6..b7771988 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/zipAll.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/zipAll.ts @@ -8,12 +8,12 @@ * @tsplus pipeable Chunk zipAll */ export function zipAll(that: Chunk) { - return (self: Chunk): Chunk, Maybe]>> => { + return (self: Chunk): Chunk, Maybe]> => { return self.zipAllWith( that, - (a, b) => Tuple(Maybe.some(a), Maybe.some(b)), - (a) => Tuple(Maybe.some(a), Maybe.none), - (b) => Tuple(Maybe.none, Maybe.some(b)) + (a, b) => [Maybe.some(a), Maybe.some(b)], + (a) => [Maybe.some(a), Maybe.none], + (b) => [Maybe.none, Maybe.some(b)] ) } } diff --git a/packages/stdlib/_src/collections/Chunk/operations/zipWithIndex.ts b/packages/stdlib/_src/collections/Chunk/operations/zipWithIndex.ts index 982cdfd4..d54975ec 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/zipWithIndex.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/zipWithIndex.ts @@ -4,6 +4,6 @@ * * @tsplus getter Chunk zipWithIndex */ -export function zipWithIndex(self: Chunk): Chunk> { +export function zipWithIndex(self: Chunk): Chunk { return self.zipWithIndexOffset(0) } diff --git a/packages/stdlib/_src/collections/Chunk/operations/zipWithIndexOffset.ts b/packages/stdlib/_src/collections/Chunk/operations/zipWithIndexOffset.ts index 9c214882..c736f284 100644 --- a/packages/stdlib/_src/collections/Chunk/operations/zipWithIndexOffset.ts +++ b/packages/stdlib/_src/collections/Chunk/operations/zipWithIndexOffset.ts @@ -8,18 +8,18 @@ import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" * @tsplus pipeable Chunk zipWithIndexOffset */ export function zipWithIndexOffset(offset: number) { - return (self: Chunk): Chunk> => { + return (self: Chunk): Chunk<[A, number]> => { const iterator = concreteChunkId(self)._arrayLikeIterator() let next let i = offset - let builder = Chunk.empty>() + let builder = Chunk.empty<[A, number]>() while ((next = iterator.next()) && !next.done) { const array = next.value const len = array.length let j = 0 while (j < len) { const a = array[j]! - builder = builder.append(Tuple(a, i)) + builder = builder.append([a, i]) j++ i++ } diff --git a/packages/stdlib/_src/collections/Collection/functions.ts b/packages/stdlib/_src/collections/Collection/functions.ts index 94f72f44..64be9f0a 100644 --- a/packages/stdlib/_src/collections/Collection/functions.ts +++ b/packages/stdlib/_src/collections/Collection/functions.ts @@ -102,7 +102,8 @@ export function map(f: (a: A, k: number) => B) { * @tsplus pipeable Collection zip */ export function zip(that: Collection) { - return (self: Collection): Collection> => self.zipWith(that, Tuple.make) + return (self: Collection): Collection => + self.zipWith(that, (a, b) => [a, b]) } /** diff --git a/packages/stdlib/_src/collections/HashMap/_internal/hashMap.ts b/packages/stdlib/_src/collections/HashMap/_internal/hashMap.ts index 131e1ae0..c9734528 100644 --- a/packages/stdlib/_src/collections/HashMap/_internal/hashMap.ts +++ b/packages/stdlib/_src/collections/HashMap/_internal/hashMap.ts @@ -8,7 +8,7 @@ import type { Node } from "@tsplus/stdlib/collections/HashMap/_internal/node" import { isEmptyNode } from "@tsplus/stdlib/collections/HashMap/_internal/node" import { _K, _V, HashMapSym } from "@tsplus/stdlib/collections/HashMap/definition" -export type TraversalFn = (node: Tuple<[K, V]>) => A +export type TraversalFn = (k: K, v: V) => A export type Cont = | [ @@ -37,14 +37,14 @@ export class HashMapInternal implements HashMap { public _size: number ) {} - [Symbol.iterator](): Iterator> { - return new HashMapIterator(this, identity) + [Symbol.iterator](): Iterator { + return new HashMapIterator(this, (k, v) => [k, v]) } [Hash.sym](): number { let hash = Hash.string("HashMap") for (const item of this) { - hash ^= Hash.combine(Hash.unknown(item.get(0)), Hash.unknown(item.get(1))) + hash ^= Hash.combine(Hash.unknown(item[0]), Hash.unknown(item[1])) } return Hash.optimize(hash) } @@ -56,11 +56,11 @@ export class HashMapInternal implements HashMap { return false } for (const item of this) { - const elem = that.getHash(item.get(0), Hash.unknown(item.get(0))) + const elem = that.getHash(item[0], Hash.unknown(item[0])) if (elem.isNone()) { return false } else { - if (!Equals.equals(item.get(1), elem.value)) { + if (!Equals.equals(item[1], elem.value)) { return false } } @@ -114,7 +114,7 @@ export function visitLazy( case "LeafNode": { return node.value.isSome() ? Maybe.some({ - value: f(Tuple(node.key, node.value.value)), + value: f(node.key, node.value.value), cont }) : applyCont(cont) diff --git a/packages/stdlib/_src/collections/HashMap/definition.ts b/packages/stdlib/_src/collections/HashMap/definition.ts index 268cc122..4485d13f 100644 --- a/packages/stdlib/_src/collections/HashMap/definition.ts +++ b/packages/stdlib/_src/collections/HashMap/definition.ts @@ -10,11 +10,11 @@ export type _V = typeof _V /** * @tsplus type HashMap */ -export interface HashMap extends Collection>, Equals { +export interface HashMap extends Collection, Equals { readonly [HashMapSym]: HashMapSym readonly [_K]: () => K readonly [_V]: () => V - [Symbol.iterator](): Iterator> + [Symbol.iterator](): Iterator } /** @@ -47,7 +47,7 @@ export function unifyHashMap>( /** * @tsplus static HashMap.Ops isHashMap */ -export function isHashMap(u: Iterable>): u is HashMap +export function isHashMap(u: Iterable): u is HashMap export function isHashMap(u: unknown): u is HashMap export function isHashMap(u: unknown): u is HashMap { return typeof u === "object" && u != null && HashMapSym in u diff --git a/packages/stdlib/_src/collections/HashMap/operations/collectWithIndex.ts b/packages/stdlib/_src/collections/HashMap/operations/collectWithIndex.ts index 3e261dcd..485888be 100644 --- a/packages/stdlib/_src/collections/HashMap/operations/collectWithIndex.ts +++ b/packages/stdlib/_src/collections/HashMap/operations/collectWithIndex.ts @@ -9,7 +9,7 @@ export function collectWithIndex(f: (k: K, a: A) => Maybe) { return (self: HashMap): HashMap => { const m = HashMap.empty() return m.mutate((m) => { - for (const { tuple: [k, a] } of self) { + for (const [k, a] of self) { const o = f(k, a) if (o.isSome()) { m.set(k, o.value) diff --git a/packages/stdlib/_src/collections/HashMap/operations/filterWithIndex.ts b/packages/stdlib/_src/collections/HashMap/operations/filterWithIndex.ts index fab59967..43b7db16 100644 --- a/packages/stdlib/_src/collections/HashMap/operations/filterWithIndex.ts +++ b/packages/stdlib/_src/collections/HashMap/operations/filterWithIndex.ts @@ -14,7 +14,7 @@ export function filterWithIndex(f: (k: K, a: A) => boolean) { return (self: HashMap): HashMap => { const m = HashMap.empty() return m.mutate((m) => { - for (const { tuple: [k, a] } of self) { + for (const [k, a] of self) { if (f(k, a)) { m.set(k, a) } diff --git a/packages/stdlib/_src/collections/HashMap/operations/from.ts b/packages/stdlib/_src/collections/HashMap/operations/from.ts index e4efb1ce..337314c8 100644 --- a/packages/stdlib/_src/collections/HashMap/operations/from.ts +++ b/packages/stdlib/_src/collections/HashMap/operations/from.ts @@ -4,12 +4,12 @@ * @tsplus static HashMap.Ops from */ export function from( - entries: Collection> + entries: Collection ): HashMap { const map = HashMap.empty().beginMutation for (const entry of entries) { - map.set(entry.get(0), entry.get(1)) + map.set(entry[0], entry[1]) } return map.endMutation diff --git a/packages/stdlib/_src/collections/HashMap/operations/keys.ts b/packages/stdlib/_src/collections/HashMap/operations/keys.ts index b4d1a5c9..9384df83 100644 --- a/packages/stdlib/_src/collections/HashMap/operations/keys.ts +++ b/packages/stdlib/_src/collections/HashMap/operations/keys.ts @@ -7,5 +7,5 @@ import { HashMapIterator, realHashMap } from "@tsplus/stdlib/collections/HashMap */ export function keys(self: HashMap): IterableIterator { realHashMap(self) - return new HashMapIterator(self, ({ tuple: [key] }) => key) + return new HashMapIterator(self, (key) => key) } diff --git a/packages/stdlib/_src/collections/HashMap/operations/make.ts b/packages/stdlib/_src/collections/HashMap/operations/make.ts index d1068e11..2871de69 100644 --- a/packages/stdlib/_src/collections/HashMap/operations/make.ts +++ b/packages/stdlib/_src/collections/HashMap/operations/make.ts @@ -4,11 +4,11 @@ * @tsplus static HashMap.Ops make * @tsplus static HashMap.Ops __call */ -export function make[]>( +export function make( ...entries: Entries ): HashMap< - Entries[number] extends Tuple<[infer K, any]> ? K : never, - Entries[number] extends Tuple<[any, infer V]> ? V : never + Entries[number] extends readonly [infer K, any] ? K : never, + Entries[number] extends readonly [any, infer V] ? V : never > { return HashMap.from(entries) } diff --git a/packages/stdlib/_src/collections/HashMap/operations/toCollection.ts b/packages/stdlib/_src/collections/HashMap/operations/toCollection.ts index b0faaeb7..f597a8c5 100644 --- a/packages/stdlib/_src/collections/HashMap/operations/toCollection.ts +++ b/packages/stdlib/_src/collections/HashMap/operations/toCollection.ts @@ -1,6 +1,6 @@ /** * @tsplus getter HashMap toCollection */ -export function toCollection(self: HashMap): Collection> { +export function toCollection(self: HashMap): Collection { return self } diff --git a/packages/stdlib/_src/collections/HashMap/operations/values.ts b/packages/stdlib/_src/collections/HashMap/operations/values.ts index 9dc7b508..07aa8f0f 100644 --- a/packages/stdlib/_src/collections/HashMap/operations/values.ts +++ b/packages/stdlib/_src/collections/HashMap/operations/values.ts @@ -7,5 +7,5 @@ import { HashMapIterator, realHashMap } from "@tsplus/stdlib/collections/HashMap */ export function values(self: HashMap): IterableIterator { realHashMap(self) - return new HashMapIterator(self, ({ tuple: [, value] }) => value) + return new HashMapIterator(self, (_, value) => value) } diff --git a/packages/stdlib/_src/collections/HashMap/patch/operations/diff.ts b/packages/stdlib/_src/collections/HashMap/patch/operations/diff.ts index 3d35925e..f07fd8ef 100644 --- a/packages/stdlib/_src/collections/HashMap/patch/operations/diff.ts +++ b/packages/stdlib/_src/collections/HashMap/patch/operations/diff.ts @@ -15,20 +15,20 @@ export function diff( newValue: HashMap, differ: Differ ): Differ.HashMap.Patch { - const { tuple: [removed, patch] } = newValue.reduceWithIndex( - Tuple(oldValue, Differ.HashMap.empty()), - ({ tuple: [map, patch] }, key, newValue) => { + const [removed, patch] = newValue.reduceWithIndex( + [oldValue, Differ.HashMap.empty()] as const, + ([map, patch], key, newValue) => { const maybe = map.get(key) switch (maybe._tag) { case "Some": { const valuePatch = differ.diff(maybe.value, newValue) if (Equals.equals(valuePatch, differ.empty)) { - return Tuple(map.remove(key), patch) + return [map.remove(key), patch] } - return Tuple(map.remove(key), patch.combine(new UpdateHashMapPatch(key, valuePatch))) + return [map.remove(key), patch.combine(new UpdateHashMapPatch(key, valuePatch))] } case "None": { - return Tuple(map, patch.combine(new AddHashMapPatch(key, newValue))) + return [map, patch.combine(new AddHashMapPatch(key, newValue))] } } } diff --git a/packages/stdlib/_src/collections/HashSet/operations/partition.ts b/packages/stdlib/_src/collections/HashSet/operations/partition.ts index 8a92b5e0..9c87babc 100644 --- a/packages/stdlib/_src/collections/HashSet/operations/partition.ts +++ b/packages/stdlib/_src/collections/HashSet/operations/partition.ts @@ -10,14 +10,14 @@ */ export function partition( f: Refinement -): (self: HashSet) => Tuple<[HashSet, HashSet]> +): (self: HashSet) => readonly [HashSet, HashSet] export function partition( f: Predicate -): (self: HashSet) => Tuple<[HashSet, HashSet]> +): (self: HashSet) => readonly [HashSet, HashSet] export function partition( f: Predicate ) { - return (self: HashSet): Tuple<[HashSet, HashSet]> => { + return (self: HashSet): readonly [HashSet, HashSet] => { const vs = self.values let e: IteratorResult const right = HashSet.empty().beginMutation @@ -30,6 +30,6 @@ export function partition( left.add(value) } } - return Tuple(left.endMutation, right.endMutation) + return [left.endMutation, right.endMutation] } } diff --git a/packages/stdlib/_src/collections/HashSet/patch/operations/diff.ts b/packages/stdlib/_src/collections/HashSet/patch/operations/diff.ts index 5283431e..7280e32f 100644 --- a/packages/stdlib/_src/collections/HashSet/patch/operations/diff.ts +++ b/packages/stdlib/_src/collections/HashSet/patch/operations/diff.ts @@ -12,13 +12,13 @@ export function diff( oldValue: HashSet, newValue: HashSet ): Differ.HashSet.Patch { - const { tuple: [removed, patch] } = newValue.reduce( - Tuple(oldValue, Differ.HashSet.empty()), - ({ tuple: [set, patch] }, value) => { + const [removed, patch] = newValue.reduce( + [oldValue, Differ.HashSet.empty()] as const, + ([set, patch], value) => { if (set.has(value)) { - return Tuple(set.remove(value), patch) + return [set.remove(value), patch] } - return Tuple(set, patch.combine(new AddHashSetPatch(value))) + return [set, patch.combine(new AddHashSetPatch(value))] } ) return removed.reduce(patch, (patch, value) => patch.combine(new RemoveHashSetPatch(value))) diff --git a/packages/stdlib/_src/collections/ImmutableArray/forEachWithIndexF.ts b/packages/stdlib/_src/collections/ImmutableArray/forEachWithIndexF.ts index 37850d07..e3770e51 100644 --- a/packages/stdlib/_src/collections/ImmutableArray/forEachWithIndexF.ts +++ b/packages/stdlib/_src/collections/ImmutableArray/forEachWithIndexF.ts @@ -15,7 +15,7 @@ export const forEachWithIndexF = ForEachWithIndex.implementForEachWithIndexF< ) for (let i = 0; i < fa.array.length; i = i + 1) { base = G.map( - ({ tuple: [bs, b] }: Tuple<[ImmutableArray, typeof _.B]>) => bs.append(b) + ([bs, b]: readonly [ImmutableArray, typeof _.B]) => bs.append(b) )(G.both(f(i, fa.array[i]!))(base)) } return base diff --git a/packages/stdlib/_src/collections/ImmutableArray/partition.ts b/packages/stdlib/_src/collections/ImmutableArray/partition.ts index 6d60963d..c3e01302 100644 --- a/packages/stdlib/_src/collections/ImmutableArray/partition.ts +++ b/packages/stdlib/_src/collections/ImmutableArray/partition.ts @@ -5,6 +5,6 @@ * @tsplus pipeable ImmutableArray partition */ export function partition(f: Predicate) { - return (self: ImmutableArray): Tuple<[ImmutableArray, ImmutableArray]> => + return (self: ImmutableArray): readonly [ImmutableArray, ImmutableArray] => self.partitionWithIndex((_, a) => f(a)) } diff --git a/packages/stdlib/_src/collections/ImmutableArray/partitionMap.ts b/packages/stdlib/_src/collections/ImmutableArray/partitionMap.ts index bb0b242c..0a67d353 100644 --- a/packages/stdlib/_src/collections/ImmutableArray/partitionMap.ts +++ b/packages/stdlib/_src/collections/ImmutableArray/partitionMap.ts @@ -5,6 +5,6 @@ * @tsplus pipeable ImmutableArray partitionMap */ export function partitionMap(f: (a: A) => Either) { - return (self: ImmutableArray): Tuple<[ImmutableArray, ImmutableArray]> => + return (self: ImmutableArray): readonly [ImmutableArray, ImmutableArray] => self.partitionMapWithIndex((_, a) => f(a)) } diff --git a/packages/stdlib/_src/collections/ImmutableArray/partitionMapWithIndex.ts b/packages/stdlib/_src/collections/ImmutableArray/partitionMapWithIndex.ts index f5903355..9ba6de19 100644 --- a/packages/stdlib/_src/collections/ImmutableArray/partitionMapWithIndex.ts +++ b/packages/stdlib/_src/collections/ImmutableArray/partitionMapWithIndex.ts @@ -5,7 +5,7 @@ * @tsplus pipeable ImmutableArray partitionMapWithIndex */ export function partitionMapWithIndex(f: (i: number, a: A) => Either) { - return (self: ImmutableArray): Tuple<[ImmutableArray, ImmutableArray]> => { + return (self: ImmutableArray): readonly [ImmutableArray, ImmutableArray] => { const left: Array = [] const right: Array = [] for (let i = 0; i < self.array.length; i = i + 1) { @@ -16,6 +16,6 @@ export function partitionMapWithIndex(f: (i: number, a: A) => Either(f: PredicateWithIndex) { - return (self: ImmutableArray): Tuple<[ImmutableArray, ImmutableArray]> => { + return (self: ImmutableArray): readonly [ImmutableArray, ImmutableArray] => { const left: Array = [] const right: Array = [] for (let i = 0; i < self.array.length; i = i + 1) { @@ -16,6 +16,6 @@ export function partitionWithIndex(f: PredicateWithIndex) { left.push(a) } } - return Tuple(new ImmutableArray(left), new ImmutableArray(right)) + return [new ImmutableArray(left), new ImmutableArray(right)] } } diff --git a/packages/stdlib/_src/collections/ImmutableArray/separate.ts b/packages/stdlib/_src/collections/ImmutableArray/separate.ts index 40007e70..9165f028 100644 --- a/packages/stdlib/_src/collections/ImmutableArray/separate.ts +++ b/packages/stdlib/_src/collections/ImmutableArray/separate.ts @@ -3,7 +3,7 @@ */ export function separate( self: ImmutableArray> -): Tuple<[ImmutableArray, ImmutableArray]> { +): readonly [ImmutableArray, ImmutableArray] { const left: Array = [] const right: Array = [] for (const element of self) { @@ -13,5 +13,5 @@ export function separate( right.push(element.right) } } - return Tuple(ImmutableArray.from(left), ImmutableArray.from(right)) + return [ImmutableArray.from(left), ImmutableArray.from(right)] } diff --git a/packages/stdlib/_src/collections/ImmutableArray/separateF.ts b/packages/stdlib/_src/collections/ImmutableArray/separateF.ts index 3ce7795d..4af678b2 100644 --- a/packages/stdlib/_src/collections/ImmutableArray/separateF.ts +++ b/packages/stdlib/_src/collections/ImmutableArray/separateF.ts @@ -13,7 +13,7 @@ export const separateF = Wiltable.implementSeparateF()( (f: (a: A) => HKT.Kind>) => ( fa: ImmutableArray - ): HKT.Kind, ImmutableArray]>> => + ): HKT.Kind, ImmutableArray]> => G.map((self: ImmutableArray>) => self.separate)( ImmutableArray.forEachF(G)(f)(fa) ) diff --git a/packages/stdlib/_src/collections/ImmutableArray/separateWithIndexF.ts b/packages/stdlib/_src/collections/ImmutableArray/separateWithIndexF.ts index 62a18498..4bdd9505 100644 --- a/packages/stdlib/_src/collections/ImmutableArray/separateWithIndexF.ts +++ b/packages/stdlib/_src/collections/ImmutableArray/separateWithIndexF.ts @@ -16,7 +16,7 @@ export const separateWithIndexF = WiltableWithIndex.implementSeparateWithIndexF< (f: (k: number, a: A) => HKT.Kind>) => ( fa: ImmutableArray - ): HKT.Kind, ImmutableArray]>> => + ): HKT.Kind, ImmutableArray]> => G.map((self: ImmutableArray>) => self.separate)( ImmutableArray.forEachWithIndexF(G)(f)(fa) ) diff --git a/packages/stdlib/_src/collections/ImmutableArray/zip.ts b/packages/stdlib/_src/collections/ImmutableArray/zip.ts index 9cf222b3..af344b85 100644 --- a/packages/stdlib/_src/collections/ImmutableArray/zip.ts +++ b/packages/stdlib/_src/collections/ImmutableArray/zip.ts @@ -6,6 +6,6 @@ * @tsplus pipeable ImmutableArray zip */ export function zip(that: ImmutableArray) { - return (self: ImmutableArray): ImmutableArray> => - self.zipWith(that, (a, b) => Tuple(a, b)) + return (self: ImmutableArray): ImmutableArray => + self.zipWith(that, (a, b) => [a, b]) } diff --git a/packages/stdlib/_src/collections/ImmutableMap/definition.ts b/packages/stdlib/_src/collections/ImmutableMap/definition.ts index fc712748..bb29efa3 100644 --- a/packages/stdlib/_src/collections/ImmutableMap/definition.ts +++ b/packages/stdlib/_src/collections/ImmutableMap/definition.ts @@ -2,10 +2,10 @@ * @tsplus type ImmutableMap * @tsplus companion ImmutableMap.Ops */ -export class ImmutableMap implements Equals, Collection> { +export class ImmutableMap implements Equals, Collection { constructor(readonly internalMap: ReadonlyMap) {} - [Symbol.iterator](): Iterator> { + [Symbol.iterator](): Iterator { const iterator = this.internalMap[Symbol.iterator]() return { next: () => { @@ -13,7 +13,7 @@ export class ImmutableMap implements Equals, Collection> { if (next.done) { return { done: true, value: undefined } } - return { done: false, value: Tuple(next.value[0], next.value[1]) } + return { done: false, value: [next.value[0], next.value[1]] } } } } @@ -38,7 +38,7 @@ export class ImmutableMap implements Equals, Collection> { [Hash.sym](): number { let hash = Hash.string("ImmutableMap") for (const item of this) { - hash ^= Hash.combine(Hash.unknown(item.get(0)), Hash.unknown(item.get(1))) + hash ^= Hash.combine(Hash.unknown(item[0]), Hash.unknown(item[1])) } return Hash.optimize(hash) } diff --git a/packages/stdlib/_src/collections/ImmutableMap/from.ts b/packages/stdlib/_src/collections/ImmutableMap/from.ts index 1904f453..a9152788 100644 --- a/packages/stdlib/_src/collections/ImmutableMap/from.ts +++ b/packages/stdlib/_src/collections/ImmutableMap/from.ts @@ -4,10 +4,10 @@ * @tsplus static ImmutableMap.Ops from */ export function from( - entries: Collection> + entries: Collection ): ImmutableMap { const map = new Map() - for (const { tuple: [key, value] } of entries) { + for (const [key, value] of entries) { map.set(key, value) } return new ImmutableMap(map) diff --git a/packages/stdlib/_src/collections/ImmutableMap/make.ts b/packages/stdlib/_src/collections/ImmutableMap/make.ts index acbf4cbe..e69fe972 100644 --- a/packages/stdlib/_src/collections/ImmutableMap/make.ts +++ b/packages/stdlib/_src/collections/ImmutableMap/make.ts @@ -4,11 +4,11 @@ * @tsplus static ImmutableMap.Ops __call * @tsplus static ImmutableMap.Ops make */ -export function make[]>( +export function make( ...entries: Entries ): ImmutableMap< - Entries[number] extends Tuple<[infer K, any]> ? K : never, - Entries[number] extends Tuple<[any, infer V]> ? V : never + Entries[number] extends readonly [infer K, any] ? K : never, + Entries[number] extends readonly [any, infer V] ? V : never > { return ImmutableMap.from(entries) } diff --git a/packages/stdlib/_src/collections/ImmutableQueue/dequeue.ts b/packages/stdlib/_src/collections/ImmutableQueue/dequeue.ts index 7d52d447..96b29b3a 100644 --- a/packages/stdlib/_src/collections/ImmutableQueue/dequeue.ts +++ b/packages/stdlib/_src/collections/ImmutableQueue/dequeue.ts @@ -8,18 +8,18 @@ import { */ export function dequeue( self: ImmutableQueue -): Maybe, ImmutableQueue]>> { +): Maybe, ImmutableQueue]> { concreteImmutableQueue(self) const size = self.backingList.length if (size === 0) { return Maybe.none } return Maybe.some( - Tuple( + [ self.backingList.unsafeHead!, size === 1 ? new ImmutableQueueInternal(List.nil()) : new ImmutableQueueInternal(self.backingList.unsafeTail!) - ) + ] ) } diff --git a/packages/stdlib/_src/collections/ImmutableQueue/splitAt.ts b/packages/stdlib/_src/collections/ImmutableQueue/splitAt.ts index 93545169..114afabd 100644 --- a/packages/stdlib/_src/collections/ImmutableQueue/splitAt.ts +++ b/packages/stdlib/_src/collections/ImmutableQueue/splitAt.ts @@ -2,16 +2,15 @@ import { concreteImmutableQueue, ImmutableQueueInternal } from "@tsplus/stdlib/collections/ImmutableQueue/_internal/ImmutableQueueInternal" -import { Tuple } from "@tsplus/stdlib/data/Tuple" /** * @tsplus static ImmutableQueue.Aspects splitAt * @tsplus pipeable ImmutableQueue splitAt */ export function splitAt(n: number) { - return (self: ImmutableQueue): Tuple<[ImmutableQueue, ImmutableQueue]> => { + return (self: ImmutableQueue): readonly [ImmutableQueue, ImmutableQueue] => { concreteImmutableQueue(self) - const { tuple: [a, b] } = self.backingList.splitAt(n) - return Tuple.make(new ImmutableQueueInternal(a), new ImmutableQueueInternal(b)) + const [a, b] = self.backingList.splitAt(n) + return [new ImmutableQueueInternal(a), new ImmutableQueueInternal(b)] } } diff --git a/packages/stdlib/_src/collections/List/partition.ts b/packages/stdlib/_src/collections/List/partition.ts index bac77fe1..6c8231cc 100644 --- a/packages/stdlib/_src/collections/List/partition.ts +++ b/packages/stdlib/_src/collections/List/partition.ts @@ -5,7 +5,7 @@ * @tsplus pipeable List partition */ export function partition(f: Predicate) { - return (self: List): Tuple<[List, List]> => { + return (self: List): readonly [List, List] => { const left: Array = [] const right: Array = [] for (const a of self) { @@ -15,6 +15,6 @@ export function partition(f: Predicate) { left.push(a) } } - return Tuple(List.from(left), List.from(right)) + return [List.from(left), List.from(right)] } } diff --git a/packages/stdlib/_src/collections/List/partitionMap.ts b/packages/stdlib/_src/collections/List/partitionMap.ts index 0d3872a7..f8e7dba7 100644 --- a/packages/stdlib/_src/collections/List/partitionMap.ts +++ b/packages/stdlib/_src/collections/List/partitionMap.ts @@ -6,7 +6,7 @@ * @tsplus pipeable List partitionMap */ export function partitionMap(f: (a: A) => Either) { - return (self: List): Tuple<[List, List]> => { + return (self: List): readonly [List, List] => { const left: Array = [] const right: Array = [] for (const a of self) { @@ -17,6 +17,6 @@ export function partitionMap(f: (a: A) => Either) { right.push(e.right) } } - return Tuple(List.from(left), List.from(right)) + return [List.from(left), List.from(right)] } } diff --git a/packages/stdlib/_src/collections/List/splitAt.ts b/packages/stdlib/_src/collections/List/splitAt.ts index e25fb27e..497a8ea8 100644 --- a/packages/stdlib/_src/collections/List/splitAt.ts +++ b/packages/stdlib/_src/collections/List/splitAt.ts @@ -5,5 +5,5 @@ * @tsplus pipeable List splitAt */ export function splitAt(n: number) { - return (self: List): Tuple<[List, List]> => Tuple(self.take(n).toList, self.drop(n)) + return (self: List): readonly [List, List] => [self.take(n).toList, self.drop(n)] } diff --git a/packages/stdlib/_src/collections/Map.ts b/packages/stdlib/_src/collections/Map.ts deleted file mode 100644 index 7d3b2332..00000000 --- a/packages/stdlib/_src/collections/Map.ts +++ /dev/null @@ -1,6 +0,0 @@ -// codegen:start {preset: barrel, include: ./Map/*.ts, prefix: "@tsplus/stdlib/collections"} -export * from "@tsplus/stdlib/collections/Map/definition" -export * from "@tsplus/stdlib/collections/Map/empty" -export * from "@tsplus/stdlib/collections/Map/from" -export * from "@tsplus/stdlib/collections/Map/make" -// codegen:end diff --git a/packages/stdlib/_src/collections/Map/definition.ts b/packages/stdlib/_src/collections/Map/definition.ts deleted file mode 100644 index aedd901d..00000000 --- a/packages/stdlib/_src/collections/Map/definition.ts +++ /dev/null @@ -1,11 +0,0 @@ -declare global { - /** - * @tsplus type Map - */ - export interface Map extends Iterable<[K, V]> {} - /** - * @tsplus type Map.Ops - */ - export interface MapConstructor { - } -} diff --git a/packages/stdlib/_src/collections/Map/empty.ts b/packages/stdlib/_src/collections/Map/empty.ts deleted file mode 100644 index 0f4e5b27..00000000 --- a/packages/stdlib/_src/collections/Map/empty.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @tsplus static Map.Ops empty - */ -export function empty(): Map { - return new Map() -} diff --git a/packages/stdlib/_src/collections/Map/from.ts b/packages/stdlib/_src/collections/Map/from.ts deleted file mode 100644 index eda2366d..00000000 --- a/packages/stdlib/_src/collections/Map/from.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * @tsplus static Map.Ops from - */ -export function from( - data: Collection> -): Map { - return new Map(data.map((_) => _.toNative)) -} diff --git a/packages/stdlib/_src/collections/Map/make.ts b/packages/stdlib/_src/collections/Map/make.ts deleted file mode 100644 index cb7f19c2..00000000 --- a/packages/stdlib/_src/collections/Map/make.ts +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Constructs a new `Map`. - * - * @tsplus static Map.Ops __call - * @tsplus static Map.Ops make - */ -export function make[]>( - ...data: Entries -): Map< - Entries[number] extends Tuple<[infer K, any]> ? K : never, - Entries[number] extends Tuple<[any, infer V]> ? V : never -> { - return Map.from(data) -} diff --git a/packages/stdlib/_src/collections/ParSeq/definition.ts b/packages/stdlib/_src/collections/ParSeq/definition.ts index f4983623..0d049b97 100644 --- a/packages/stdlib/_src/collections/ParSeq/definition.ts +++ b/packages/stdlib/_src/collections/ParSeq/definition.ts @@ -478,13 +478,11 @@ function flattenLoop( ): List>> { // eslint-disable-next-line no-constant-condition while (1) { - const { - tuple: [parallel, sequential] - } = causes.reduce( - Tuple(HashSet.empty>(), List.empty>()), - ({ tuple: [parallel, sequential] }, cause) => { - const [set, seq] = step(cause).tuple - return Tuple(parallel.union(set), sequential + seq) + const [parallel, sequential] = causes.reduce( + [HashSet.empty>(), List.empty>()] as const, + ([parallel, sequential], cause) => { + const [set, seq] = step(cause) + return [parallel.union(set), sequential + seq] } ) const updated = parallel.size > 0 ? flattened.prepend(parallel) : flattened @@ -498,7 +496,7 @@ function flattenLoop( throw new Error("Bug") } -function step(self: ParSeq): Tuple<[HashSet>, List>]> { +function step(self: ParSeq): readonly [HashSet>, List>] { return stepLoop(self, List.empty(), HashSet.empty(), List.empty()) } @@ -507,13 +505,13 @@ function stepLoop( stack: List>, parallel: HashSet>, sequential: List> -): Tuple<[HashSet>, List>]> { +): readonly [HashSet>, List>] { // eslint-disable-next-line no-constant-condition while (1) { switch (cause._tag) { case "Empty": { if (stack.isNil()) { - return Tuple(parallel, sequential) + return [parallel, sequential] } else { cause = stack.head! stack = stack.tail @@ -550,7 +548,7 @@ function stepLoop( } default: { if (stack.isNil()) { - return Tuple(parallel.add(cause), sequential) + return [parallel.add(cause), sequential] } else { parallel = parallel.add(cause) cause = stack.head diff --git a/packages/stdlib/_src/collections/ParSeq/zip.ts b/packages/stdlib/_src/collections/ParSeq/zip.ts index ee8f9916..11a95e3e 100644 --- a/packages/stdlib/_src/collections/ParSeq/zip.ts +++ b/packages/stdlib/_src/collections/ParSeq/zip.ts @@ -7,5 +7,5 @@ * @tsplus pipeable ParSeq zip */ export function zip(that: ParSeq) { - return (self: ParSeq): ParSeq> => self.zipWith(that, (a, b) => Tuple(a, b)) + return (self: ParSeq): ParSeq => self.zipWith(that, (a, b) => [a, b]) } diff --git a/packages/stdlib/_src/collections/RedBlackTree/definition.ts b/packages/stdlib/_src/collections/RedBlackTree/definition.ts index d58c03d6..6556762c 100644 --- a/packages/stdlib/_src/collections/RedBlackTree/definition.ts +++ b/packages/stdlib/_src/collections/RedBlackTree/definition.ts @@ -40,12 +40,12 @@ export const RedBlackTree: RedBlackTreeOps = { */ export interface RedBlackTreeAspects {} -export interface RedBlackTreeIterable extends Collection> { +export interface RedBlackTreeIterable extends Collection { readonly ord: Ord [Symbol.iterator](): RedBlackTreeIterator } -export class RedBlackTreeIterator implements Iterator> { +export class RedBlackTreeIterator implements Iterator { private count = 0 constructor( @@ -75,7 +75,7 @@ export class RedBlackTreeIterator implements Iterator> { /** * Iterator next */ - next(): IteratorResult> { + next(): IteratorResult { const entry = this.entry this.count++ if (this.direction === "Forward") { @@ -112,13 +112,10 @@ export class RedBlackTreeIterator implements Iterator> { /** * Returns the key */ - get entry(): Maybe> { + get entry(): Maybe { if (this.stack.length > 0) { return Maybe.some( - Tuple( - this.stack[this.stack.length - 1]!.key, - this.stack[this.stack.length - 1]!.value - ) + [this.stack[this.stack.length - 1]!.key, this.stack[this.stack.length - 1]!.value] ) } return Maybe.none diff --git a/packages/stdlib/_src/collections/RedBlackTree/first.ts b/packages/stdlib/_src/collections/RedBlackTree/first.ts index edd4a302..aecc3d22 100644 --- a/packages/stdlib/_src/collections/RedBlackTree/first.ts +++ b/packages/stdlib/_src/collections/RedBlackTree/first.ts @@ -5,12 +5,12 @@ import type { Node } from "@tsplus/stdlib/collections/RedBlackTree/node" * * @tsplus getter RedBlackTree first */ -export function first(tree: RedBlackTree): Maybe> { +export function first(tree: RedBlackTree): Maybe { let n: Node | undefined = tree.root let c: Node | undefined = tree.root while (n) { c = n n = n.left } - return c ? Maybe.some(Tuple(c.key, c.value)) : Maybe.none + return c ? Maybe.some([c.key, c.value]) : Maybe.none } diff --git a/packages/stdlib/_src/collections/RedBlackTree/from.ts b/packages/stdlib/_src/collections/RedBlackTree/from.ts index ffa3678d..7f089f5a 100644 --- a/packages/stdlib/_src/collections/RedBlackTree/from.ts +++ b/packages/stdlib/_src/collections/RedBlackTree/from.ts @@ -6,14 +6,14 @@ export function from( ord: Ord ): ( - data: Collection> + data: Collection ) => RedBlackTree { return ( - data: Collection> + data: Collection ) => { let tree = RedBlackTree.empty(ord) - for (const { tuple: [k, v] } of data) { + for (const [k, v] of data) { tree = tree.insert(k, v) } diff --git a/packages/stdlib/_src/collections/RedBlackTree/getAt.ts b/packages/stdlib/_src/collections/RedBlackTree/getAt.ts index 2bc11d9e..6ce1aa15 100644 --- a/packages/stdlib/_src/collections/RedBlackTree/getAt.ts +++ b/packages/stdlib/_src/collections/RedBlackTree/getAt.ts @@ -8,7 +8,7 @@ import type { Node } from "@tsplus/stdlib/collections/RedBlackTree/node" * @tsplus pipeable RedBlackTree getAt */ export function getAt(index: number) { - return (self: RedBlackTree): Maybe> => { + return (self: RedBlackTree): Maybe => { if (index < 0) { return Maybe.none } @@ -24,7 +24,7 @@ export function getAt(index: number) { index -= n.left.count } if (!index) { - return Maybe.some(Tuple(node.key, node.value)) + return Maybe.some([node.key, node.value]) } index -= 1 if (n.right) { diff --git a/packages/stdlib/_src/collections/RedBlackTree/last.ts b/packages/stdlib/_src/collections/RedBlackTree/last.ts index ac24e02a..efe3f960 100644 --- a/packages/stdlib/_src/collections/RedBlackTree/last.ts +++ b/packages/stdlib/_src/collections/RedBlackTree/last.ts @@ -5,12 +5,12 @@ import type { Node } from "@tsplus/stdlib/collections/RedBlackTree/node" * * @tsplus getter RedBlackTree last */ -export function last(tree: RedBlackTree): Maybe> { +export function last(tree: RedBlackTree): Maybe { let n: Node | undefined = tree.root let c: Node | undefined = tree.root while (n) { c = n n = n.right } - return c ? Maybe.some(Tuple(c.key, c.value)) : Maybe.none + return c ? Maybe.some([c.key, c.value]) : Maybe.none } diff --git a/packages/stdlib/_src/collections/RedBlackTree/make.ts b/packages/stdlib/_src/collections/RedBlackTree/make.ts index bf3a624c..d90c1f11 100644 --- a/packages/stdlib/_src/collections/RedBlackTree/make.ts +++ b/packages/stdlib/_src/collections/RedBlackTree/make.ts @@ -4,11 +4,11 @@ * @tsplus static RedBlackTree.Ops __call * @tsplus static RedBlackTree.Ops make */ -export function make[]>( +export function make( ord: Ord ): ( ...entries: Entries -) => RedBlackTree ? V : never> { +) => RedBlackTree { return (...entries: Entries) => - RedBlackTree.from ? V : never>(ord)(entries) + RedBlackTree.from(ord)(entries) } diff --git a/packages/stdlib/_src/collections/RedBlackTree/reduceWithIndex.ts b/packages/stdlib/_src/collections/RedBlackTree/reduceWithIndex.ts index 9a231d55..d440fb1f 100644 --- a/packages/stdlib/_src/collections/RedBlackTree/reduceWithIndex.ts +++ b/packages/stdlib/_src/collections/RedBlackTree/reduceWithIndex.ts @@ -7,7 +7,7 @@ export function reduceWithIndex(z: Z, f: (z: Z, k: K, v: V) => Z) { return (self: RedBlackTree): Z => { let x = z - for (const { tuple: [k, v] } of self) { + for (const [k, v] of self) { x = f(x, k, v) } return x diff --git a/packages/stdlib/_src/collections/SortedMap/_internal/SortedMapInternal.ts b/packages/stdlib/_src/collections/SortedMap/_internal/SortedMapInternal.ts index 8b3969b6..39f1eacd 100644 --- a/packages/stdlib/_src/collections/SortedMap/_internal/SortedMapInternal.ts +++ b/packages/stdlib/_src/collections/SortedMap/_internal/SortedMapInternal.ts @@ -15,7 +15,7 @@ export class SortedMapInternal implements SortedMap { return this.tree[Equals.sym](that) } - [Symbol.iterator](): Iterator> { + [Symbol.iterator](): Iterator { return this.tree[Symbol.iterator]() } } diff --git a/packages/stdlib/_src/collections/SortedMap/definition.ts b/packages/stdlib/_src/collections/SortedMap/definition.ts index bd3f7456..e8106912 100644 --- a/packages/stdlib/_src/collections/SortedMap/definition.ts +++ b/packages/stdlib/_src/collections/SortedMap/definition.ts @@ -10,11 +10,11 @@ export type _V = typeof _V /** * @tsplus type SortedMap */ -export interface SortedMap extends Collection>, Equals { +export interface SortedMap extends Collection, Equals { readonly [SortedMapSym]: SortedMapSym readonly [_K]: () => K readonly [_V]: () => V - [Symbol.iterator](): Iterator> + [Symbol.iterator](): Iterator } /** diff --git a/packages/stdlib/_src/collections/SortedMap/entries.ts b/packages/stdlib/_src/collections/SortedMap/entries.ts index 515aa359..5d7363b1 100644 --- a/packages/stdlib/_src/collections/SortedMap/entries.ts +++ b/packages/stdlib/_src/collections/SortedMap/entries.ts @@ -1,6 +1,6 @@ /** * @tsplus getter SortedMap entries */ -export function entries(self: SortedMap): Iterator> { +export function entries(self: SortedMap): Iterator { return self[Symbol.iterator]() } diff --git a/packages/stdlib/_src/collections/SortedMap/from.ts b/packages/stdlib/_src/collections/SortedMap/from.ts index de8cc4f7..2ec007f4 100644 --- a/packages/stdlib/_src/collections/SortedMap/from.ts +++ b/packages/stdlib/_src/collections/SortedMap/from.ts @@ -6,10 +6,10 @@ import { SortedMapInternal } from "@tsplus/stdlib/collections/SortedMap/_interna export function from_( ord: Ord ): ( - iterable: Collection> + iterable: Collection ) => SortedMap { return ( - iterable: Collection> + iterable: Collection ) => new SortedMapInternal(RedBlackTree.from(ord)(iterable)) } diff --git a/packages/stdlib/_src/collections/SortedMap/headMaybe.ts b/packages/stdlib/_src/collections/SortedMap/headMaybe.ts index 2cb7b63d..0dd9a74e 100644 --- a/packages/stdlib/_src/collections/SortedMap/headMaybe.ts +++ b/packages/stdlib/_src/collections/SortedMap/headMaybe.ts @@ -3,7 +3,7 @@ import { concreteSortedMap } from "@tsplus/stdlib/collections/SortedMap/_interna /** * @tsplus getter SortedMap headMaybe */ -export function headMaybe(self: SortedMap): Maybe> { +export function headMaybe(self: SortedMap): Maybe { concreteSortedMap(self) return self.tree.first } diff --git a/packages/stdlib/_src/collections/SortedMap/make.ts b/packages/stdlib/_src/collections/SortedMap/make.ts index d5d433ce..562e01a3 100644 --- a/packages/stdlib/_src/collections/SortedMap/make.ts +++ b/packages/stdlib/_src/collections/SortedMap/make.ts @@ -2,11 +2,11 @@ * @tsplus static SortedMap.Ops __call * @tsplus static SortedMap.Ops make */ -export function make[]>( +export function make( ord: Ord -): (...entries: Entries) => SortedMap< +): (...entries: Entries) => SortedMap< K, - Entries[number] extends Tuple<[any, infer V]> ? V : never + Entries[number] extends (readonly [any, infer V]) ? V : never > { - return (...entries: Entries) => SortedMap.from(ord)(entries) + return (...entries) => SortedMap.from(ord)(entries) } diff --git a/packages/stdlib/_src/collections/SortedSet/from.ts b/packages/stdlib/_src/collections/SortedSet/from.ts index 5595aaff..63d183d6 100644 --- a/packages/stdlib/_src/collections/SortedSet/from.ts +++ b/packages/stdlib/_src/collections/SortedSet/from.ts @@ -1,5 +1,4 @@ import { SortedSetInternal } from "@tsplus/stdlib/collections/SortedSet/_internal/SortedSetInternal" -import { Tuple } from "@tsplus/stdlib/data/Tuple" /** * @tsplus static SortedSet.Ops from @@ -11,7 +10,7 @@ export function from_( ) => SortedSet { return ( iterable: Collection - ) => new SortedSetInternal(RedBlackTree.from(ord)(iterable.map((_) => Tuple(_, true)))) + ) => new SortedSetInternal(RedBlackTree.from(ord)(iterable.map((_) => [_, true]))) } /** diff --git a/packages/stdlib/_src/collections/SortedSet/partition.ts b/packages/stdlib/_src/collections/SortedSet/partition.ts index 24c082c9..feecdbae 100644 --- a/packages/stdlib/_src/collections/SortedSet/partition.ts +++ b/packages/stdlib/_src/collections/SortedSet/partition.ts @@ -8,13 +8,13 @@ import { concreteSortedSet } from "@tsplus/stdlib/collections/SortedSet/_interna */ export function partition( f: Refinement -): (self: SortedSet) => Tuple<[SortedSet, SortedSet]> +): (self: SortedSet) => readonly [SortedSet, SortedSet] export function partition( f: Predicate -): (self: SortedSet) => Tuple<[SortedSet, SortedSet]> +): (self: SortedSet) => readonly [SortedSet, SortedSet] export function partition( f: Predicate -): (self: SortedSet) => Tuple<[SortedSet, SortedSet]> { +): (self: SortedSet) => readonly [SortedSet, SortedSet] { return (self) => { concreteSortedSet(self) let right = SortedSet.empty(self.keyTree.ord) @@ -26,6 +26,6 @@ export function partition( left = left.add(value) } } - return Tuple(left, right) + return [left, right] } } diff --git a/packages/stdlib/_src/collections/Tree/forEachF.ts b/packages/stdlib/_src/collections/Tree/forEachF.ts index e7621fda..6818d8a1 100644 --- a/packages/stdlib/_src/collections/Tree/forEachF.ts +++ b/packages/stdlib/_src/collections/Tree/forEachF.ts @@ -11,7 +11,7 @@ export const forEachF = ForEach.implementForEachF()( return pipe( f(fa.value), G.both(forEachFChunk(go)(fa.forest)), - G.map(({ tuple: [b, bs] }) => Tree(b, bs)) + G.map(([b, bs]) => Tree(b, bs)) ) } } diff --git a/packages/stdlib/_src/collections/Tree/unfold.ts b/packages/stdlib/_src/collections/Tree/unfold.ts index d7662b8f..581f3820 100644 --- a/packages/stdlib/_src/collections/Tree/unfold.ts +++ b/packages/stdlib/_src/collections/Tree/unfold.ts @@ -4,9 +4,9 @@ * * @tsplus static Tree.Ops unfold */ -export function unfold(s: S, f: (s: S) => Tuple<[A, Chunk]>): Tree { +export function unfold(s: S, f: (s: S) => readonly [A, Chunk]): Tree { const next = f(s) - const [a, s0] = [next.get(0), next.get(1)] + const [a, s0] = [next[0], next[1]] return Tree( a, s0.map((b) => unfold(b, f)) diff --git a/packages/stdlib/_src/collections/Tree/zip.ts b/packages/stdlib/_src/collections/Tree/zip.ts index 423f19c1..fec52796 100644 --- a/packages/stdlib/_src/collections/Tree/zip.ts +++ b/packages/stdlib/_src/collections/Tree/zip.ts @@ -3,5 +3,5 @@ * @tsplus pipeable Tree zip */ export function zip(that: Tree) { - return (self: Tree): Tree> => self.zipWith(that, Tuple.make) + return (self: Tree): Tree => self.zipWith(that, (a, b) => [a, b]) } diff --git a/packages/stdlib/_src/collections/mutable/MutableHashMap/definition.ts b/packages/stdlib/_src/collections/mutable/MutableHashMap/definition.ts index 9df1ea01..b140f55f 100644 --- a/packages/stdlib/_src/collections/mutable/MutableHashMap/definition.ts +++ b/packages/stdlib/_src/collections/mutable/MutableHashMap/definition.ts @@ -13,7 +13,7 @@ export type _V = typeof _V * @tsplus type MutableHashMap * @tsplus companion MutableHashMap.Ops */ -export class MutableHashMap implements Collection>, Equals { +export class MutableHashMap implements Collection, Equals { readonly [MutableHashMapSym]: MutableHashMapSym = MutableHashMapSym readonly [_K]!: () => K readonly [_V]!: () => V @@ -135,23 +135,23 @@ export class MutableHashMap implements Collection>, Equals { return this } - [Symbol.iterator](): Iterator> { + [Symbol.iterator](): Iterator { return ImmutableArray.from(this.backingMap.values()) - .map((node) => Tuple(node.k, node.v))[Symbol.iterator]() + .map((node) => [node.k, node.v] as const)[Symbol.iterator]() } } -class Node implements Iterable> { +class Node implements Iterable { constructor(readonly k: K, public v: V, public next?: Node) {} - [Symbol.iterator](): Iterator> { + [Symbol.iterator](): Iterator { // eslint-disable-next-line @typescript-eslint/no-this-alias let c: Node | undefined = this let n = 0 return { next: () => { if (c) { - const kv = Tuple(c.k, c.v) + const kv = [c.k, c.v] as const c = c.next n++ return { diff --git a/packages/stdlib/_src/collections/mutable/MutableHashMap/from.ts b/packages/stdlib/_src/collections/mutable/MutableHashMap/from.ts index a48c2475..a15bc40e 100644 --- a/packages/stdlib/_src/collections/mutable/MutableHashMap/from.ts +++ b/packages/stdlib/_src/collections/mutable/MutableHashMap/from.ts @@ -4,12 +4,12 @@ * @tsplus static MutableHashMap.Ops from */ export function from( - entries: Collection> + entries: Collection ): MutableHashMap { const map = MutableHashMap.empty() for (const entry of entries) { - map.set(entry.get(0), entry.get(1)) + map.set(entry[0], entry[1]) } return map diff --git a/packages/stdlib/_src/collections/mutable/MutableHashMap/make.ts b/packages/stdlib/_src/collections/mutable/MutableHashMap/make.ts index 8c08b048..6f597f7c 100644 --- a/packages/stdlib/_src/collections/mutable/MutableHashMap/make.ts +++ b/packages/stdlib/_src/collections/mutable/MutableHashMap/make.ts @@ -4,11 +4,11 @@ * @tsplus static MutableHashMap.Ops __call * @tsplus static MutableHashMap.Ops make */ -export function make[]>( +export function make( ...entries: Entries ): MutableHashMap< - Entries[number] extends Tuple<[infer K, any]> ? K : never, - Entries[number] extends Tuple<[any, infer V]> ? V : never + Entries[number] extends readonly [infer K, any] ? K : never, + Entries[number] extends readonly [any, infer V] ? V : never > { return MutableHashMap.from(entries) } diff --git a/packages/stdlib/_src/collections/mutable/MutableHashSet/definition.ts b/packages/stdlib/_src/collections/mutable/MutableHashSet/definition.ts index 0d09809e..03714f1b 100644 --- a/packages/stdlib/_src/collections/mutable/MutableHashSet/definition.ts +++ b/packages/stdlib/_src/collections/mutable/MutableHashSet/definition.ts @@ -41,6 +41,6 @@ export class MutableHashSet implements Collection, Equals { } [Symbol.iterator](): Iterator { - return this.backingMap.map(({ tuple: [a] }) => a)[Symbol.iterator]() + return this.backingMap.map(([a]) => a)[Symbol.iterator]() } } diff --git a/packages/stdlib/_src/data.ts b/packages/stdlib/_src/data.ts index 7ea1f459..51fe9007 100644 --- a/packages/stdlib/_src/data.ts +++ b/packages/stdlib/_src/data.ts @@ -12,4 +12,3 @@ export * as maybe from "@tsplus/stdlib/data/Maybe" export * as predicate from "@tsplus/stdlib/data/Predicate" export * as stack from "@tsplus/stdlib/data/Stack" export * as string from "@tsplus/stdlib/data/String" -export * as tuple from "@tsplus/stdlib/data/Tuple" diff --git a/packages/stdlib/_src/data/Differ/operations/zip.ts b/packages/stdlib/_src/data/Differ/operations/zip.ts index 7c4b4a3c..48b026cd 100644 --- a/packages/stdlib/_src/data/Differ/operations/zip.ts +++ b/packages/stdlib/_src/data/Differ/operations/zip.ts @@ -8,26 +8,23 @@ export function zip(that: Differ) { return ( self: Differ - ): Differ, Tuple<[Patch, Patch2]>> => + ): Differ => Differ.make({ - empty: Tuple( - self.empty, - that.empty - ), - combine: (first, second) => - Tuple( - self.combine(first.get(0), second.get(0)), - that.combine(first.get(1), second.get(1)) - ), - diff: (oldValue, newValue) => - Tuple( - self.diff(oldValue.get(0), newValue.get(0)), - that.diff(oldValue.get(1), newValue.get(1)) - ), - patch: (patch, oldValue) => - Tuple( - self.patch(patch.get(0), oldValue.get(0)), - that.patch(patch.get(1), oldValue.get(1)) - ) + empty: [self.empty, that.empty] as const, + combine: ( + first, + second + ) => [self.combine(first[0], second[0]), that.combine(first[1], second[1])], + diff: ( + oldValue, + newValue + ) => [ + self.diff(oldValue[0], newValue[0]), + that.diff(oldValue[1], newValue[1]) + ], + patch: ( + patch, + oldValue + ) => [self.patch(patch[0], oldValue[0]), that.patch(patch[1], oldValue[1])] }) } diff --git a/packages/stdlib/_src/data/Either/separate.ts b/packages/stdlib/_src/data/Either/separate.ts index a78979a5..3e7ce4cf 100644 --- a/packages/stdlib/_src/data/Either/separate.ts +++ b/packages/stdlib/_src/data/Either/separate.ts @@ -6,12 +6,12 @@ * @tsplus pipeable Either separate */ export function separate(M: AssociativeIdentity) { - return (self: Either>): Tuple<[Either, Either]> => { + return (self: Either>): readonly [Either, Either] => { const empty = Either.left(M.identity) return self.isLeft() - ? Tuple<[Either, Either]>(self, self) + ? [self, self] : self.right.isLeft() - ? Tuple<[Either, Either]>(Either.right(self.right.left), empty) - : Tuple<[Either, Either]>(empty, Either.right(self.right.right)) + ? [Either.right(self.right.left), empty] + : [empty, Either.right(self.right.right)] } } diff --git a/packages/stdlib/_src/data/Either/zip.ts b/packages/stdlib/_src/data/Either/zip.ts index f16e50a1..caf9e9de 100644 --- a/packages/stdlib/_src/data/Either/zip.ts +++ b/packages/stdlib/_src/data/Either/zip.ts @@ -6,8 +6,8 @@ * @tsplus pipeable Either zip */ export function zip(that: Either) { - return (self: Either): Either> => + return (self: Either): Either => self.flatMap( - (a) => that.map((b) => Tuple(a, b)) + (a) => that.map((b) => [a, b]) ) } diff --git a/packages/stdlib/_src/data/Either/zipValidation.ts b/packages/stdlib/_src/data/Either/zipValidation.ts index fb708fdd..5d067920 100644 --- a/packages/stdlib/_src/data/Either/zipValidation.ts +++ b/packages/stdlib/_src/data/Either/zipValidation.ts @@ -4,13 +4,13 @@ * @tsplus static Either.Ops zipValidation */ export function zipValidation(S: Associative) { - return (fa: Either, fb: Either): Either> => + return (fa: Either, fb: Either): Either => fa.fold( (ea) => fb.fold( (eb) => Either.left(S.combine(ea, eb)), () => Either.left(ea) ), - (a) => fb.fold(Either.left, (b) => Either.right(Tuple(a, b))) + (a) => fb.fold(Either.left, (b) => Either.right([a, b])) ) } diff --git a/packages/stdlib/_src/data/Maybe/dsl/separateF.ts b/packages/stdlib/_src/data/Maybe/dsl/separateF.ts index 3338ffad..bb4483eb 100644 --- a/packages/stdlib/_src/data/Maybe/dsl/separateF.ts +++ b/packages/stdlib/_src/data/Maybe/dsl/separateF.ts @@ -11,8 +11,8 @@ export const separateF = Wiltable.implementSeparateF()( }) => (G: Applicative) => (f: (a: A) => HKT.Kind>) => - (fa: Maybe): HKT.Kind, Maybe]>> => { - const maybe = fa.map((a) => G.map((e: Either) => Tuple(e.left, e.right))(f(a))) - return maybe.isNone() ? DSL.succeedF(G)(Tuple(Maybe.none, Maybe.none)) : maybe.value + (fa: Maybe): HKT.Kind, Maybe]> => { + const maybe = fa.map((a) => G.map((e: Either) => [e.left, e.right] as const)(f(a))) + return maybe.isNone() ? DSL.succeedF(G)([Maybe.none, Maybe.none]) : maybe.value } ) diff --git a/packages/stdlib/_src/data/Maybe/partition.ts b/packages/stdlib/_src/data/Maybe/partition.ts index 5b656c95..77cb5c9b 100644 --- a/packages/stdlib/_src/data/Maybe/partition.ts +++ b/packages/stdlib/_src/data/Maybe/partition.ts @@ -4,9 +4,10 @@ */ export function partition( f: Refinement -): (self: Maybe) => Tuple<[Maybe, Maybe]> -export function partition(f: Predicate): (self: Maybe) => Tuple<[Maybe, Maybe]> +): (self: Maybe) => readonly [Maybe, Maybe] +export function partition(f: Predicate): (self: Maybe) => readonly [Maybe, Maybe] export function partition(f: Predicate) { - return (self: Maybe): Tuple<[Maybe, Maybe]> => - Tuple(self.filter((a) => !f(a)), self.filter(f)) + return ( + self: Maybe + ): readonly [Maybe, Maybe] => [self.filter((a) => !f(a)), self.filter(f)] } diff --git a/packages/stdlib/_src/data/Maybe/partitionMap.ts b/packages/stdlib/_src/data/Maybe/partitionMap.ts index 6b3b1c99..61897a19 100644 --- a/packages/stdlib/_src/data/Maybe/partitionMap.ts +++ b/packages/stdlib/_src/data/Maybe/partitionMap.ts @@ -3,5 +3,5 @@ * @tsplus pipeable Maybe partitionMap */ export function partitionMap(f: (a: A) => Either) { - return (self: Maybe): Tuple<[Maybe, Maybe]> => self.map(f).separate + return (self: Maybe): readonly [Maybe, Maybe] => self.map(f).separate } diff --git a/packages/stdlib/_src/data/Maybe/separate.ts b/packages/stdlib/_src/data/Maybe/separate.ts index 7841fc4c..c8af421a 100644 --- a/packages/stdlib/_src/data/Maybe/separate.ts +++ b/packages/stdlib/_src/data/Maybe/separate.ts @@ -1,11 +1,11 @@ -const defaultSeparate = Tuple(Maybe.none, Maybe.none) +const defaultSeparate = [Maybe.none, Maybe.none] as const /** * @tsplus getter Maybe separate */ export function separate( self: Maybe> -): Tuple<[Maybe, Maybe]> { - const maybe = self.map((either) => Tuple(either.left, either.right)) +): readonly [Maybe, Maybe] { + const maybe = self.map((either) => [either.left, either.right] as const) return maybe.isNone() ? defaultSeparate : maybe.value } diff --git a/packages/stdlib/_src/data/Maybe/zip.ts b/packages/stdlib/_src/data/Maybe/zip.ts index cdd7258e..181f9497 100644 --- a/packages/stdlib/_src/data/Maybe/zip.ts +++ b/packages/stdlib/_src/data/Maybe/zip.ts @@ -6,6 +6,5 @@ * @tsplus pipeable Maybe zip */ export function zip(that: Maybe) { - return (self: Maybe): Maybe> => - self.flatMap((a) => that.map((b) => Tuple(a, b))) + return (self: Maybe): Maybe => self.flatMap((a) => that.map((b) => [a, b])) } diff --git a/packages/stdlib/_src/data/Tuple.ts b/packages/stdlib/_src/data/Tuple.ts deleted file mode 100644 index 1a77ac6b..00000000 --- a/packages/stdlib/_src/data/Tuple.ts +++ /dev/null @@ -1,12 +0,0 @@ -// codegen:start {preset: barrel, include: ./Tuple/*.ts, prefix: "@tsplus/stdlib/data"} -export * from "@tsplus/stdlib/data/Tuple/append" -export * from "@tsplus/stdlib/data/Tuple/at" -export * from "@tsplus/stdlib/data/Tuple/concat" -export * from "@tsplus/stdlib/data/Tuple/definition" -export * from "@tsplus/stdlib/data/Tuple/fromNative" -export * from "@tsplus/stdlib/data/Tuple/make" -export * from "@tsplus/stdlib/data/Tuple/mergeTuple" -export * from "@tsplus/stdlib/data/Tuple/prepend" -export * from "@tsplus/stdlib/data/Tuple/toNative" -export * from "@tsplus/stdlib/data/Tuple/update" -// codegen:end diff --git a/packages/stdlib/_src/data/Tuple/append.ts b/packages/stdlib/_src/data/Tuple/append.ts deleted file mode 100644 index b0657165..00000000 --- a/packages/stdlib/_src/data/Tuple/append.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Appends a value to a tuple. - * - * @tsplus static Tuple.Aspects append - * @tsplus pipeable Tuple append - */ -export function append(k: K) { - return (self: Tuple): Tuple<[...Ks, K]> => new Tuple([...self.tuple, k]) -} diff --git a/packages/stdlib/_src/data/Tuple/at.ts b/packages/stdlib/_src/data/Tuple/at.ts deleted file mode 100644 index 5002a66d..00000000 --- a/packages/stdlib/_src/data/Tuple/at.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Gets an element from the tuple. - * - * @tsplus static Tuple.Aspects at - * @tsplus pipeable Tuple at - */ -export function at(i: I) { - return (self: Tuple): Ks[I] => self.get(i) -} diff --git a/packages/stdlib/_src/data/Tuple/concat.ts b/packages/stdlib/_src/data/Tuple/concat.ts deleted file mode 100644 index d7f9661b..00000000 --- a/packages/stdlib/_src/data/Tuple/concat.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Concatenates two tuples. - * - * @tsplus pipeable-operator Tuple + - * @tsplus static Tuple.Aspects concat - * @tsplus pipeable Tuple concat - */ -export function concat(that: Tuple) { - return (self: Tuple): Tuple<[...Ks, ...Hs]> => - new Tuple( - [...self.tuple, ...that.tuple] - ) -} diff --git a/packages/stdlib/_src/data/Tuple/definition.ts b/packages/stdlib/_src/data/Tuple/definition.ts deleted file mode 100644 index 5fb3b9a1..00000000 --- a/packages/stdlib/_src/data/Tuple/definition.ts +++ /dev/null @@ -1,64 +0,0 @@ -export const TupleSym: unique symbol = Symbol.for("Tuple") -export type TupleSym = typeof TupleSym - -/** - * A `Tuple` represents an immutable, finite ordered sequence of elements. - * - * @tsplus type Tuple - * @tsplus companion Tuple.Ops - */ -export class Tuple implements Collection, Equals { - readonly [TupleSym]: TupleSym = TupleSym - - constructor(readonly tuple: T) {} - - [Symbol.iterator](): IterableIterator { - return this.tuple[Symbol.iterator]() - } - - [Hash.sym](): number { - return Hash.array(this.tuple) - } - - [Equals.sym](that: unknown): boolean { - if (isTuple(that)) { - return ( - this.tuple.length === that.tuple.length && - this.tuple.every((v, i) => Equals.equals(v, that.tuple[i])) - ) - } - return false - } - - get(i: K): T[K] { - return this.tuple[i] - } -} - -/** - * @tsplus static Tuple.Ops $ - */ -export const TupleAspects: TupleAspects = {} - -/** - * @tsplus type Tuple.Aspects - */ -export interface TupleAspects {} - -/** - * @tsplus unify Tuple - */ -export function unifyTuple>( - self: X -): Tuple<[X] extends [Tuple] ? A : never> { - return self -} - -/** - * Checks if the provided value is a `Tuple`. - * - * @tsplus static Tuple.Ops isTuple - */ -export function isTuple(self: unknown): self is Tuple { - return typeof self === "object" && self != null && TupleSym in self -} diff --git a/packages/stdlib/_src/data/Tuple/fromNative.ts b/packages/stdlib/_src/data/Tuple/fromNative.ts deleted file mode 100644 index 3b88f448..00000000 --- a/packages/stdlib/_src/data/Tuple/fromNative.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Converts from native tuple type. - * - * @tsplus static Tuple.Ops fromNative - */ -export function fromNative(self: Ks): Tuple { - return new Tuple(self) -} diff --git a/packages/stdlib/_src/data/Tuple/make.ts b/packages/stdlib/_src/data/Tuple/make.ts deleted file mode 100644 index 5d636497..00000000 --- a/packages/stdlib/_src/data/Tuple/make.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Creates a new `Tuple`. - * - * @tsplus static Tuple.Ops __call - * @tsplus static Tuple.Ops make - */ -export function make(...args: Ks): Tuple { - return new Tuple(args) -} diff --git a/packages/stdlib/_src/data/Tuple/mergeTuple.ts b/packages/stdlib/_src/data/Tuple/mergeTuple.ts deleted file mode 100644 index 30d8d560..00000000 --- a/packages/stdlib/_src/data/Tuple/mergeTuple.ts +++ /dev/null @@ -1,19 +0,0 @@ -export type MergeTuple = A extends Tuple - ? B extends Tuple ? Tuple<[...TA, ...TB]> - : Tuple<[...TA, B]> - : B extends Tuple ? Tuple<[A, ...TB]> - : Tuple<[A, B]> - -/** - * @tsplus static Tuple.Ops mergeTuple - */ -export function mergeTuple(_a: A, _b: A2): MergeTuple { - // @ts-expect-error - return Tuple.isTuple(_a) && Tuple.isTuple(_b) - ? Tuple(..._a.tuple, ..._b.tuple) - : Tuple.isTuple(_a) - ? Tuple(..._a.tuple, _b) - : Tuple.isTuple(_b) - ? Tuple(_a, ..._b.tuple) - : Tuple(_a, _b) -} diff --git a/packages/stdlib/_src/data/Tuple/prepend.ts b/packages/stdlib/_src/data/Tuple/prepend.ts deleted file mode 100644 index 56a1dc88..00000000 --- a/packages/stdlib/_src/data/Tuple/prepend.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Prepends a value to a tuple. - * - * @tsplus static Tuple.Aspects prepend - * @tsplus pipeable Tuple prepend - */ -export function prepend(k: K) { - return (self: Tuple): Tuple<[K, ...Ks]> => new Tuple([k, ...self.tuple]) -} diff --git a/packages/stdlib/_src/data/Tuple/toNative.ts b/packages/stdlib/_src/data/Tuple/toNative.ts deleted file mode 100644 index 69c66c93..00000000 --- a/packages/stdlib/_src/data/Tuple/toNative.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Converts to native tuple type. - * - * @tsplus getter Tuple toNative - */ -export function toNative(self: Tuple): Ks { - return self.tuple -} diff --git a/packages/stdlib/_src/data/Tuple/update.ts b/packages/stdlib/_src/data/Tuple/update.ts deleted file mode 100644 index e7be4ebe..00000000 --- a/packages/stdlib/_src/data/Tuple/update.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Replaces the element in position `I`. - * - * @tsplus static Tuple.Aspects update - * @tsplus pipeable Tuple update - */ -export function update( - i: I, - f: (_: Ks[I]) => J -) { - return (self: Tuple): Tuple< - ForcedArray< - { - [k in keyof Ks]: k extends `${I}` ? J : Ks[k] - } - > - > => { - const len = self.tuple.length - const r = new Array(len) - for (let k = 0; k < len; k++) { - if (k === i) { - r[k] = f(self.tuple[k]) - } else { - r[k] = self.tuple[k] - } - } - return new Tuple(r) as any - } -} diff --git a/packages/stdlib/_src/global.ts b/packages/stdlib/_src/global.ts index 79b73450..ebe4699e 100644 --- a/packages/stdlib/_src/global.ts +++ b/packages/stdlib/_src/global.ts @@ -137,10 +137,6 @@ import { Predicate } from "@tsplus/stdlib/data/Predicate" * @tsplus global */ import { Stack } from "@tsplus/stdlib/data/Stack" -/** - * @tsplus global - */ -import { Tuple } from "@tsplus/stdlib/data/Tuple/definition" /** * @tsplus global */ @@ -453,7 +449,6 @@ import { ESIterable, ESReadonlyArray, ForcedArray, - ForcedTuple, IsInt, MergeRecord, OrElse, diff --git a/packages/stdlib/_src/io/Eval/tuple.ts b/packages/stdlib/_src/io/Eval/tuple.ts index bdec7dff..02752c6c 100644 --- a/packages/stdlib/_src/io/Eval/tuple.ts +++ b/packages/stdlib/_src/io/Eval/tuple.ts @@ -9,7 +9,7 @@ export function tuple[]>( readonly 1: Eval } ): Eval< - Tuple< + Readonly< { [K in keyof EN]: [EN[K]] extends [Eval] ? A : never } @@ -17,7 +17,7 @@ export function tuple[]>( > { const init = e1.zip(e2) return es.reduce( - (acc, v) => acc.zipWith(v, (a, b) => Tuple.mergeTuple(a, b)), + (acc: Eval, v) => acc.zipWith(v, (a, b) => [...a, b]), init ) } diff --git a/packages/stdlib/_src/io/Eval/zip.ts b/packages/stdlib/_src/io/Eval/zip.ts index ed15d73a..0a321e97 100644 --- a/packages/stdlib/_src/io/Eval/zip.ts +++ b/packages/stdlib/_src/io/Eval/zip.ts @@ -6,5 +6,5 @@ * @tsplus pipeable Eval zip */ export function zip(that: Eval) { - return (self: Eval): Eval> => self.zipWith(that, (a, b) => Tuple(a, b)) + return (self: Eval): Eval => self.zipWith(that, (a, b) => [a, b]) } diff --git a/packages/stdlib/_src/prelude/AssociativeBoth.ts b/packages/stdlib/_src/prelude/AssociativeBoth.ts index 43d5466f..ea52f619 100644 --- a/packages/stdlib/_src/prelude/AssociativeBoth.ts +++ b/packages/stdlib/_src/prelude/AssociativeBoth.ts @@ -12,5 +12,5 @@ export interface AssociativeBoth extends HKT.Typeclass { fb: HKT.Kind ) => ( fa: HKT.Kind - ) => HKT.Kind> + ) => HKT.Kind } diff --git a/packages/stdlib/_src/prelude/DSL/apF.ts b/packages/stdlib/_src/prelude/DSL/apF.ts index c89bd4ab..c19bd209 100644 --- a/packages/stdlib/_src/prelude/DSL/apF.ts +++ b/packages/stdlib/_src/prelude/DSL/apF.ts @@ -6,7 +6,7 @@ export function apF_(F: Apply) { fab: HKT.Kind B>, fa: HKT.Kind ): HKT.Kind => - F.map(({ tuple: [a, f] }: Tuple<[A, (a: A) => B]>) => f(a))(F.both(fab)(fa)) + F.map(([a, f]: readonly [A, (a: A) => B]) => f(a))(F.both(fab)(fa)) } /** diff --git a/packages/stdlib/_src/prelude/DSL/getApplyF.ts b/packages/stdlib/_src/prelude/DSL/getApplyF.ts index f55d324d..0518a40f 100644 --- a/packages/stdlib/_src/prelude/DSL/getApplyF.ts +++ b/packages/stdlib/_src/prelude/DSL/getApplyF.ts @@ -8,7 +8,7 @@ export function getApplyF(F: Monad): Apply { both: ( fb: HKT.Kind ) => - (fa: HKT.Kind): HKT.Kind> => - flatMap_(fb, (b) => F.map((a: A) => Tuple(a, b))(fa)) + (fa: HKT.Kind): HKT.Kind => + flatMap_(fb, (b) => F.map((a: A) => [a, b] as const)(fa)) }) } diff --git a/packages/stdlib/_src/prelude/DSL/getValidationF.ts b/packages/stdlib/_src/prelude/DSL/getValidationF.ts index a1fdcdd8..30707d3f 100644 --- a/packages/stdlib/_src/prelude/DSL/getValidationF.ts +++ b/packages/stdlib/_src/prelude/DSL/getValidationF.ts @@ -18,7 +18,7 @@ export function getValidationF(M: Monad & Run & Fail & A (fa: HKT.Kind) => { const both = M.both(M.either(fb))(M.either(fa)) return M.flatten( - M.map(({ tuple: [eitherA, eitherB] }: Tuple<[Either, Either]>) => + M.map(([eitherA, eitherB]: readonly [Either, Either]) => eitherA.fold( (ea) => eitherB.fold( @@ -28,7 +28,7 @@ export function getValidationF(M: Monad & Run & Fail & A (a) => eitherB.fold( (e) => M.fail(e), - (b) => DSL.succeedF(M)(Tuple(a, b)) + (b) => DSL.succeedF(M)([a, b] as const) ) ) )(both) diff --git a/packages/stdlib/_src/prelude/DSL/zip.ts b/packages/stdlib/_src/prelude/DSL/zip.ts index 25332ac8..2592ba08 100644 --- a/packages/stdlib/_src/prelude/DSL/zip.ts +++ b/packages/stdlib/_src/prelude/DSL/zip.ts @@ -5,7 +5,7 @@ export function zipF_(F: Apply) { return ( fa: HKT.Kind, fb: HKT.Kind - ): HKT.Kind> => F.both(fb)(fa) + ): HKT.Kind => F.both(fb)(fa) } /** @@ -13,6 +13,6 @@ export function zipF_(F: Apply) { */ export function zipF(F: Apply) { return (fb: HKT.Kind) => - (fa: HKT.Kind): HKT.Kind> => + (fa: HKT.Kind): HKT.Kind => zipF_(F)(fa, fb) } diff --git a/packages/stdlib/_src/prelude/Equivalence/tuple.ts b/packages/stdlib/_src/prelude/Equivalence/tuple.ts index b9cccc19..e392e7e6 100644 --- a/packages/stdlib/_src/prelude/Equivalence/tuple.ts +++ b/packages/stdlib/_src/prelude/Equivalence/tuple.ts @@ -6,11 +6,11 @@ export function tuple>>( ...eqs: T ): Equivalence< - ForcedTuple< + Readonly< { [K in keyof T]: T[K] extends Equivalence ? A : never } > > { - return Equivalence((x, y) => eqs.every((E, i) => E.equals(x.get(i), y.get(i)))) + return Equivalence((x, y) => eqs.every((E, i) => E.equals(x[i], y[i]))) } diff --git a/packages/stdlib/_src/prelude/Equivalence/zip.ts b/packages/stdlib/_src/prelude/Equivalence/zip.ts index 14571404..87f5ee48 100644 --- a/packages/stdlib/_src/prelude/Equivalence/zip.ts +++ b/packages/stdlib/_src/prelude/Equivalence/zip.ts @@ -8,9 +8,9 @@ export function zip_( self: Equivalence, that: Equivalence -): Equivalence> { +): Equivalence { return Equivalence( - ({ tuple: [x0, x1] }, { tuple: [y0, y1] }) => self.equals(x0, y0) && that.equals(x1, y1) + ([x0, x1], [y0, y1]) => self.equals(x0, y0) && that.equals(x1, y1) ) } diff --git a/packages/stdlib/_src/prelude/Ord/tuple.ts b/packages/stdlib/_src/prelude/Ord/tuple.ts index b64811d2..6f4923d4 100644 --- a/packages/stdlib/_src/prelude/Ord/tuple.ts +++ b/packages/stdlib/_src/prelude/Ord/tuple.ts @@ -1,8 +1,10 @@ export type NonEmptyArrayOrd = Array> & { readonly 0: Ord } -export type TupleOrd = { - [K in keyof T]: [T[K]] extends [Ord] ? A : never -} +export type TupleOrd = Readonly< + { + [K in keyof T]: [T[K]] extends [Ord] ? A : never + } +> /** * Derives an Ord instance for a tuple @@ -13,7 +15,7 @@ export function tuple( ...ords: T & { readonly 0: Ord } -): Ord>> { +): Ord> { return Ord((first, second) => { let i = 0 for (; i < ords.length - 1; i++) { diff --git a/packages/stdlib/_src/prelude/Partition.ts b/packages/stdlib/_src/prelude/Partition.ts index 36518e63..39e8a8bc 100644 --- a/packages/stdlib/_src/prelude/Partition.ts +++ b/packages/stdlib/_src/prelude/Partition.ts @@ -8,9 +8,9 @@ export interface Partition extends HKT.Typeclass { readonly partition: { (refinement: Refinement): ( fa: HKT.Kind - ) => Tuple<[HKT.Kind, HKT.Kind]> + ) => readonly [HKT.Kind, HKT.Kind] (predicate: Predicate): ( fa: HKT.Kind - ) => Tuple<[HKT.Kind, HKT.Kind]> + ) => readonly [HKT.Kind, HKT.Kind] } } diff --git a/packages/stdlib/_src/prelude/PartitionMap.ts b/packages/stdlib/_src/prelude/PartitionMap.ts index 4a32d283..9c91206a 100644 --- a/packages/stdlib/_src/prelude/PartitionMap.ts +++ b/packages/stdlib/_src/prelude/PartitionMap.ts @@ -9,5 +9,5 @@ export interface PartitionMap extends HKT.Typeclass { f: (a: A) => Either ) => ( fa: HKT.Kind - ) => Tuple<[HKT.Kind, HKT.Kind]> + ) => readonly [HKT.Kind, HKT.Kind] } diff --git a/packages/stdlib/_src/prelude/PartitionMapWithIndex.ts b/packages/stdlib/_src/prelude/PartitionMapWithIndex.ts index f78f0259..c7f93ef9 100644 --- a/packages/stdlib/_src/prelude/PartitionMapWithIndex.ts +++ b/packages/stdlib/_src/prelude/PartitionMapWithIndex.ts @@ -9,5 +9,5 @@ export interface PartitionMapWithIndex extends HKT.Typeclass Either ) => ( fa: HKT.Kind - ) => Tuple<[HKT.Kind, HKT.Kind]> + ) => readonly [HKT.Kind, HKT.Kind] } diff --git a/packages/stdlib/_src/prelude/PartitionWithIndex.ts b/packages/stdlib/_src/prelude/PartitionWithIndex.ts index e9a94efd..0273a89b 100644 --- a/packages/stdlib/_src/prelude/PartitionWithIndex.ts +++ b/packages/stdlib/_src/prelude/PartitionWithIndex.ts @@ -12,9 +12,9 @@ export declare namespace PartitionWithIndex { export interface Fn { (refinement: RefinementWithIndex): ( fa: HKT.Kind - ) => Tuple<[HKT.Kind, HKT.Kind]> + ) => readonly [HKT.Kind, HKT.Kind] (predicate: PredicateWithIndex): ( fa: HKT.Kind - ) => Tuple<[HKT.Kind, HKT.Kind]> + ) => readonly [HKT.Kind, HKT.Kind] } } diff --git a/packages/stdlib/_src/prelude/Selective.ts b/packages/stdlib/_src/prelude/Selective.ts index de3c7a24..72a2eb11 100644 --- a/packages/stdlib/_src/prelude/Selective.ts +++ b/packages/stdlib/_src/prelude/Selective.ts @@ -54,9 +54,7 @@ export function applicativeF(F: Applicative): Selective { select: (fab: HKT.Kind B>) => (fa: HKT.Kind>): HKT.Kind => { const both = F.both(fab)(fa) - return F.map( - ({ tuple: [ea, f] }: Tuple<[Either, (a: A) => B]>) => ea.fold(f, identity) - )(both) + return F.map(([ea, f]: readonly [Either, (a: A) => B]) => ea.fold(f, identity))(both) } }) } diff --git a/packages/stdlib/_src/prelude/Separate.ts b/packages/stdlib/_src/prelude/Separate.ts index e13839ce..7dc4c683 100644 --- a/packages/stdlib/_src/prelude/Separate.ts +++ b/packages/stdlib/_src/prelude/Separate.ts @@ -7,5 +7,5 @@ export interface Separate extends HKT.Typeclass { } readonly separate: ( fa: HKT.Kind> - ) => Tuple<[HKT.Kind, HKT.Kind]> + ) => readonly [HKT.Kind, HKT.Kind] } diff --git a/packages/stdlib/_src/prelude/Wiltable.ts b/packages/stdlib/_src/prelude/Wiltable.ts index f39f1e3a..d3683ae4 100644 --- a/packages/stdlib/_src/prelude/Wiltable.ts +++ b/packages/stdlib/_src/prelude/Wiltable.ts @@ -19,7 +19,7 @@ export interface Wilt { f: (a: A) => HKT.Kind> ) => ( ta: HKT.Kind - ) => HKT.Kind, HKT.Kind]>> + ) => HKT.Kind, HKT.Kind]> } /** @@ -44,7 +44,7 @@ export function implementSeparateF(): ( f: (a: A) => HKT.Kind> ) => ( ta: HKT.Kind - ) => HKT.Kind, HKT.Kind]>> + ) => HKT.Kind, HKT.Kind]> ) => Wilt export function implementSeparateF() { return (i: any) => i() diff --git a/packages/stdlib/_src/prelude/WiltableWithIndex.ts b/packages/stdlib/_src/prelude/WiltableWithIndex.ts index 7356fcd5..6f250e15 100644 --- a/packages/stdlib/_src/prelude/WiltableWithIndex.ts +++ b/packages/stdlib/_src/prelude/WiltableWithIndex.ts @@ -19,7 +19,7 @@ export interface WiltWithIndex extends HKT.Typeclass { f: (k: K, a: A) => HKT.Kind> ) => ( ta: HKT.Kind - ) => HKT.Kind, HKT.Kind]>> + ) => HKT.Kind, HKT.Kind]> } /** @@ -38,7 +38,7 @@ export function implementSeparateWithIndexF(): ( f: (k: K, a: A) => HKT.Kind> ) => ( ta: HKT.Kind - ) => HKT.Kind, HKT.Kind]>> + ) => HKT.Kind, HKT.Kind]> ) => WiltWithIndex export function implementSeparateWithIndexF() { return (i: any) => i() diff --git a/packages/stdlib/_src/utilities/Types.ts b/packages/stdlib/_src/utilities/Types.ts index 493836ed..7d22df9d 100644 --- a/packages/stdlib/_src/utilities/Types.ts +++ b/packages/stdlib/_src/utilities/Types.ts @@ -5,8 +5,6 @@ export type MergeRecord = { } extends infer X ? X : never -export type ForcedTuple = A extends unknown[] ? Tuple : never - export type ForcedArray = A extends readonly any[] ? A : [] export type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ( diff --git a/packages/stdlib/_test/Chunk.test.ts b/packages/stdlib/_test/Chunk.test.ts index 4fa317d8..b353dfa0 100644 --- a/packages/stdlib/_test/Chunk.test.ts +++ b/packages/stdlib/_test/Chunk.test.ts @@ -303,18 +303,18 @@ describe.concurrent("Chunk", () => { it("mapWithIndex", () => { const chunk = Chunk(1, 2, 3, 4, 5, 6, 7) - const result = chunk.mapWithIndex((i, n) => Tuple(i, n)).toImmutableArray + const result = chunk.mapWithIndex((i, n) => [i, n]).toImmutableArray assert.isTrue( result == ImmutableArray( - Tuple(0, 1), - Tuple(1, 2), - Tuple(2, 3), - Tuple(3, 4), - Tuple(4, 5), - Tuple(5, 6), - Tuple(6, 7) + [0, 1], + [1, 2], + [2, 3], + [3, 4], + [4, 5], + [5, 6], + [6, 7] ) ) }) @@ -322,40 +322,40 @@ describe.concurrent("Chunk", () => { it("partition", () => { assert.isTrue( Chunk.empty().partition((n) => n > 2) == - Tuple(Chunk.empty(), Chunk.empty()) + [Chunk.empty(), Chunk.empty()] ) - assert.isTrue(Chunk(1, 3).partition((n) => n > 2) == Tuple(Chunk(1), Chunk(3))) + assert.isTrue(Chunk(1, 3).partition((n) => n > 2) == [Chunk(1), Chunk(3)]) }) it("partitionMap", () => { assert.isTrue( Chunk.empty>().partitionMap(identity) == - Tuple(Chunk.empty(), Chunk.empty()) + [Chunk.empty(), Chunk.empty()] ) assert.isTrue( Chunk(Either.right(1), Either.left("foo"), Either.right(2)).partitionMap(identity) == - Tuple(Chunk("foo"), Chunk(1, 2)) + [Chunk("foo"), Chunk(1, 2)] ) }) it("partitionMapWithIndex", () => { assert.isTrue( Chunk.empty>().partitionMapWithIndex((_, a) => a) == - Tuple(Chunk.empty(), Chunk.empty()) + [Chunk.empty(), Chunk.empty()] ) assert.isTrue( Chunk(Either.right(1), Either.left("foo"), Either.right(2)) .partitionMapWithIndex((i, a) => a.filterOrElse((n) => n > i, () => "woops")) == - Tuple(Chunk("foo", "woops"), Chunk(1)) + [Chunk("foo", "woops"), Chunk(1)] ) }) it("partitionWithIndex", () => { assert.isTrue( Chunk.empty().partitionWithIndex((i, n) => i + n > 2) == - Tuple(Chunk.empty(), Chunk.empty()) + [Chunk.empty(), Chunk.empty()] ) - assert.isTrue(Chunk(1, 2).partitionWithIndex((i, n) => i + n > 2) == Tuple(Chunk(1), Chunk(2))) + assert.isTrue(Chunk(1, 2).partitionWithIndex((i, n) => i + n > 2) == [Chunk(1), Chunk(2)]) }) it("prepend", () => { @@ -369,19 +369,19 @@ describe.concurrent("Chunk", () => { const chunk = Chunk(1, 2, 3, 4, 5, 6, 7) const result = chunk.reduceWithIndex( - ImmutableArray.empty>(), - (i, acc, n) => acc + Tuple(i, n) + ImmutableArray.empty(), + (i, acc, n) => acc + [i, n] ) assert.isTrue( result == ImmutableArray( - Tuple(0, 1), - Tuple(1, 2), - Tuple(2, 3), - Tuple(3, 4), - Tuple(4, 5), - Tuple(5, 6), - Tuple(6, 7) + [0, 1], + [1, 2], + [2, 3], + [3, 4], + [4, 5], + [5, 6], + [6, 7] ) ) }) @@ -390,20 +390,20 @@ describe.concurrent("Chunk", () => { const chunk = Chunk(1, 2, 3, 4, 5, 6, 7) const result = chunk.reduceRightWithIndex( - ImmutableArray.empty>(), - (i, n, acc) => acc + Tuple(i, n) + ImmutableArray.empty(), + (i, n, acc) => acc + [i, n] ) assert.isTrue( result == ImmutableArray( - Tuple(6, 7), - Tuple(5, 6), - Tuple(4, 5), - Tuple(3, 4), - Tuple(2, 3), - Tuple(1, 2), - Tuple(0, 1) + [6, 7], + [5, 6], + [4, 5], + [3, 4], + [2, 3], + [1, 2], + [0, 1] ) ) }) @@ -415,7 +415,7 @@ describe.concurrent("Chunk", () => { const result = chunk.separate - assert.isTrue(result == Tuple(Chunk("1", "3", "5"), Chunk(2, 4, 6))) + assert.isTrue(result == [Chunk("1", "3", "5"), Chunk(2, 4, 6)]) }) it("separateF", () => { @@ -424,9 +424,9 @@ describe.concurrent("Chunk", () => { ) assert.isTrue( - separateF(Chunk.empty()) == Maybe.some(Tuple(Chunk.empty(), Chunk.empty())) + separateF(Chunk.empty()) == Maybe.some([Chunk.empty(), Chunk.empty()]) ) - assert.isTrue(separateF(Chunk(1, 3)) == Maybe.some(Tuple(Chunk(0), Chunk(4)))) + assert.isTrue(separateF(Chunk(1, 3)) == Maybe.some([Chunk(0), Chunk(4)])) }) it("separateWithIndexF", () => { @@ -436,9 +436,9 @@ describe.concurrent("Chunk", () => { assert.isTrue( separateWithIndexF(Chunk.empty()) == - Maybe.some(Tuple(Chunk.empty(), Chunk.empty())) + Maybe.some([Chunk.empty(), Chunk.empty()]) ) - assert.isTrue(separateWithIndexF(Chunk(1, 3)) == Maybe.some(Tuple(Chunk(1), Chunk(4)))) + assert.isTrue(separateWithIndexF(Chunk(1, 3)) == Maybe.some([Chunk(1), Chunk(4)])) }) describe.concurrent("sort", () => { @@ -562,9 +562,7 @@ describe.concurrent("Chunk", () => { it("splitWhere", () => { const chunk = Chunk(0, 1, 2, 3, 4, 5) - const { - tuple: [left, right] - } = chunk.splitWhere((n) => n === 3) + const [left, right] = chunk.splitWhere((n) => n === 3) assert.isTrue(left == Chunk(0, 1, 2)) assert.isTrue(right == Chunk(3, 4, 5)) @@ -661,8 +659,8 @@ describe.concurrent("Chunk", () => { const resultA = leftChunk.zip(rightChunk).toImmutableArray const resultB = rightChunk.zip(leftChunk).toImmutableArray - assert.isTrue(resultA == ImmutableArray(Tuple(0, 0), Tuple(1, 1), Tuple(2, 2), Tuple(3, 3))) - assert.isTrue(resultB == ImmutableArray(Tuple(0, 0), Tuple(1, 1), Tuple(2, 2), Tuple(3, 3))) + assert.isTrue(resultA == ImmutableArray([0, 0], [1, 1], [2, 2], [3, 3])) + assert.isTrue(resultB == ImmutableArray([0, 0], [1, 1], [2, 2], [3, 3])) }) it("zipAll", () => { @@ -674,20 +672,20 @@ describe.concurrent("Chunk", () => { assert.isTrue( resultA == ImmutableArray( - Tuple(Maybe.some(0), Maybe.some(0)), - Tuple(Maybe.some(1), Maybe.some(1)), - Tuple(Maybe.some(2), Maybe.some(2)), - Tuple(Maybe.some(3), Maybe.some(3)), - Tuple(Maybe.none, Maybe.some(4)) + [Maybe.some(0), Maybe.some(0)], + [Maybe.some(1), Maybe.some(1)], + [Maybe.some(2), Maybe.some(2)], + [Maybe.some(3), Maybe.some(3)], + [Maybe.none, Maybe.some(4)] ) ) assert.isTrue( resultB == ImmutableArray( - Tuple(Maybe.some(0), Maybe.some(0)), - Tuple(Maybe.some(1), Maybe.some(1)), - Tuple(Maybe.some(2), Maybe.some(2)), - Tuple(Maybe.some(3), Maybe.some(3)), - Tuple(Maybe.some(4), Maybe.none) + [Maybe.some(0), Maybe.some(0)], + [Maybe.some(1), Maybe.some(1)], + [Maybe.some(2), Maybe.some(2)], + [Maybe.some(3), Maybe.some(3)], + [Maybe.some(4), Maybe.none] ) ) }) @@ -697,6 +695,6 @@ describe.concurrent("Chunk", () => { const result = chunk.zipWithIndex.toImmutableArray - assert.isTrue(result == ImmutableArray(Tuple(1, 0), Tuple(2, 1), Tuple(3, 2), Tuple(4, 3))) + assert.isTrue(result == ImmutableArray([1, 0], [2, 1], [3, 2], [4, 3])) }) }) diff --git a/packages/stdlib/_test/Differ.test.ts b/packages/stdlib/_test/Differ.test.ts index fe8e99b4..29112bc0 100644 --- a/packages/stdlib/_test/Differ.test.ts +++ b/packages/stdlib/_test/Differ.test.ts @@ -77,8 +77,8 @@ function randomEither(): Either { return Math.random() < 0.5 ? Either.left(smallInt()) : Either.right(smallInt()) } -function randomTuple(): Tuple<[number, number]> { - return Tuple(smallInt(), smallInt()) +function randomTuple(): readonly [number, number] { + return [smallInt(), smallInt()] } describe.concurrent("Differ", () => { diff --git a/packages/stdlib/_test/Either.test.ts b/packages/stdlib/_test/Either.test.ts index a25f2f15..992f118a 100644 --- a/packages/stdlib/_test/Either.test.ts +++ b/packages/stdlib/_test/Either.test.ts @@ -1,5 +1,3 @@ -import { Tuple } from "@tsplus/stdlib/data/Tuple" - describe.concurrent("Either", () => { it("value right", () => { assert.isTrue(Either.right(0).right == Maybe.some(0)) @@ -220,10 +218,10 @@ describe.concurrent("Either", () => { const f = separateF((n: number) => Maybe.some(p(n) ? Either.right(n + 1) : Either.left(n - 1))) assert.isTrue( - f(Either.left("foo")) == Maybe.some(Tuple(Either.left("foo"), Either.left("foo"))) + f(Either.left("foo")) == Maybe.some([Either.left("foo"), Either.left("foo")]) ) - assert.isTrue(f(Either.right(1)) == Maybe.some(Tuple(Either.right(0), Either.left("")))) - assert.isTrue(f(Either.right(3)) == Maybe.some(Tuple(Either.left(""), Either.right(4)))) + assert.isTrue(f(Either.right(1)) == Maybe.some([Either.right(0), Either.left("")])) + assert.isTrue(f(Either.right(3)) == Maybe.some([Either.left(""), Either.right(4)])) }) it("getOrElse", () => { @@ -347,7 +345,7 @@ describe.concurrent("Either", () => { }) it("zip", () => { - assert.isTrue(Either.right(0).zip(Either.right(1)) == Either.right(Tuple(0, 1))) + assert.isTrue(Either.right(0).zip(Either.right(1)) == Either.right([0, 1])) assert.isTrue(Either.right(0).zip(Either.left(1)) == Either.left(1)) }) diff --git a/packages/stdlib/_test/Eval.test.ts b/packages/stdlib/_test/Eval.test.ts index 363274e5..aaf981c2 100644 --- a/packages/stdlib/_test/Eval.test.ts +++ b/packages/stdlib/_test/Eval.test.ts @@ -74,7 +74,7 @@ describe.concurrent("Eval", () => { const result = program.run - assert.isTrue(result == Tuple(0, "a", true)) + assert.isTrue(result == [0, "a", true]) }) it("unit", () => { @@ -88,7 +88,7 @@ describe.concurrent("Eval", () => { const result = program.run - assert.isTrue(result == Tuple(0, 1)) + assert.isTrue(result == [0, 1]) }) it("zipLeft", () => { diff --git a/packages/stdlib/_test/HashMap.test.ts b/packages/stdlib/_test/HashMap.test.ts index e99b9fc0..83fa9e6b 100644 --- a/packages/stdlib/_test/HashMap.test.ts +++ b/packages/stdlib/_test/HashMap.test.ts @@ -32,28 +32,28 @@ describe.concurrent("HashMap", () => { } it("has", () => { - const hashMap = HashMap(Tuple(key(0), value("a"))) + const hashMap = HashMap([key(0), value("a")]) assert.isTrue(hashMap.has(key(0))) assert.isFalse(hashMap.has(key(1))) }) it("hasHash", () => { - const hashMap = HashMap(Tuple(key(0), value("a"))) + const hashMap = HashMap([key(0), value("a")]) assert.isTrue(hashMap.hasHash(key(0), Hash.unknown(key(0)))) assert.isFalse(hashMap.hasHash(key(1), Hash.unknown(key(0)))) }) it("get", () => { - const hashMap = HashMap(Tuple(key(0), value("a"))) + const hashMap = HashMap([key(0), value("a")]) assert.isTrue(hashMap[key(0)] == Maybe.some(value("a"))) assert.isTrue(hashMap[key(1)] == Maybe.none) }) it("getHash", () => { - const hashMap = HashMap(Tuple(key(0), value("a"))) + const hashMap = HashMap([key(0), value("a")]) assert.isTrue(hashMap.getHash(key(0), Hash.unknown(0)) == Maybe.some(value("a"))) assert.isTrue(hashMap.getHash(key(1), Hash.unknown(0)) == Maybe.none) @@ -93,7 +93,7 @@ describe.concurrent("HashMap", () => { }) it("flatMap", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("bb"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("bb")]) const result = hashMap.flatMap(({ s }) => { const newKey = key(s.length) @@ -107,7 +107,7 @@ describe.concurrent("HashMap", () => { }) it("chainWithIndex", () => { - const hashMap = HashMap(Tuple(key(1), value("a")), Tuple(key(2), value("bb"))) + const hashMap = HashMap([key(1), value("a")], [key(2), value("bb")]) const result = hashMap.flatMapWithIndex(({ n }, { s }) => { const newKey = key(s.length + n) @@ -121,7 +121,7 @@ describe.concurrent("HashMap", () => { }) it("collect", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("bb"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("bb")]) const result = hashMap.collect(({ s }) => s.length > 1 ? Maybe.some(value(s)) : Maybe.none) @@ -130,7 +130,7 @@ describe.concurrent("HashMap", () => { }) it("collectWithIndex", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("bb"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("bb")]) const result = hashMap.collectWithIndex(({ n }, v) => n > 0 ? Maybe.some(v) : Maybe.none) @@ -139,7 +139,7 @@ describe.concurrent("HashMap", () => { }) it("compact", () => { - const hashMap = HashMap(Tuple(0, Maybe.some("a")), Tuple(1, Maybe.none)) + const hashMap = HashMap([0, Maybe.some("a")], [1, Maybe.none]) const result = hashMap.compact @@ -148,7 +148,7 @@ describe.concurrent("HashMap", () => { }) it("filter", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("bb"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("bb")]) const result = hashMap.filter(({ s }) => s.length > 1) @@ -157,7 +157,7 @@ describe.concurrent("HashMap", () => { }) it("filterWithIndex", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("bb"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("bb")]) const result = hashMap.filterWithIndex(({ n }, { s }) => n > 0 && s.length > 0) @@ -166,7 +166,7 @@ describe.concurrent("HashMap", () => { }) it("forEach", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("b")]) const result: Array = [] hashMap.forEach((v) => { @@ -177,7 +177,7 @@ describe.concurrent("HashMap", () => { }) it("forEachWithIndex", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("b")]) const result: Array<[number, string]> = [] hashMap.forEachWithIndex(({ n }, { s }) => { @@ -189,11 +189,11 @@ describe.concurrent("HashMap", () => { it("isEmpty", () => { assert.isTrue(HashMap().isEmpty) - assert.isFalse(HashMap(Tuple(key(0), value("a"))).isEmpty) + assert.isFalse(HashMap([key(0), value("a")]).isEmpty) }) it("keys", () => { - const hashMap = HashMap(Tuple(0, "a"), Tuple(1, "b")) + const hashMap = HashMap([0, "a"], [1, "b"]) const result = hashMap.keys @@ -202,9 +202,9 @@ describe.concurrent("HashMap", () => { it("keySet", () => { const hashMap = HashMap( - Tuple(key(0), value("a")), - Tuple(key(1), value("b")), - Tuple(key(1), value("c")) + [key(0), value("a")], + [key(1), value("b")], + [key(1), value("c")] ) const result = hashMap.keySet @@ -213,7 +213,7 @@ describe.concurrent("HashMap", () => { }) it("map", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("bb"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("bb")]) const result = hashMap.map(({ s }) => s.length) @@ -223,7 +223,7 @@ describe.concurrent("HashMap", () => { }) it("mapWithIndex", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("bb"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("bb")]) const result = hashMap.mapWithIndex(({ n }, { s }) => n + s.length) @@ -233,7 +233,7 @@ describe.concurrent("HashMap", () => { }) it("modify", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("b")]) const result = hashMap.modify( key(0), @@ -246,7 +246,7 @@ describe.concurrent("HashMap", () => { }) it("modifyHash", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("b")]) const result = hashMap.modifyHash( key(0), @@ -260,7 +260,7 @@ describe.concurrent("HashMap", () => { }) it("reduce", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("b")]) const result = hashMap.reduce("", (acc, { s }) => acc.length > 0 ? `${acc},${s}` : s) @@ -268,7 +268,7 @@ describe.concurrent("HashMap", () => { }) it("reduceWithIndex", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("b")]) const result = hashMap.reduceWithIndex( "", @@ -279,7 +279,7 @@ describe.concurrent("HashMap", () => { }) it("remove", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("b")]) const result = hashMap.remove(key(0)) @@ -288,12 +288,12 @@ describe.concurrent("HashMap", () => { }) it("remove non existing key doesn't change the array", () => { - const map = HashMap(Tuple(13, 95), Tuple(90, 4)) + const map = HashMap([13, 95], [90, 4]) assert.deepEqual(map.remove(75).keySet.toArray, map.keySet.toArray) }) it("removeMany", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("b")]) assert.isFalse(hashMap.isEmpty) @@ -303,7 +303,7 @@ describe.concurrent("HashMap", () => { }) it("size", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("b")]) const result = hashMap.size @@ -311,8 +311,8 @@ describe.concurrent("HashMap", () => { }) it("union", () => { - const map1 = HashMap(Tuple(0, "a"), Tuple(1, "b")) - const map2 = HashMap(Tuple("foo", true), Tuple("bar", false)) + const map1 = HashMap([0, "a"], [1, "b"]) + const map2 = HashMap(["foo", true], ["bar", false]) const result = map1 + map2 @@ -323,7 +323,7 @@ describe.concurrent("HashMap", () => { }) it("update", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("b")]) const result = hashMap.update(key(0), ({ s }) => value(`${s}-${s}`)) @@ -333,7 +333,7 @@ describe.concurrent("HashMap", () => { }) it("values", () => { - const hashMap = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) + const hashMap = HashMap([key(0), value("a")], [key(1), value("b")]) const result = hashMap.values @@ -341,16 +341,16 @@ describe.concurrent("HashMap", () => { }) it("equals", () => { - const a = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) - const b = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) + const a = HashMap([key(0), value("a")], [key(1), value("b")]) + const b = HashMap([key(0), value("a")], [key(1), value("b")]) assert.isTrue(a == b) }) it("getAssociative", () => { - const a = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) - const b = HashMap(Tuple(key(0), value("a")), Tuple(key(1), value("b"))) - const expected = HashMap(Tuple(key(0), value("aa")), Tuple(key(1), value("bb"))) + const a = HashMap([key(0), value("a")], [key(1), value("b")]) + const b = HashMap([key(0), value("a")], [key(1), value("b")]) + const expected = HashMap([key(0), value("aa")], [key(1), value("bb")]) const A = HashMap.getAssociative( Associative((x: Value, y: Value) => value(Associative.string.combine(x.s, y.s))) ) diff --git a/packages/stdlib/_test/HashSet.test.ts b/packages/stdlib/_test/HashSet.test.ts index c6404bec..ee6e5c61 100644 --- a/packages/stdlib/_test/HashSet.test.ts +++ b/packages/stdlib/_test/HashSet.test.ts @@ -141,8 +141,8 @@ describe.concurrent("HashSet", () => { const result = hashSet.partition(({ n }) => n > 2) - assert.isTrue(result.get(0) == HashSet(value(0), value(1), value(2))) - assert.isTrue(result.get(1) == HashSet(value(3), value(4), value(5))) + assert.isTrue(result[0] == HashSet(value(0), value(1), value(2))) + assert.isTrue(result[1] == HashSet(value(3), value(4), value(5))) }) it("remove", () => { diff --git a/packages/stdlib/_test/ImmutableArray.test.ts b/packages/stdlib/_test/ImmutableArray.test.ts index 979d726b..a10c3605 100644 --- a/packages/stdlib/_test/ImmutableArray.test.ts +++ b/packages/stdlib/_test/ImmutableArray.test.ts @@ -281,46 +281,46 @@ describe.concurrent("ImmutableArray", () => { it("partition", () => { assert.isTrue( ImmutableArray.empty().partition((n) => n > 2) == - Tuple(ImmutableArray.empty(), ImmutableArray.empty()) + [ImmutableArray.empty(), ImmutableArray.empty()] ) assert.isTrue( - ImmutableArray(1, 3).partition((n) => n > 2) == Tuple(ImmutableArray(1), ImmutableArray(3)) + ImmutableArray(1, 3).partition((n) => n > 2) == [ImmutableArray(1), ImmutableArray(3)] ) }) it("partitionMap", () => { assert.isTrue( ImmutableArray.empty>().partitionMap(identity) == - Tuple(ImmutableArray.empty(), ImmutableArray.empty()) + [ImmutableArray.empty(), ImmutableArray.empty()] ) assert.isTrue( ImmutableArray(Either.right(1), Either.left("foo"), Either.right(2)).partitionMap(identity) == - Tuple(ImmutableArray("foo"), ImmutableArray(1, 2)) + [ImmutableArray("foo"), ImmutableArray(1, 2)] ) }) it("partitionMapWithIndex", () => { assert.isTrue( ImmutableArray.empty>().partitionMapWithIndex((_, a) => a) == - Tuple(ImmutableArray.empty(), ImmutableArray.empty()) + [ImmutableArray.empty(), ImmutableArray.empty()] ) assert.isTrue( ImmutableArray(Either.right(1), Either.left("foo"), Either.right(2)).partitionMapWithIndex(( i, a ) => a.filterOrElse((n) => n > i, () => "error")) == - Tuple(ImmutableArray("foo", "error"), ImmutableArray(1)) + [ImmutableArray("foo", "error"), ImmutableArray(1)] ) }) it("partitionWithIndex", () => { assert.isTrue( ImmutableArray.empty().partitionWithIndex((i, n) => i + n > 2) == - Tuple(ImmutableArray.empty(), ImmutableArray.empty()) + [ImmutableArray.empty(), ImmutableArray.empty()] ) assert.isTrue( ImmutableArray(1, 2).partitionWithIndex((i, n) => i + n > 2) == - Tuple(ImmutableArray(1), ImmutableArray(2)) + [ImmutableArray(1), ImmutableArray(2)] ) }) @@ -340,11 +340,11 @@ describe.concurrent("ImmutableArray", () => { it("separate", () => { assert.isTrue( ImmutableArray.empty>().separate == - Tuple(ImmutableArray.empty(), ImmutableArray.empty()) + [ImmutableArray.empty(), ImmutableArray.empty()] ) assert.isTrue( ImmutableArray(Either.left(123), Either.right("123")).separate == - Tuple(ImmutableArray(123), ImmutableArray("123")) + [ImmutableArray(123), ImmutableArray("123")] ) }) @@ -417,10 +417,10 @@ describe.concurrent("ImmutableArray", () => { assert.isTrue( separateF(ImmutableArray.empty()) == - Maybe.some(Tuple(ImmutableArray.empty(), ImmutableArray.empty())) + Maybe.some([ImmutableArray.empty(), ImmutableArray.empty()]) ) assert.isTrue( - separateF(ImmutableArray(1, 3)) == Maybe.some(Tuple(ImmutableArray(0), ImmutableArray(4))) + separateF(ImmutableArray(1, 3)) == Maybe.some([ImmutableArray(0), ImmutableArray(4)]) ) }) @@ -432,11 +432,11 @@ describe.concurrent("ImmutableArray", () => { assert.isTrue( separateWithIndexF(ImmutableArray.empty()) == - Maybe.some(Tuple(ImmutableArray.empty(), ImmutableArray.empty())) + Maybe.some([ImmutableArray.empty(), ImmutableArray.empty()]) ) assert.isTrue( separateWithIndexF(ImmutableArray(1, 3)) == - Maybe.some(Tuple(ImmutableArray(1), ImmutableArray(4))) + Maybe.some([ImmutableArray(1), ImmutableArray(4)]) ) }) @@ -574,7 +574,7 @@ describe.concurrent("ImmutableArray", () => { ) assert.isTrue( ImmutableArray(1, 2, 3).zip(ImmutableArray("a", "b", "c")) == - ImmutableArray(Tuple(1, "a"), Tuple(2, "b"), Tuple(3, "c")) + ImmutableArray([1, "a"], [2, "b"], [3, "c"]) ) }) }) diff --git a/packages/stdlib/_test/ImmutableMap.test.ts b/packages/stdlib/_test/ImmutableMap.test.ts index 4b6b4881..67e3c504 100644 --- a/packages/stdlib/_test/ImmutableMap.test.ts +++ b/packages/stdlib/_test/ImmutableMap.test.ts @@ -1,14 +1,14 @@ describe.concurrent("ImmutableMap", () => { it("compact", () => { - const map = ImmutableMap(Tuple(1, Maybe.some("a")), Tuple(2, Maybe.none)) + const map = ImmutableMap([1, Maybe.some("a")], [2, Maybe.none]) const result = map.compact - assert.isTrue(result == ImmutableMap(Tuple(1, "a"))) + assert.isTrue(result == ImmutableMap([1, "a"])) }) it("copy", () => { - const map = ImmutableMap(Tuple(1, "a")) + const map = ImmutableMap([1, "a"]) const result = map.copy @@ -22,50 +22,50 @@ describe.concurrent("ImmutableMap", () => { }) it("filter", () => { - const map = ImmutableMap(Tuple(1, "a"), Tuple(2, "b"), Tuple(3, "c")) + const map = ImmutableMap([1, "a"], [2, "b"], [3, "c"]) const result = map.filter((char) => char === "b") - assert.isTrue(result == ImmutableMap(Tuple(2, "b"))) + assert.isTrue(result == ImmutableMap([2, "b"])) }) it("filterWithIndex", () => { - const map = ImmutableMap(Tuple(1, "a"), Tuple(2, "b"), Tuple(3, "c")) + const map = ImmutableMap([1, "a"], [2, "b"], [3, "c"]) const result = map.filterWithIndex((key, char) => key < 2 || char === "b") - assert.isTrue(result == ImmutableMap(Tuple(1, "a"), Tuple(2, "b"))) + assert.isTrue(result == ImmutableMap([1, "a"], [2, "b"])) }) it("filterMap", () => { - const map = ImmutableMap(Tuple(1, "a"), Tuple(2, "b"), Tuple(3, "c")) + const map = ImmutableMap([1, "a"], [2, "b"], [3, "c"]) const result = map.filterMap((char) => char === "b" ? Maybe.some(char.toUpperCase()) : Maybe.none ) - assert.isTrue(result == ImmutableMap(Tuple(2, "B"))) + assert.isTrue(result == ImmutableMap([2, "B"])) }) it("filterMapWithIndex", () => { - const map = ImmutableMap(Tuple(1, "a"), Tuple(2, "b"), Tuple(3, "c")) + const map = ImmutableMap([1, "a"], [2, "b"], [3, "c"]) const result = map.filterMapWithIndex((key, char) => key < 2 || char === "b" ? Maybe.some(char.toUpperCase()) : Maybe.none ) - assert.isTrue(result == ImmutableMap(Tuple(1, "A"), Tuple(2, "B"))) + assert.isTrue(result == ImmutableMap([1, "A"], [2, "B"])) }) it("get", () => { - const map = ImmutableMap(Tuple(1, "a"), Tuple(2, "b"), Tuple(3, "c")) + const map = ImmutableMap([1, "a"], [2, "b"], [3, "c"]) assert.isTrue(map.get(1) == Maybe.some("a")) assert.isTrue(map.get(4) == Maybe.none) }) it("has", () => { - const map = ImmutableMap(Tuple(1, "a"), Tuple(2, "b"), Tuple(3, "c")) + const map = ImmutableMap([1, "a"], [2, "b"], [3, "c"]) assert.isTrue(map.has(1)) assert.isFalse(map.has(4)) @@ -73,37 +73,37 @@ describe.concurrent("ImmutableMap", () => { it("isEmpty", () => { assert.isTrue(ImmutableMap.empty().isEmpty) - assert.isFalse(ImmutableMap(Tuple(1, "a")).isEmpty) + assert.isFalse(ImmutableMap([1, "a"]).isEmpty) }) it("map", () => { - const map = ImmutableMap(Tuple(1, "a"), Tuple(2, "b"), Tuple(3, "c")) + const map = ImmutableMap([1, "a"], [2, "b"], [3, "c"]) const result = map.map((v) => v.toUpperCase()) - assert.isTrue(result == ImmutableMap(Tuple(1, "A"), Tuple(2, "B"), Tuple(3, "C"))) + assert.isTrue(result == ImmutableMap([1, "A"], [2, "B"], [3, "C"])) }) it("mapWithIndex", () => { - const map = ImmutableMap(Tuple(1, "a"), Tuple(2, "b"), Tuple(3, "c")) + const map = ImmutableMap([1, "a"], [2, "b"], [3, "c"]) const result = map.mapWithIndex((k, v) => k + v.toUpperCase()) - assert.isTrue(result == ImmutableMap(Tuple(1, "1A"), Tuple(2, "2B"), Tuple(3, "3C"))) + assert.isTrue(result == ImmutableMap([1, "1A"], [2, "2B"], [3, "3C"])) }) it("remove", () => { - const map = ImmutableMap(Tuple(1, "a"), Tuple(2, "b"), Tuple(3, "c")) + const map = ImmutableMap([1, "a"], [2, "b"], [3, "c"]) const result1 = map.remove(1) const result2 = result1.remove(1) - assert.isTrue(result1 == ImmutableMap(Tuple(2, "b"), Tuple(3, "c"))) - assert.isTrue(result2 == ImmutableMap(Tuple(2, "b"), Tuple(3, "c"))) + assert.isTrue(result1 == ImmutableMap([2, "b"], [3, "c"])) + assert.isTrue(result2 == ImmutableMap([2, "b"], [3, "c"])) }) it("removeMany", () => { - const map = ImmutableMap(Tuple(1, "a"), Tuple(2, "b"), Tuple(3, "c")) + const map = ImmutableMap([1, "a"], [2, "b"], [3, "c"]) const result = map.removeMany([1, 2, 3]) @@ -115,16 +115,16 @@ describe.concurrent("ImmutableMap", () => { const result = map.set(1, "a") - assert.isTrue(result == ImmutableMap(Tuple(1, "a"))) + assert.isTrue(result == ImmutableMap([1, "a"])) }) it("size", () => { assert.strictEqual(ImmutableMap.empty().size, 0) - assert.strictEqual(ImmutableMap(Tuple(1, "a")).size, 1) + assert.strictEqual(ImmutableMap([1, "a"]).size, 1) }) it("update", () => { - const map = ImmutableMap(Tuple(1, "a"), Tuple(2, "b"), Tuple(3, "c")) + const map = ImmutableMap([1, "a"], [2, "b"], [3, "c"]) const result1 = map.update( 1, @@ -135,9 +135,9 @@ describe.concurrent("ImmutableMap", () => { Maybe.$.fold(Maybe.some("-"), (char) => Maybe.some(char.toUpperCase())) ) - assert.isTrue(result1 == ImmutableMap(Tuple(2, "b"), Tuple(3, "c"))) + assert.isTrue(result1 == ImmutableMap([2, "b"], [3, "c"])) assert.isTrue( - result2 == ImmutableMap(Tuple(1, "a"), Tuple(2, "b"), Tuple(3, "c"), Tuple(4, "-")) + result2 == ImmutableMap([1, "a"], [2, "b"], [3, "c"], [4, "-"]) ) }) }) diff --git a/packages/stdlib/_test/ImmutableQueue.test.ts b/packages/stdlib/_test/ImmutableQueue.test.ts index 74ba54a9..916829a3 100644 --- a/packages/stdlib/_test/ImmutableQueue.test.ts +++ b/packages/stdlib/_test/ImmutableQueue.test.ts @@ -19,11 +19,11 @@ describe.concurrent("ImmutableQueue", () => { const queue = ImmutableQueue(1, 2) const result1 = queue.dequeue - const result2 = result1.value!.get(1).dequeue - const result3 = result2.value!.get(1).dequeue + const result2 = result1.value![1].dequeue + const result3 = result2.value![1].dequeue - assert.isTrue(result1 == Maybe.some(Tuple(1, ImmutableQueue(2)))) - assert.isTrue(result2 == Maybe.some(Tuple(2, ImmutableQueue.empty()))) + assert.isTrue(result1 == Maybe.some([1, ImmutableQueue(2)])) + assert.isTrue(result2 == Maybe.some([2, ImmutableQueue.empty()])) assert.isTrue(result3 == Maybe.none) }) @@ -49,9 +49,7 @@ describe.concurrent("ImmutableQueue", () => { it("splitAt", () => { const queue = ImmutableQueue(0, 1, 2, 3, 4, 5) - const { - tuple: [left, right] - } = queue.splitAt(3) + const [left, right] = queue.splitAt(3) assert.isTrue(left == ImmutableQueue(0, 1, 2)) assert.isTrue(right == ImmutableQueue(3, 4, 5)) @@ -60,9 +58,7 @@ describe.concurrent("ImmutableQueue", () => { it("splitAt - empty leftover", () => { const queue = ImmutableQueue(0, 1, 2, 3, 4, 5) - const { - tuple: [left, right] - } = queue.splitAt(6) + const [left, right] = queue.splitAt(6) assert.isTrue(left == ImmutableQueue(0, 1, 2, 3, 4, 5)) assert.isTrue(right == ImmutableQueue()) diff --git a/packages/stdlib/_test/List.test.ts b/packages/stdlib/_test/List.test.ts index 3fe70c7c..676089ac 100644 --- a/packages/stdlib/_test/List.test.ts +++ b/packages/stdlib/_test/List.test.ts @@ -30,9 +30,7 @@ describe.concurrent("List", () => { it("splitAt", () => { const list = List(0, 1, 2, 3, 4, 5) - const { - tuple: [left, right] - } = list.splitAt(3) + const [left, right] = list.splitAt(3) assert.isTrue(left == List(0, 1, 2)) assert.isTrue(right == List(3, 4, 5)) @@ -68,19 +66,19 @@ describe.concurrent("List", () => { it("partition", () => { assert.isTrue( List.empty().partition((n) => n > 2) == - Tuple(List.empty(), List.empty()) + [List.empty(), List.empty()] ) - assert.isTrue(List(1, 3).partition((n) => n > 2) == Tuple(List(1), List(3))) + assert.isTrue(List(1, 3).partition((n) => n > 2) == [List(1), List(3)]) }) it("partitionMap", () => { assert.isTrue( List.empty>().partitionMap(identity) == - Tuple(List.empty(), List.empty()) + [List.empty(), List.empty()] ) assert.isTrue( List(Either.right(1), Either.left("foo"), Either.right(2)).partitionMap(identity) == - Tuple(List("foo"), List(1, 2)) + [List("foo"), List(1, 2)] ) }) }) diff --git a/packages/stdlib/_test/Maybe.test.ts b/packages/stdlib/_test/Maybe.test.ts index 4374ce40..88675ab4 100644 --- a/packages/stdlib/_test/Maybe.test.ts +++ b/packages/stdlib/_test/Maybe.test.ts @@ -215,24 +215,24 @@ describe.concurrent("Maybe", () => { it("partition", () => { const p = (n: number) => n > 2 - assert.isTrue(Maybe.none.partition(p) == Tuple(Maybe.none, Maybe.none)) - assert.isTrue(Maybe.some(1).partition(p) == Tuple(Maybe.some(1), Maybe.none)) - assert.isTrue(Maybe.some(3).partition(p) == Tuple(Maybe.none, Maybe.some(3))) + assert.isTrue(Maybe.none.partition(p) == [Maybe.none, Maybe.none]) + assert.isTrue(Maybe.some(1).partition(p) == [Maybe.some(1), Maybe.none]) + assert.isTrue(Maybe.some(3).partition(p) == [Maybe.none, Maybe.some(3)]) }) it("partitionMap", () => { const p = (n: number) => n > 2 const f = (n: number) => (p(n) ? Either.right(n + 1) : Either.left(n - 1)) - assert.isTrue(Maybe.none.partitionMap(f) == Tuple(Maybe.none, Maybe.none)) - assert.isTrue(Maybe.some(1).partitionMap(f) == Tuple(Maybe.some(0), Maybe.none)) - assert.isTrue(Maybe.some(3).partitionMap(f) == Tuple(Maybe.none, Maybe.some(4))) + assert.isTrue(Maybe.none.partitionMap(f) == [Maybe.none, Maybe.none]) + assert.isTrue(Maybe.some(1).partitionMap(f) == [Maybe.some(0), Maybe.none]) + assert.isTrue(Maybe.some(3).partitionMap(f) == [Maybe.none, Maybe.some(4)]) }) it("separate", () => { - assert.isTrue(Maybe.none.separate == Tuple(Maybe.none, Maybe.none)) - assert.isTrue(Maybe.some(Either.left("123")).separate == Tuple(Maybe.some("123"), Maybe.none)) - assert.isTrue(Maybe.some(Either.right("123")).separate == Tuple(Maybe.none, Maybe.some("123"))) + assert.isTrue(Maybe.none.separate == [Maybe.none, Maybe.none]) + assert.isTrue(Maybe.some(Either.left("123")).separate == [Maybe.some("123"), Maybe.none]) + assert.isTrue(Maybe.some(Either.right("123")).separate == [Maybe.none, Maybe.some("123")]) }) it("sequence", () => { @@ -265,7 +265,7 @@ describe.concurrent("Maybe", () => { }) it("zip", () => { - assert.isTrue((Maybe.some(1) + Maybe.some(2)) == Maybe.some(Tuple(1, 2))) + assert.isTrue((Maybe.some(1) + Maybe.some(2)) == Maybe.some([1, 2])) }) it("separateF", () => { @@ -274,9 +274,9 @@ describe.concurrent("Maybe", () => { Either.right(p(n) ? Either.right(n + 1) : Either.left(n - 1)) ) - assert.isTrue(separateF(Maybe.none) == Either.right(Tuple(Maybe.none, Maybe.none))) - assert.isTrue(separateF(Maybe.some(1)) == Either.right(Tuple(Maybe.some(0), Maybe.none))) - assert.isTrue(separateF(Maybe.some(3)) == Either.right(Tuple(Maybe.none, Maybe.some(4)))) + assert.isTrue(separateF(Maybe.none) == Either.right([Maybe.none, Maybe.none])) + assert.isTrue(separateF(Maybe.some(1)) == Either.right([Maybe.some(0), Maybe.none])) + assert.isTrue(separateF(Maybe.some(3)) == Either.right([Maybe.none, Maybe.some(4)])) }) it("struct", () => { diff --git a/packages/stdlib/_test/MutableHashMap.test.ts b/packages/stdlib/_test/MutableHashMap.test.ts index c9b11f80..373ab32f 100644 --- a/packages/stdlib/_test/MutableHashMap.test.ts +++ b/packages/stdlib/_test/MutableHashMap.test.ts @@ -32,7 +32,7 @@ function value(c: number, d: number): Value { describe.concurrent("MutableHashMap", () => { it("from", () => { - const map = MutableHashMap(Tuple(key(0, 0), value(0, 0)), Tuple(key(1, 1), value(1, 1))) + const map = MutableHashMap([key(0, 0), value(0, 0)], [key(1, 1), value(1, 1)]) assert.strictEqual(map.size, 2) assert.isTrue(map.has(key(0, 0))) @@ -102,8 +102,8 @@ describe.concurrent("MutableHashMap", () => { assert.isTrue( map.toImmutableArray == ImmutableArray( - Tuple(key(0, 0), value(4, 4)), - Tuple(key(1, 1), value(3, 3)) + [key(0, 0), value(4, 4)], + [key(1, 1), value(3, 3)] ) ) }) diff --git a/packages/stdlib/_test/ParSeq.test.ts b/packages/stdlib/_test/ParSeq.test.ts index 67e7ea7d..93f4735d 100644 --- a/packages/stdlib/_test/ParSeq.test.ts +++ b/packages/stdlib/_test/ParSeq.test.ts @@ -35,10 +35,10 @@ describe.concurrent("ParSeq", () => { }) it("zip", () => { - assert.isTrue(ParSeq.single("a").zip(ParSeq.single(0)) == ParSeq.single(Tuple("a", 0))) + assert.isTrue(ParSeq.single("a").zip(ParSeq.single(0)) == ParSeq.single(["a", 0])) assert.isTrue( ParSeq.combinePar(ParSeq.single("a"), ParSeq.single("b")).zip(ParSeq.single("c")) == - ParSeq.combinePar(ParSeq.single(Tuple("b", "c")), ParSeq.single(Tuple("a", "c"))) + ParSeq.combinePar(ParSeq.single(["b", "c"]), ParSeq.single(["a", "c"])) ) }) diff --git a/packages/stdlib/_test/Recursive.test.ts b/packages/stdlib/_test/Recursive.test.ts index 9ec5c22c..840c756f 100644 --- a/packages/stdlib/_test/Recursive.test.ts +++ b/packages/stdlib/_test/Recursive.test.ts @@ -42,18 +42,18 @@ describe.concurrent("Recursive", () => { }) it("fib", () => { - type T = Tuple<[number, number]> + type T = readonly [number, number] type NatT = Nat const fibAlgebra = (r: NatT): T => r.fold( - () => Tuple(0, 1), - ({ tuple: [n1, n2] }) => Tuple(n1 + n2, n1) + () => [0, 1], + ([n1, n2]) => [n1 + n2, n1] ) const fib = Recursive.$.fold(Covariant, fibAlgebra) - assert.equal(fib(zero).get(0), 0) - assert.equal(fib(one).get(0), 1) - assert.equal(fib(five).get(0), 5) - assert.equal(five.fold(Covariant, fibAlgebra).get(0), 5) + assert.equal(fib(zero)[0], 0) + assert.equal(fib(one)[0], 1) + assert.equal(fib(five)[0], 5) + assert.equal(five.fold(Covariant, fibAlgebra)[0], 5) }) it("depth first", () => { @@ -163,16 +163,16 @@ describe.concurrent("Recursive", () => { }) it("fib", () => { - type FibDownR = Recursive.FoldDownFn> - const fibAlgebra: FibDownR = ({ tuple: [n1, n2] }, r) => + type FibDownR = Recursive.FoldDownFn + const fibAlgebra: FibDownR = ([n1, n2], r) => r.caseValue.fold( - () => Tuple(n1, n2), - (_) => Tuple(n1 + n2, n1) + () => [n1, n2], + (_) => [n1 + n2, n1] ) - const fib = Recursive.$.foldDown(Maybe.Foldable, Tuple(0, 1), fibAlgebra) - assert.equal(fib(zero).get(0), 0) - assert.equal(fib(one).get(0), 1) - assert.equal(fib(five).get(0), 5) + const fib = Recursive.$.foldDown(Maybe.Foldable, [0, 1], fibAlgebra) + assert.equal(fib(zero)[0], 0) + assert.equal(fib(one)[0], 1) + assert.equal(fib(five)[0], 5) }) }) diff --git a/packages/stdlib/_test/RedBlackTree.test.ts b/packages/stdlib/_test/RedBlackTree.test.ts index 98186e1a..1f7e254e 100644 --- a/packages/stdlib/_test/RedBlackTree.test.ts +++ b/packages/stdlib/_test/RedBlackTree.test.ts @@ -31,11 +31,11 @@ describe.concurrent("RedBlackTree", () => { assert.strictEqual(tree.size, 5) assert.deepEqual(Array.from(tree), [ - Tuple(-2, "d"), - Tuple(-1, "c"), - Tuple(0, "b"), - Tuple(1, "a"), - Tuple(3, "e") + [-2, "d"], + [-1, "c"], + [0, "b"], + [1, "a"], + [3, "e"] ]) }) @@ -56,11 +56,11 @@ describe.concurrent("RedBlackTree", () => { assert.strictEqual(tree.size, 5) assert.deepEqual(Array.from(tree.backwards), [ - Tuple(3, "e"), - Tuple(1, "a"), - Tuple(0, "b"), - Tuple(-1, "c"), - Tuple(-2, "d") + [3, "e"], + [1, "a"], + [0, "b"], + [-1, "c"], + [-2, "d"] ]) }) @@ -103,9 +103,9 @@ describe.concurrent("RedBlackTree", () => { .insert(-2, "d") .insert(3, "e") - assert.isTrue(tree.first == Maybe.some(Tuple(-2, "d"))) - assert.isTrue(tree.last == Maybe.some(Tuple(3, "e"))) - assert.isTrue(tree.getAt(1) == Maybe.some(Tuple(-1, "c"))) + assert.isTrue(tree.first == Maybe.some([-2, "d"])) + assert.isTrue(tree.last == Maybe.some([3, "e"])) + assert.isTrue(tree.getAt(1) == Maybe.some([-1, "c"])) }) it("forEachGe", () => { @@ -164,11 +164,11 @@ describe.concurrent("RedBlackTree", () => { .insert(-2, "d") .insert(3, "e") - assert.deepEqual(Array.from(tree.ge(0)), [Tuple(0, "b"), Tuple(1, "a"), Tuple(3, "e")]) + assert.deepEqual(Array.from(tree.ge(0)), [[0, "b"], [1, "a"], [3, "e"]]) assert.deepEqual(Array.from(tree.ge(0, "Backward")), [ - Tuple(0, "b"), - Tuple(-1, "c"), - Tuple(-2, "d") + [0, "b"], + [-1, "c"], + [-2, "d"] ]) }) diff --git a/packages/stdlib/_test/SortedMap.test.ts b/packages/stdlib/_test/SortedMap.test.ts index 69ae4c2a..578b58ce 100644 --- a/packages/stdlib/_test/SortedMap.test.ts +++ b/packages/stdlib/_test/SortedMap.test.ts @@ -30,50 +30,50 @@ function value(n: number): Value { return new Value(n) } -function makeSortedMap(...numbers: Array>): SortedMap { - const entries = numbers.map(({ tuple: [k, v] }) => Tuple(key(k), value(v))) +function makeSortedMap(...numbers: Array): SortedMap { + const entries = numbers.map(([k, v]) => [key(k), value(v)] as const) return SortedMap.from(Ord.number.contramap((key: Key) => key.id))(entries) } describe.concurrent("SortedMap", () => { it("entries", () => { - const map = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map = makeSortedMap([0, 10], [1, 20], [2, 30]) const result = ImmutableArray.from(map) assert.isTrue( result == ImmutableArray( - Tuple(key(0), value(10)), - Tuple(key(1), value(20)), - Tuple(key(2), value(30)) + [key(0), value(10)], + [key(1), value(20)], + [key(2), value(30)] ) ) }) it("get", () => { - const map = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map = makeSortedMap([0, 10], [1, 20], [2, 30]) assert.isTrue(map.get(key(0)) == Maybe.some(value(10))) assert.isTrue(map.get(key(4)) == Maybe.none) }) it("has", () => { - const map = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map = makeSortedMap([0, 10], [1, 20], [2, 30]) assert.isTrue(map.has(key(0))) assert.isFalse(map.has(key(4))) }) it("headOption", () => { - const map1 = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map1 = makeSortedMap([0, 10], [1, 20], [2, 30]) const map2 = SortedMap.empty(Ord.number) - assert.isTrue(map1.headMaybe == Maybe.some(Tuple(key(0), value(10)))) + assert.isTrue(map1.headMaybe == Maybe.some([key(0), value(10)])) assert.isTrue(map2.headMaybe == Maybe.none) }) it("isEmpty", () => { - const map1 = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map1 = makeSortedMap([0, 10], [1, 20], [2, 30]) const map2 = SortedMap.empty(Ord.number) assert.isFalse(map1.isEmpty) @@ -81,7 +81,7 @@ describe.concurrent("SortedMap", () => { }) it("isNonEmpty", () => { - const map1 = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map1 = makeSortedMap([0, 10], [1, 20], [2, 30]) const map2 = SortedMap.empty(Ord.number) assert.isTrue(map1.isNonEmpty) @@ -89,7 +89,7 @@ describe.concurrent("SortedMap", () => { }) it("keys", () => { - const map = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map = makeSortedMap([0, 10], [1, 20], [2, 30]) const result = ImmutableArray.from(map.keys) @@ -97,35 +97,35 @@ describe.concurrent("SortedMap", () => { }) it("map", () => { - const map = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map = makeSortedMap([0, 10], [1, 20], [2, 30]) const result = ImmutableArray.from(map.map((value) => value.id)) assert.isTrue( result == ImmutableArray( - Tuple(key(0), 10), - Tuple(key(1), 20), - Tuple(key(2), 30) + [key(0), 10], + [key(1), 20], + [key(2), 30] ) ) }) it("mapWithIndex", () => { - const map = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map = makeSortedMap([0, 10], [1, 20], [2, 30]) const result = ImmutableArray.from(map.mapWithIndex((key, value) => key.id + value.id)) assert.isTrue( result == ImmutableArray( - Tuple(key(0), 10), - Tuple(key(1), 21), - Tuple(key(2), 32) + [key(0), 10], + [key(1), 21], + [key(2), 32] ) ) }) it("reduce", () => { - const map = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map = makeSortedMap([0, 10], [1, 20], [2, 30]) const result = map.reduce("", (acc, value) => acc + value.id) @@ -133,7 +133,7 @@ describe.concurrent("SortedMap", () => { }) it("reduceWithIndex", () => { - const map = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map = makeSortedMap([0, 10], [1, 20], [2, 30]) const result = map.reduceWithIndex("", (acc, key, value) => acc + key.id + value.id) @@ -141,7 +141,7 @@ describe.concurrent("SortedMap", () => { }) it("remove", () => { - const map = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map = makeSortedMap([0, 10], [1, 20], [2, 30]) assert.isTrue(map.has(key(0))) @@ -151,7 +151,7 @@ describe.concurrent("SortedMap", () => { }) it("set", () => { - const map = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map = makeSortedMap([0, 10], [1, 20], [2, 30]) assert.isFalse(map.has(key(4))) @@ -161,13 +161,13 @@ describe.concurrent("SortedMap", () => { }) it("size", () => { - const map = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map = makeSortedMap([0, 10], [1, 20], [2, 30]) assert.strictEqual(map.size, 3) }) it("values", () => { - const map = makeSortedMap(Tuple(0, 10), Tuple(1, 20), Tuple(2, 30)) + const map = makeSortedMap([0, 10], [1, 20], [2, 30]) const result = ImmutableArray.from(map.values) diff --git a/packages/stdlib/_test/SortedSet.test.ts b/packages/stdlib/_test/SortedSet.test.ts index dc1f53db..501f10d6 100644 --- a/packages/stdlib/_test/SortedSet.test.ts +++ b/packages/stdlib/_test/SortedSet.test.ts @@ -215,13 +215,13 @@ describe.concurrent("SortedSet", () => { const result = set.partition((member) => member.id.endsWith("1") || member.id.endsWith("3")) assert.isTrue( - result.get(0).toImmutableArray == ImmutableArray( + result[0].toImmutableArray == ImmutableArray( new Member("worker_000000"), new Member("worker_000002") ) ) assert.isTrue( - result.get(1).toImmutableArray == ImmutableArray( + result[1].toImmutableArray == ImmutableArray( new Member("worker_000001"), new Member("worker_000003") ) diff --git a/packages/stdlib/_test/Tree.test.ts b/packages/stdlib/_test/Tree.test.ts index 887e7ae3..49a4ce7a 100644 --- a/packages/stdlib/_test/Tree.test.ts +++ b/packages/stdlib/_test/Tree.test.ts @@ -77,7 +77,7 @@ describe.concurrent("Tree", () => { }) it("unfold", () => { - const y = Tree.unfold(2, (a) => Tuple(a, a > 1 ? Chunk.range(0, a - 1) : Chunk.empty())) + const y = Tree.unfold(2, (a) => [a, a > 1 ? Chunk.range(0, a - 1) : Chunk.empty()]) const x = Tree(2, Chunk(Tree(0)) + Chunk(Tree(1))) assert.isTrue(x == y) }) @@ -158,8 +158,8 @@ describe.concurrent("Tree", () => { const a = Tree("a", Chunk(Tree("b"), Tree("c"))) const b = Tree("a", Chunk(Tree("b"), Tree("c"), Tree("d"))) const expected = Tree( - Tuple("a", "a"), - Chunk(Tree(Tuple("b", "b")), Tree(Tuple("c", "c"))) + ["a", "a"], + Chunk(Tree(["b", "b"]), Tree(["c", "c"])) ) assert.isTrue(a.zip(b) == b.zip(a)) assert.isTrue(a.zip(b) == expected) @@ -169,11 +169,11 @@ describe.concurrent("Tree", () => { const a = Tree("a", Chunk(Tree("b"), Tree("c"))) const b = Tree("a", Chunk(Tree("b"), Tree("c"), Tree("d"))) const expected = Tree( - Tuple("a", "a"), - Chunk(Tree(Tuple("b", "b")), Tree(Tuple("c", "c"))) + ["a", "a"], + Chunk(Tree(["b", "b"]), Tree(["c", "c"])) ) - assert.isTrue(a.zipWith(b, Tuple.make) == expected) - assert.isTrue(pipe(a, Tree.$.zipWith(b, Tuple.make)) == expected) + assert.isTrue(a.zipWith(b, (a, b) => [a, b]) == expected) + assert.isTrue(pipe(a, Tree.$.zipWith(b, (a, b) => [a, b])) == expected) }) it("isTree", () => {