Skip to content

Commit

Permalink
feat(associative): enable TS strict compiler flags (refactor)
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 4, 2019
1 parent 8724f9e commit 7931e14
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/associative/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface IEquivSet<T>
IGet<T, T>,
IInto<T, IEquivSet<T>> {
disj(xs: Iterable<T>): this;
first(): T;
first(): T | undefined;
}

export interface EquivSetConstructor<T> {
Expand Down
6 changes: 3 additions & 3 deletions packages/associative/src/array-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ArraySet<T> extends Set<T> implements IEquivSet<T> {
vals && this.into(vals);
}

*[Symbol.iterator]() {
*[Symbol.iterator](): IterableIterator<T> {
yield* __private.get(this).vals;
}

Expand All @@ -42,7 +42,7 @@ export class ArraySet<T> extends Set<T> implements IEquivSet<T> {
return "ArraySet";
}

get size() {
get size(): number {
return __private.get(this).vals.length;
}

Expand All @@ -61,7 +61,7 @@ export class ArraySet<T> extends Set<T> implements IEquivSet<T> {
__private.get(this).vals.length = 0;
}

first() {
first(): T | undefined {
if (this.size) {
return __private.get(this).vals[0];
}
Expand Down
6 changes: 3 additions & 3 deletions packages/associative/src/equiv-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class EquivMap<K, V> extends Map<K, V>
return "EquivMap";
}

get size() {
get size(): number {
return __private.get(this).keys.size;
}

Expand All @@ -91,7 +91,7 @@ export class EquivMap<K, V> extends Map<K, V>
$this.map.clear();
}

empty() {
empty(): EquivMap<K, V> {
return new EquivMap<K, V>(null, __private.get(this).opts);
}

Expand Down Expand Up @@ -157,7 +157,7 @@ export class EquivMap<K, V> extends Map<K, V>
return notFound;
}

has(key: K) {
has(key: K): boolean {
return __private.get(this).keys.has(key);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/associative/src/hash-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class HashMap<K, V> extends Map<K, V>
return "HashMap";
}

get size() {
get size(): number {
return __private.get(this).size;
}

Expand Down Expand Up @@ -151,7 +151,7 @@ export class HashMap<K, V> extends Map<K, V>
return i >= 0 && $this.bins[i] != undefined;
}

get(key: K, notFound?: V) {
get(key: K, notFound?: V): V | undefined {
const $this = __private.get(this);
const i = this.find(key, $this);
return i >= 0 && $this.bins[i] ? $this.bins[i][1] : notFound;
Expand Down
4 changes: 2 additions & 2 deletions packages/associative/src/ll-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class LLSet<T> extends Set<T> implements IEquivSet<T> {
return "LLSet";
}

get size() {
get size(): number {
return __private.get(this).vals.length;
}

Expand All @@ -65,7 +65,7 @@ export class LLSet<T> extends Set<T> implements IEquivSet<T> {
__private.get(this).vals.clear();
}

first() {
first(): T | undefined {
if (this.size) {
return __private.get(this).vals.head.value;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/associative/src/merge-deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { IObjectOf } from "@thi.ng/api";
import { isPlainObject } from "@thi.ng/checks";
import { mergeObjWith } from "./merge-with";

export const mergeDeepObj = (dest: IObjectOf<any>, ...xs: IObjectOf<any>[]) =>
export const mergeDeepObj = (
dest: IObjectOf<any>,
...xs: IObjectOf<any>[]
): any =>
mergeObjWith(
(a, b) =>
isPlainObject(a) && isPlainObject(b) ? mergeDeepObj(a, b) : b,
Expand Down
2 changes: 1 addition & 1 deletion packages/associative/src/select-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const selectKeysObj = <T>(
): { [id in keyof T]?: T[id] } => {
const dest: any = {};
for (let k of ks) {
src.hasOwnProperty(k) && (dest[k] = src[<any>k]);
src.hasOwnProperty(k) && (dest[k] = (<any>src)[<any>k]);
}
return dest;
};
4 changes: 2 additions & 2 deletions packages/associative/src/sorted-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class SortedMap<K, V> extends Map<K, V> {
return map((p) => p[1], this.entries(key, max));
}

get size() {
get size(): number {
return __private.get(this).length;
}

Expand Down Expand Up @@ -189,7 +189,7 @@ export class SortedMap<K, V> extends Map<K, V> {
return true;
}

first(): Pair<K, V> {
first(): Pair<K, V> | undefined {
const node = __private.get(this).head.next[0];
return node ? [node.k, node.v] : undefined;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/associative/src/sorted-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class SortedSet<T> extends Set<T>
return "SortedSet";
}

get size() {
get size(): number {
return __private.get(this).size;
}

Expand Down Expand Up @@ -104,7 +104,7 @@ export class SortedSet<T> extends Set<T>
return true;
}

$reduce(rfn: ReductionFn<any, T>, acc: any) {
$reduce(rfn: ReductionFn<any, T>, acc: any): any {
return __private.get(this).$reduce((_acc, x) => rfn(_acc, x[0]), acc);
}

Expand Down Expand Up @@ -157,7 +157,7 @@ export class SortedSet<T> extends Set<T>
thisArg?: any
): void {
for (let p of this) {
fn.call(thisArg, p[0], p[0], this);
fn.call(thisArg, p, p, this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/associative/src/sparse-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export abstract class ASparseSet<T extends UIntArray> extends Set<number>
return this.keys();
}

get size() {
get size(): number {
return __private.get(this).n;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/associative/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Pair } from "@thi.ng/api";
import { implementsFunction, isMap, isSet } from "@thi.ng/checks";

export const empty = (x, ctor) =>
export const empty = (x: any, ctor: Function) =>
implementsFunction(x, "empty")
? x.empty()
: new (x[Symbol.species] || ctor)();

export const copy = (x, ctor) =>
export const copy = (x: any, ctor: Function) =>
implementsFunction(x, "copy")
? x.copy()
: new (x[Symbol.species] || ctor)(x);
Expand Down

0 comments on commit 7931e14

Please sign in to comment.