Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/light-turkeys-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tsplus/stdlib": patch
---

Kill Tuple
6 changes: 6 additions & 0 deletions .changeset/short-berries-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@tsplus/stdlib": patch
"@tsplus/runtime": patch
---

Cleanup Array and fix mutable comparison
4 changes: 2 additions & 2 deletions packages/stdlib/_examples/associative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion packages/stdlib/_examples/main.ts
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
14 changes: 7 additions & 7 deletions packages/stdlib/_examples/recursive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ListF, Carrier> {
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])
}
}
}
Expand All @@ -54,7 +54,7 @@ function editDistanceAnnotatedAlgebra(len: number): Annotated.Fn<ListF, number>
"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
Expand All @@ -72,7 +72,7 @@ function editDistanceAnnotatedAlgebra(len: number): Annotated.Fn<ListF, number>
}
// Type definitions
type MyNonEmptyList<A> = Leaf<A> | Node<A>
type Carrier = Tuple<[string, string]>
type Carrier = readonly [string, string]
interface ListF extends HKT {
readonly type: MyNonEmptyList<this["A"]>
}
Expand Down
1 change: 0 additions & 1 deletion packages/stdlib/_src/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 8 additions & 8 deletions packages/stdlib/_src/collections/Chunk/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export abstract class ChunkInternal<A> implements Chunk<A>, Equals {
if (this.arrayLikeCache) {
return this.arrayLikeCache as IterableArrayLike<A>
}
const arr = this.binary ? alloc(this.length) : Array.alloc<any>(this.length)
const arr = this.binary ? alloc(this.length) : new Array<any>(this.length)

this._copyToArray(0, arr)
this.arrayLikeCache = arr
Expand All @@ -98,7 +98,7 @@ export abstract class ChunkInternal<A> implements Chunk<A>, Equals {
if (this.arrayCache) {
return this.arrayCache as readonly A[]
}
const arr = Array.alloc<A>(this.length)
const arr = new Array<A>(this.length)
this._copyToArray(0, arr)
this.arrayCache = arr
return arr
Expand Down Expand Up @@ -178,14 +178,14 @@ export abstract class ChunkInternal<A> implements Chunk<A>, Equals {

_append<A1>(a1: A1): ChunkInternal<A | A1> {
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: A1): ChunkInternal<A | A1> {
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)
}
Expand Down Expand Up @@ -409,7 +409,7 @@ export class AppendN<A> extends ChunkInternal<A> {
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]
}
Expand All @@ -431,7 +431,7 @@ export class AppendN<A> extends ChunkInternal<A> {
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(
Expand Down Expand Up @@ -901,7 +901,7 @@ export class PrependN<A> extends ChunkInternal<A> {
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]
}
Expand All @@ -917,7 +917,7 @@ export class PrependN<A> extends ChunkInternal<A> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const forEachWithIndexF = ForEachWithIndex.implementForEachWithIndexF<num
let base = succeed<Chunk<typeof _.B>, 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>, typeof _.B]>) => bs.append(b)
([bs, b]: readonly [Chunk<typeof _.B>, typeof _.B]) => bs.append(b)
)(G.both(f(i, fa.unsafeGet(i)!))(base))
}
return base
Expand Down
10 changes: 5 additions & 5 deletions packages/stdlib/_src/collections/Chunk/operations/mapAccum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition"
* @tsplus static Chunk.Aspects mapAccum
* @tsplus pipeable Chunk mapAccum
*/
export function mapAccum<A, B, S>(s: S, f: (s: S, a: A) => Tuple<[S, B]>) {
return (self: Chunk<A>): Tuple<[S, Chunk<B>]> => {
export function mapAccum<A, B, S>(s: S, f: (s: S, a: A) => readonly [S, B]) {
return (self: Chunk<A>): readonly [S, Chunk<B>] => {
const iterator = concreteChunkId(self)._arrayLikeIterator()
let next
let s1 = s
Expand All @@ -20,12 +20,12 @@ export function mapAccum<A, B, S>(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]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
* @tsplus pipeable Chunk partition
*/
export function partition<A>(f: Predicate<A>) {
return (self: Chunk<A>): Tuple<[Chunk<A>, Chunk<A>]> => self.partitionWithIndex((_, a: A) => f(a))
return (self: Chunk<A>): readonly [Chunk<A>, Chunk<A>] =>
self.partitionWithIndex((_, a: A) => f(a))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
* @tsplus pipeable Chunk partitionMap
*/
export function partitionMap<A, B, C>(f: (a: A) => Either<B, C>) {
return (self: Chunk<A>): Tuple<[Chunk<B>, Chunk<C>]> => self.partitionMapWithIndex((_, a) => f(a))
return (self: Chunk<A>): readonly [Chunk<B>, Chunk<C>] =>
self.partitionMapWithIndex((_, a) => f(a))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @tsplus pipeable Chunk partitionMapWithIndex
*/
export function partitionMapWithIndex<A, B, C>(f: (i: number, a: A) => Either<B, C>) {
return (self: Chunk<A>): Tuple<[Chunk<B>, Chunk<C>]> => {
return (self: Chunk<A>): readonly [Chunk<B>, Chunk<C>] => {
const left: Array<B> = []
const right: Array<C> = []
for (let i = 0; i < self.length; i++) {
Expand All @@ -17,6 +17,6 @@ export function partitionMapWithIndex<A, B, C>(f: (i: number, a: A) => Either<B,
right.push(e.right)
}
}
return Tuple(Chunk.from(left), Chunk.from(right))
return [Chunk.from(left), Chunk.from(right)]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @tsplus pipeable Chunk partitionWithIndex
*/
export function partitionWithIndex<A>(f: PredicateWithIndex<number, A>) {
return (self: Chunk<A>): Tuple<[Chunk<A>, Chunk<A>]> => {
return (self: Chunk<A>): readonly [Chunk<A>, Chunk<A>] => {
const left: Array<A> = []
const right: Array<A> = []
for (let i = 0; i < self.length; i++) {
Expand All @@ -17,6 +17,6 @@ export function partitionWithIndex<A>(f: PredicateWithIndex<number, A>) {
left.push(a)
}
}
return Tuple(Chunk.from(left), Chunk.from(right))
return [Chunk.from(left), Chunk.from(right)]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
*
* @tsplus getter Chunk separate
*/
export function separate<B, C>(self: Chunk<Either<B, C>>): Tuple<[Chunk<B>, Chunk<C>]> {
export function separate<B, C>(self: Chunk<Either<B, C>>): readonly [Chunk<B>, Chunk<C>] {
return self.partitionMap(identity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export const separateF = Wiltable.implementSeparateF<Chunk.HKT>()(
}) =>
(G: Applicative<G>) =>
(f: (a: A) => HKT.Kind<G, FR, FE, Either<B, B2>>) =>
(fa: Chunk<A>): HKT.Kind<G, FR, FE, Tuple<[Chunk<B>, Chunk<B2>]>> =>
(fa: Chunk<A>): HKT.Kind<G, FR, FE, readonly [Chunk<B>, Chunk<B2>]> =>
G.map((self: Chunk<Either<B, B2>>) => self.separate)(Chunk.forEachF(G)(f)(fa))
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export const separateWithIndexF = WiltableWithIndex.implementSeparateWithIndexF<
}) =>
(G: Applicative<G>) =>
<B2>(f: (k: number, a: A) => HKT.Kind<G, R, E, Either<B, B2>>) =>
(fa: Chunk<A>): HKT.Kind<G, R, E, Tuple<[Chunk<B>, Chunk<B2>]>> =>
(fa: Chunk<A>): HKT.Kind<G, R, E, readonly [Chunk<B>, Chunk<B2>]> =>
G.map((self: Chunk<Either<B, B2>>) => self.separate)(Chunk.forEachWithIndexF(G)(f)(fa))
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
* @tsplus pipeable Chunk splitAt
*/
export function splitAt(n: number) {
return <A>(self: Chunk<A>): Tuple<[Chunk<A>, Chunk<A>]> => Tuple(self.take(n), self.drop(n))
return <A>(self: Chunk<A>): readonly [Chunk<A>, Chunk<A>] => [self.take(n), self.drop(n)]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition"
* @tsplus pipeable Chunk splitWhere
*/
export function splitWhere<A>(f: Predicate<A>) {
return (self: Chunk<A>): Tuple<[Chunk<A>, Chunk<A>]> => {
return (self: Chunk<A>): readonly [Chunk<A>, Chunk<A>] => {
const iterator = concreteChunkId(self)._arrayLikeIterator()
let next
let cont = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @tsplus static Chunk.Ops unfold
*/
export function unfold<A, S>(s: S, f: (s: S) => Maybe<Tuple<[A, S]>>): Chunk<A> {
export function unfold<A, S>(s: S, f: (s: S) => Maybe<readonly [A, S]>): Chunk<A> {
let builder = Chunk.empty<A>()
let cont = true
let s1 = s
Expand Down
6 changes: 3 additions & 3 deletions packages/stdlib/_src/collections/Chunk/operations/unzip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*
* @tsplus getter Chunk unzip
*/
export function unzip<A, B>(as: Chunk<Tuple<[A, B]>>): Tuple<[Chunk<A>, Chunk<B>]> {
export function unzip<A, B>(as: Chunk<readonly [A, B]>): readonly [Chunk<A>, Chunk<B>] {
let fa: Chunk<A> = Chunk.empty()
let fb: Chunk<B> = 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]
}
2 changes: 1 addition & 1 deletion packages/stdlib/_src/collections/Chunk/operations/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
* @tsplus pipeable Chunk zip
*/
export function zip<B>(that: Chunk<B>) {
return <A>(self: Chunk<A>): Chunk<Tuple<[A, B]>> => self.zipWith(that, (a, b) => Tuple(a, b))
return <A>(self: Chunk<A>): Chunk<[A, B]> => self.zipWith(that, (a, b) => [a, b])
}
8 changes: 4 additions & 4 deletions packages/stdlib/_src/collections/Chunk/operations/zipAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
* @tsplus pipeable Chunk zipAll
*/
export function zipAll<B>(that: Chunk<B>) {
return <A>(self: Chunk<A>): Chunk<Tuple<[Maybe<A>, Maybe<B>]>> => {
return <A>(self: Chunk<A>): Chunk<readonly [Maybe<A>, Maybe<B>]> => {
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)]
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
*
* @tsplus getter Chunk zipWithIndex
*/
export function zipWithIndex<A>(self: Chunk<A>): Chunk<Tuple<[A, number]>> {
export function zipWithIndex<A>(self: Chunk<A>): Chunk<readonly [A, number]> {
return self.zipWithIndexOffset(0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition"
* @tsplus pipeable Chunk zipWithIndexOffset
*/
export function zipWithIndexOffset(offset: number) {
return <A>(self: Chunk<A>): Chunk<Tuple<[A, number]>> => {
return <A>(self: Chunk<A>): Chunk<[A, number]> => {
const iterator = concreteChunkId(self)._arrayLikeIterator()
let next
let i = offset
let builder = Chunk.empty<Tuple<[A, number]>>()
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++
}
Expand Down
Loading