Skip to content

Commit

Permalink
feat: 🎸 biome applied
Browse files Browse the repository at this point in the history
  • Loading branch information
jamashita committed Apr 17, 2024
1 parent bc3026e commit 4f43c78
Show file tree
Hide file tree
Showing 74 changed files with 1,028 additions and 1,698 deletions.
34 changes: 18 additions & 16 deletions src/address/AAddress.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Objet } from '@jamashita/anden/object';
import { BinaryPredicate, ForEach, Mapping, Nullable } from '@jamashita/anden/type';
import { NarrowingBinaryPredicate, Quantity } from '../collection/index.js';
import { Address } from './Address.js';
import type { BinaryPredicate, ForEach, Mapping, Nullable } from '@jamashita/anden/type';
import { type NarrowingBinaryPredicate, Quantity } from '../collection/index.js';
import type { Address } from './Address.js';

export abstract class AAddress<out V> extends Quantity<void, V> implements Address<V> {
protected readonly address: Map<V | string, V>;
Expand Down Expand Up @@ -55,11 +55,11 @@ export abstract class AAddress<out V> extends Quantity<void, V> implements Addre
protected filterInternal<W extends V = V>(predicate: NarrowingBinaryPredicate<V, W, void>): Map<W | string, W> {
const m: Map<W | string, W> = new Map();

this.address.forEach((value: V) => {
if (predicate(value, undefined)) {
m.set(Quantity.genKey(value), value);
for (const [, v] of this.address) {
if (predicate(v, undefined)) {
m.set(Quantity.genKey(v), v);
}
});
}

return m;
}
Expand All @@ -77,9 +77,9 @@ export abstract class AAddress<out V> extends Quantity<void, V> implements Addre
}

public forEach(foreach: ForEach<void, V>): void {
this.address.forEach((v: V) => {
for (const [, v] of this.address) {
foreach(v);
});
}
}

public get(): null {
Expand All @@ -90,7 +90,9 @@ export abstract class AAddress<out V> extends Quantity<void, V> implements Addre
return this.address.has(Quantity.genKey(value));
}

// biome-ignore lint/suspicious/noConfusingVoidType: <explanation>
public iterator(): IterableIterator<[void, V]> {
// biome-ignore lint/suspicious/noConfusingVoidType: <explanation>
const iterable: Array<[void, V]> = [];

for (const [, v] of this.address) {
Expand All @@ -102,24 +104,24 @@ export abstract class AAddress<out V> extends Quantity<void, V> implements Addre

protected mapInternal<W>(mapping: Mapping<V, W>): Map<W | string, W> {
const m: Map<W | string, W> = new Map();
let i: number = 0;
let i = 0;

this.address.forEach((value: V) => {
const w: W = mapping(value, i);
for (const [, v] of this.address) {
const w: W = mapping(v, i);

m.set(Quantity.genKey(w), w);
i++;
});
}

return m;
}

public serialize(): string {
const props: Array<string> = [];

this.forEach((element: V) => {
props.push(Objet.identify(element));
});
for (const [, v] of this.address) {
props.push(Objet.identify(v));
}

return props.join(', ');
}
Expand Down
6 changes: 3 additions & 3 deletions src/address/Address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BinaryPredicate, Mapping } from '@jamashita/anden/type';
import { NarrowingBinaryPredicate } from '../collection/index.js';
import { ReadonlyAddress } from './ReadonlyAddress.js';
import type { BinaryPredicate, Mapping } from '@jamashita/anden/type';
import type { NarrowingBinaryPredicate } from '../collection/index.js';
import type { ReadonlyAddress } from './ReadonlyAddress.js';

export interface Address<out V> extends ReadonlyAddress<V> {
add(value: V): Address<V>;
Expand Down
52 changes: 27 additions & 25 deletions src/address/AddressUtil.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
import { Reject, Resolve, UnaryFunction } from '@jamashita/anden/type';
import { Address } from './Address.js';
import { ReadonlyAddress } from './ReadonlyAddress.js';
import type { Reject, Resolve, UnaryFunction } from '@jamashita/anden/type';
import type { Address } from './Address.js';
import type { ReadonlyAddress } from './ReadonlyAddress.js';

// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class AddressUtil {
public static await<V, A extends Address<V>>(address: ReadonlyAddress<PromiseLike<V>>, callback: UnaryFunction<Set<V>, A>): Promise<A> {
export namespace AddressUtil {
export const wait = <V, A extends Address<V>>(address: ReadonlyAddress<PromiseLike<V>>, callback: UnaryFunction<Set<V>, A>): Promise<A> => {
if (address.isEmpty()) {
return Promise.resolve(callback(new Set()));
}

let rejected: boolean = false;
let rejected = false;
const set: Set<V> = new Set();

return new Promise((resolve: Resolve<A>, reject: Reject) => {
address.forEach((value: PromiseLike<V>) => {
value.then((v: V) => {
if (rejected) {
return;
}
for (const value of address.values()) {
value.then(
(v: V) => {
if (rejected) {
return;
}

set.add(v);
set.add(v);

if (set.size === address.size()) {
resolve(callback(set));
}
}, (e: unknown) => {
if (rejected) {
return;
}
if (set.size === address.size()) {
resolve(callback(set));
}
},
(e: unknown) => {
if (rejected) {
return;
}

rejected = true;
rejected = true;

reject(e);
});
});
reject(e);
}
);
}
});
}
};
}
12 changes: 6 additions & 6 deletions src/address/ImmutableAddress.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { BinaryPredicate, Mapping } from '@jamashita/anden/type';
import { Collection, NarrowingBinaryPredicate, Quantity } from '../collection/index.js';
import type { BinaryPredicate, Mapping } from '@jamashita/anden/type';
import { type Collection, type NarrowingBinaryPredicate, Quantity } from '../collection/index.js';
import { AAddress } from './AAddress.js';
import { AddressUtil } from './AddressUtil.js';
import { ReadonlyAddress } from './ReadonlyAddress.js';
import type { ReadonlyAddress } from './ReadonlyAddress.js';

export class ImmutableAddress<out V> extends AAddress<V> {
private static readonly EMPTY: ImmutableAddress<unknown> = new ImmutableAddress(new Map());

public static await<V>(address: ReadonlyAddress<PromiseLike<V>>): Promise<ImmutableAddress<V>> {
return AddressUtil.await(address, (values: Set<V>) => {
return AddressUtil.wait(address, (values: Set<V>) => {
return ImmutableAddress.ofSet(values);
});
}
Expand All @@ -34,9 +34,9 @@ export class ImmutableAddress<out V> extends AAddress<V> {
public static ofSet<V>(set: ReadonlySet<V>): ImmutableAddress<V> {
const m: Map<V | string, V> = new Map();

set.forEach((v: V) => {
for (const v of set) {
m.set(Quantity.genKey(v), v);
});
}

return ImmutableAddress.ofInternal(m);
}
Expand Down
12 changes: 6 additions & 6 deletions src/address/MutableAddress.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BinaryPredicate, Mapping } from '@jamashita/anden/type';
import { Collection, NarrowingBinaryPredicate, Quantity } from '../collection/index.js';
import type { BinaryPredicate, Mapping } from '@jamashita/anden/type';
import { type Collection, type NarrowingBinaryPredicate, Quantity } from '../collection/index.js';
import { AAddress } from './AAddress.js';
import { AddressUtil } from './AddressUtil.js';
import { ReadonlyAddress } from './ReadonlyAddress.js';
import type { ReadonlyAddress } from './ReadonlyAddress.js';

export class MutableAddress<out V> extends AAddress<V> {
public static await<V>(address: ReadonlyAddress<PromiseLike<V>>): Promise<MutableAddress<V>> {
return AddressUtil.await(address, (values: Set<V>) => {
return AddressUtil.wait(address, (values: Set<V>) => {
return MutableAddress.ofSet(values);
});
}
Expand All @@ -28,9 +28,9 @@ export class MutableAddress<out V> extends AAddress<V> {
public static ofSet<V>(set: ReadonlySet<V>): MutableAddress<V> {
const m: Map<V | string, V> = new Map();

set.forEach((v: V) => {
for (const v of set) {
m.set(Quantity.genKey(v), v);
});
}

return MutableAddress.ofInternal(m);
}
Expand Down
4 changes: 2 additions & 2 deletions src/address/ReadonlyAddress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BinaryPredicate, Cloneable, Mapping } from '@jamashita/anden/type';
import { Collection, NarrowingBinaryPredicate } from '../collection/index.js';
import type { BinaryPredicate, Cloneable, Mapping } from '@jamashita/anden/type';
import type { Collection, NarrowingBinaryPredicate } from '../collection/index.js';

export interface ReadonlyAddress<out V> extends Collection<void, V>, Cloneable<ReadonlyAddress<V>> {
filter<W extends V>(predicate: NarrowingBinaryPredicate<V, W, void>): ReadonlyAddress<W>;
Expand Down
Loading

0 comments on commit 4f43c78

Please sign in to comment.