Skip to content

Commit

Permalink
test: add Ref tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0x706b committed Nov 20, 2023
1 parent 3623b94 commit 7503434
Show file tree
Hide file tree
Showing 22 changed files with 365 additions and 193 deletions.
2 changes: 1 addition & 1 deletion packages/base/src/collection/compat/Array/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function updateAt<A>(i: number, a: A) {
return (self: ReadonlyArray<A>): ReadonlyArray<A> => {
if (i in self) {
const copy = self.slice();
copy[i] = a;
copy[i] = a;
return copy;
}
return self;
Expand Down
2 changes: 1 addition & 1 deletion packages/base/src/collection/compat/ArrayLike/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function toIterable<A>(self: ArrayLike<A>): Iterable<A> {
}
return Iterable.make<A>(() => {
let done = false;
let i = 0;
let i = 0;
return {
next() {
if (i >= self.length || done) {
Expand Down
128 changes: 64 additions & 64 deletions packages/base/src/collection/immutable/Conc/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function alignWith<A, B, C>(fb: Conc<B>, f: (_: These<A, B>) => C) {
return (self: Conc<A>): Conc<C> => {
concrete(self);
concrete(fb);
const out = builder<C>();
const out = builder<C>();
const minlen = Math.min(self.length, fb.length);
const maxlen = Math.max(self.length, fb.length);
for (let i = 0; i < minlen; i++) {
Expand Down Expand Up @@ -87,13 +87,13 @@ export function flatMap<A, B>(f: (a: A) => Conc<B>) {
concrete(ma);
const iterator = ma.arrayIterator();
let result: IteratorResult<ArrayLike<A>>;
let out = Conc.empty<B>();
let out = Conc.empty<B>();
while (!(result = iterator.next()).done) {
const arr = result.value;
const arr = result.value;
const length = arr.length;
for (let i = 0; i < length; i++) {
const a = arr[i]!;
out = out.concat(f(a));
out = out.concat(f(a));
}
}
return out;
Expand All @@ -105,11 +105,11 @@ export function flatMap<A, B>(f: (a: A) => Conc<B>) {
*/
export function chainRecDepthFirst<A, B>(a: A, f: (a: A) => Conc<Either<A, B>>): Conc<B> {
let buffer = f(a);
let out = Conc.empty<B>();
let out = Conc.empty<B>();

while (buffer.length > 0) {
const e = buffer.unsafeHead;
buffer = buffer.unsafeTail;
buffer = buffer.unsafeTail;
Either.concrete(e);
if (e._tag === EitherTag.Left) {
buffer = f(e.left).concat(buffer);
Expand All @@ -126,8 +126,8 @@ export function chainRecDepthFirst<A, B>(a: A, f: (a: A) => Conc<Either<A, B>>):
*/
export function chainRecBreadthFirst<A, B>(a: A, f: (a: A) => Conc<Either<A, B>>): Conc<B> {
const initial = f(a);
let buffer = Conc.empty<Either<A, B>>();
let out = Conc.empty<B>();
let buffer = Conc.empty<Either<A, B>>();
let out = Conc.empty<B>();

function go(e: Either<A, B>): void {
Either.concrete(e);
Expand All @@ -144,7 +144,7 @@ export function chainRecBreadthFirst<A, B>(a: A, f: (a: A) => Conc<Either<A, B>>

while (buffer.length > 0) {
const ab = buffer.unsafeHead;
buffer = buffer.unsafeTail;
buffer = buffer.unsafeTail;
go(ab);
}

Expand All @@ -156,7 +156,7 @@ export function chainRecBreadthFirst<A, B>(a: A, f: (a: A) => Conc<Either<A, B>>
*/
export function chop<A, B>(f: (as: Conc<A>) => readonly [B, Conc<A>]) {
return (self: Conc<A>): Conc<B> => {
const out = builder<B>();
const out = builder<B>();
let cs: Conc<A> = self;
while (cs.isNonEmpty) {
const [b, c] = f(cs);
Expand Down Expand Up @@ -190,7 +190,7 @@ export function collectWhile<A, B>(f: (a: A) => Maybe<B>) {
}
case ConcTag.Chunk: {
const array = as.arrayLike();
let dest = Conc.empty<B>();
let dest = Conc.empty<B>();
for (let i = 0; i < array.length; i++) {
const rhs = f(array[i]!);
if (rhs.isJust()) {
Expand Down Expand Up @@ -242,7 +242,7 @@ export function some<A>(predicate: Predicate<A>) {
return (as: Conc<A>): boolean => {
concrete(as);
const iterator = as.arrayIterator();
let exists = false;
let exists = false;
let result: IteratorResult<ArrayLike<A>>;
while (!exists && !(result = iterator.next()).done) {
const array = result.value;
Expand Down Expand Up @@ -286,7 +286,7 @@ export function drop(n: number) {
export function dropUntil<A>(p: Predicate<A>) {
return (self: Conc<A>): Conc<A> => {
let cont = true;
let i = 0;
let i = 0;
for (const elem of self) {
if (!cont) {
break;
Expand All @@ -307,7 +307,7 @@ export function dropWhile<A>(p: Predicate<A>) {
switch (self._tag) {
case ConcTag.Chunk: {
const arr = self.arrayLike();
let i = 0;
let i = 0;
while (i < arr.length && p(arr[i]!)) {
i++;
}
Expand All @@ -316,11 +316,11 @@ export function dropWhile<A>(p: Predicate<A>) {
default: {
const iterator = self.arrayIterator();
let result: IteratorResult<ArrayLike<A>>;
let cont = true;
let i = 0;
let cont = true;
let i = 0;
while (cont && !(result = iterator.next()).done) {
const array = result.value;
let j = 0;
let j = 0;
while (cont && j < array.length) {
if (p(array[j]!)) {
i++;
Expand Down Expand Up @@ -363,9 +363,9 @@ export function filterMapWithIndex<A, B>(f: (i: number, a: A) => Maybe<B>) {
return (self: Conc<A>): Conc<B> => {
concrete(self);
const iterator = self.arrayIterator();
const out = builder<B>();
const out = builder<B>();
let result: IteratorResult<ArrayLike<A>>;
let i = 0;
let i = 0;
while (!(result = iterator.next()).done) {
const array = result.value;
for (let j = 0; j < array.length; j++) {
Expand Down Expand Up @@ -393,7 +393,7 @@ export function filterWithIndex<A>(p: PredicateWithIndex<number, A>) {
return _Empty;
}
case ConcTag.Chunk: {
const arr = self.arrayLike();
const arr = self.arrayLike();
let builder = Conc.empty<A>();
for (let i = 0; i < arr.length; i++) {
const a = arr[i]!;
Expand All @@ -411,9 +411,9 @@ export function filterWithIndex<A>(p: PredicateWithIndex<number, A>) {
}
default: {
const iterator = self.arrayIterator();
let out = Conc.empty<A>();
let out = Conc.empty<A>();
let result: IteratorResult<ArrayLike<A>>;
let i = 0;
let i = 0;
while (!(result = iterator.next()).done) {
const array = result.value;
for (let j = 0; j < array.length; j++) {
Expand All @@ -437,10 +437,10 @@ export function find<A>(f: (a: A) => boolean) {
return (self: Conc<A>): Maybe<A> => {
concrete(self);
const iterator = self.arrayIterator();
let out = Nothing<A>();
let out = Nothing<A>();
let result: IteratorResult<ArrayLike<A>>;
while (out.isNothing() && !(result = iterator.next()).done) {
const array = result.value;
const array = result.value;
const length = array.length;
for (let i = 0; out.isNothing() && i < length; i++) {
const a = array[i]!;
Expand Down Expand Up @@ -470,13 +470,13 @@ export function foldLeftWhile<A, B>(b: B, p: Predicate<B>, f: (b: B, a: A) => B)
return (as: Conc<A>): B => {
concrete(as);
const iterator = as.arrayIterator();
let s = b;
let cont = p(s);
let s = b;
let cont = p(s);
let result: IteratorResult<ArrayLike<A>>;
while (cont && !(result = iterator.next()).done) {
const array = result.value;
for (let i = 0; cont && i < array.length; i++) {
s = f(s, array[i]!);
s = f(s, array[i]!);
cont = p(s);
}
}
Expand All @@ -500,9 +500,9 @@ export function foldLeftWithIndex<A, B>(b: B, f: (i: number, b: B, a: A) => B) {
return (self: Conc<A>): B => {
concrete(self);
const iterator = self.arrayIterator();
let out = b;
let out = b;
let result: IteratorResult<ArrayLike<A>>;
let i = 0;
let i = 0;
while (!(result = iterator.next()).done) {
const array = result.value;
for (let j = 0; j < array.length; j++) {
Expand Down Expand Up @@ -548,9 +548,9 @@ export function foldRightWithIndex<A, B>(b: B, f: (i: number, a: A, b: B) => B)
return (self: Conc<A>): B => {
concrete(self);
const iterator = self.reverseArrayIterator();
let out = b;
let out = b;
let result: IteratorResult<ArrayLike<A>>;
let i = self.length - 1;
let i = self.length - 1;
while (!(result = iterator.next()).done) {
const array = result.value;
for (let j = array.length - 1; j >= 0; j--) {
Expand Down Expand Up @@ -653,14 +653,14 @@ export function mapAccum<A, S, B>(s: S, f: (s: S, a: A) => readonly [S, B]) {
return (self: Conc<A>): readonly [S, Conc<B>] => {
concrete(self);
const iterator = self.arrayIterator();
const out = builder<B>();
let state = s;
const out = builder<B>();
let state = s;
let result;
while (!(result = iterator.next()).done) {
const array = result.value;
const array = result.value;
const length = array.length;
for (let i = 0; i < length; i++) {
const a = array[i]!;
const a = array[i]!;
const tup = f(state, a);
out.append(tup[1]);
state = tup[0];
Expand Down Expand Up @@ -724,7 +724,7 @@ type Frame<A, B> = DoneFrame | ConcatLeftFrame<A> | ConcatRightFrame<B> | Append
export function mapWithIndex<A, B>(f: (i: number, a: A) => B) {
return (self: Conc<A>): Conc<B> => {
let current = self;
let index = 0;
let index = 0;
const stack = Stack<Frame<A, B>>();
stack.push(new DoneFrame());
let result: Conc<B> = Conc.empty();
Expand Down Expand Up @@ -856,10 +856,10 @@ export function partitionMapWithIndex<A, B, C>(f: (i: number, a: A) => Either<B,
return (fa: Conc<A>): readonly [Conc<B>, Conc<C>] => {
concrete(fa);
const iterator = fa.arrayIterator();
const left = builder<B>();
const right = builder<C>();
const left = builder<B>();
const right = builder<C>();
let result: IteratorResult<ArrayLike<A>>;
let i = 0;
let i = 0;
while (!(result = iterator.next()).done) {
const array = result.value;
for (let j = 0; j < array.length; j++) {
Expand All @@ -886,10 +886,10 @@ export function partitionWithIndex<A>(p: PredicateWithIndex<number, A>) {
return (self: Conc<A>): readonly [Conc<A>, Conc<A>] => {
concrete(self);
const iterator = self.arrayIterator();
const left = builder<A>();
const right = builder<A>();
const left = builder<A>();
const right = builder<A>();
let result: IteratorResult<ArrayLike<A>>;
let i = 0;
let i = 0;
while (!(result = iterator.next()).done) {
const array = result.value;
for (let j = 0; j < array.length; j++) {
Expand Down Expand Up @@ -958,7 +958,7 @@ export function slice(from: number, to: number) {
return <A>(self: Conc<A>): Conc<A> => {
concrete(self);
const start = from < 0 ? 0 : from > self.length ? self.length : from;
const end = to < start ? start : to > self.length ? self.length : to;
const end = to < start ? start : to > self.length ? self.length : to;
return new Slice(self, start, end - start);
};
}
Expand All @@ -982,12 +982,12 @@ export function splitWhere<A>(f: (a: A) => boolean) {
concrete(self);
const iterator = self.arrayIterator();
let next;
let cont = true;
let i = 0;
let cont = true;
let i = 0;
while (cont && (next = iterator.next()) && !next.done) {
const array = next.value;
const len = array.length;
let j = 0;
const len = array.length;
let j = 0;
while (cont && j < len) {
const a = array[j]!;
if (f(a)) {
Expand Down Expand Up @@ -1031,7 +1031,7 @@ export function takeWhile<A>(p: Predicate<A>) {
switch (self._tag) {
case ConcTag.Chunk: {
const arr = self.arrayLike();
let i = 0;
let i = 0;
while (i < arr.length && p(arr[i]!)) {
i++;
}
Expand All @@ -1040,11 +1040,11 @@ export function takeWhile<A>(p: Predicate<A>) {
default: {
const iterator = self.arrayIterator();
let result: IteratorResult<ArrayLike<A>>;
let cont = true;
let i = 0;
let cont = true;
let i = 0;
while (cont && !(result = iterator.next()).done) {
const array = result.value;
let j = 0;
let j = 0;
while (cont && j < array.length) {
if (!p(array[j]!)) {
cont = false;
Expand Down Expand Up @@ -1113,7 +1113,7 @@ export function toBuffer(self: Conc<Byte>): Uint8Array {
*/
export function unfold<A, B>(b: B, f: (b: B) => Maybe<readonly [A, B]>): Conc<A> {
const out = builder<A>();
let bb = b;
let bb = b;
while (true) {
const mt = f(bb);
if (mt.isJust()) {
Expand Down Expand Up @@ -1208,16 +1208,16 @@ export function zipWith<A, B, C>(fb: Conc<B>, f: (a: A, b: B) => C) {
if (length === 0) {
return Conc.empty();
} else {
const leftIterator = self.arrayIterator();
const leftIterator = self.arrayIterator();
const rightIterator = fb.arrayIterator();
const out = builder<C>();
let left: IteratorResult<ArrayLike<A>> = null as any;
const out = builder<C>();
let left: IteratorResult<ArrayLike<A>> = null as any;
let right: IteratorResult<ArrayLike<B>> = null as any;
let leftLength = 0;
let leftLength = 0;
let rightLength = 0;
let i = 0;
let j = 0;
let k = 0;
let i = 0;
let j = 0;
let k = 0;
while (i < length) {
if (j < leftLength && k < rightLength) {
const a = left.value[j];
Expand All @@ -1229,10 +1229,10 @@ export function zipWith<A, B, C>(fb: Conc<B>, f: (a: A, b: B) => C) {
k++;
} else if (j === leftLength && !(left = leftIterator.next()).done) {
leftLength = left.value.length;
j = 0;
j = 0;
} else if (k === rightLength && !(right = rightIterator.next()).done) {
rightLength = right.value.length;
k = 0;
k = 0;
}
}
return out.result();
Expand All @@ -1255,11 +1255,11 @@ export function zipWithIndexOffset(offset: number) {
concrete(as);
const iterator = as.arrayIterator();
let next: IteratorResult<ArrayLike<A>>;
let i = offset;
const out = builder<readonly [A, number]>();
let i = offset;
const out = builder<readonly [A, number]>();
while (!(next = iterator.next()).done) {
const array = next.value;
const len = array.length;
const len = array.length;
for (let j = 0; i < len; j++, i++) {
out.append([array[j]!, i]);
}
Expand Down
Loading

0 comments on commit 7503434

Please sign in to comment.