Skip to content

Commit

Permalink
rename to sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Nov 23, 2018
1 parent 7c7b2ad commit 9d3d0cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
42 changes: 21 additions & 21 deletions src/internal/interable.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@


export interface IIterable<T> extends Iterable<T> {
export interface ISequence<T> extends Iterable<T> {
readonly length: number;
filter(callback: (v: T, i: number) => boolean): IIterable<T>;
map<U>(callback: (v: T, i: number) => U): IIterable<U>;
filter(callback: (v: T, i: number) => boolean): ISequence<T>;
map<U>(callback: (v: T, i: number) => U): ISequence<U>;
forEach(callback: (v: T, i: number) => void): void;
}

class LazyFilter<T> implements IIterable<T> {
class LazyFilter<T> implements ISequence<T> {
private _length = -1;
constructor(private readonly it: IIterable<T>, private readonly filters: ((v: T, i: number) => boolean)[]) {
constructor(private readonly it: ISequence<T>, private readonly filters: ((v: T, i: number) => boolean)[]) {

}

Expand All @@ -23,11 +23,11 @@ class LazyFilter<T> implements IIterable<T> {
return l;
}

filter(callback: (v: T, i: number) => boolean): IIterable<T> {
filter(callback: (v: T, i: number) => boolean): ISequence<T> {
return new LazyFilter(this.it, this.filters.concat(callback));
}

map<U>(callback: (v: T, i: number) => U): IIterable<U> {
map<U>(callback: (v: T, i: number) => U): ISequence<U> {
return new LazyMap1(this, callback);
}

Expand Down Expand Up @@ -65,20 +65,20 @@ class LazyFilter<T> implements IIterable<T> {
}
}

class LazyMap1<T1, T2> implements IIterable<T2> {
constructor(private readonly it: IIterable<T1>, private readonly map12: (v: T1, i: number) => T2) {
class LazyMap1<T1, T2> implements ISequence<T2> {
constructor(private readonly it: ISequence<T1>, private readonly map12: (v: T1, i: number) => T2) {

}

get length() {
return this.it.length;
}

filter(callback: (v: T2, i: number) => boolean): IIterable<T2> {
filter(callback: (v: T2, i: number) => boolean): ISequence<T2> {
return new LazyFilter(this, [callback]);
}

map<U>(callback: (v: T2, i: number) => U): IIterable<U> {
map<U>(callback: (v: T2, i: number) => U): ISequence<U> {
return new LazyMap2(this.it, this.map12, callback);
}

Expand Down Expand Up @@ -110,20 +110,20 @@ class LazyMap1<T1, T2> implements IIterable<T2> {
}
}

class LazyMap2<T, T2, T3> implements IIterable<T3> {
constructor(private readonly it: IIterable<T>, private readonly map12: (v: T, i: number) => T2, private readonly map23: (v: T2, i: number) => T3) {
class LazyMap2<T, T2, T3> implements ISequence<T3> {
constructor(private readonly it: ISequence<T>, private readonly map12: (v: T, i: number) => T2, private readonly map23: (v: T2, i: number) => T3) {

}

get length() {
return this.it.length;
}

filter(callback: (v: T3, i: number) => boolean): IIterable<T3> {
filter(callback: (v: T3, i: number) => boolean): ISequence<T3> {
return new LazyFilter(this, [callback]);
}

map<U>(callback: (v: T3, i: number) => U): IIterable<U> {
map<U>(callback: (v: T3, i: number) => U): ISequence<U> {
return new LazyMap3(this.it, this.map12, this.map23, callback);
}

Expand Down Expand Up @@ -156,20 +156,20 @@ class LazyMap2<T, T2, T3> implements IIterable<T3> {
}


class LazyMap3<T1, T2, T3, T4> implements IIterable<T4> {
constructor(private readonly it: IIterable<T1>, private readonly map12: (v: T1, i: number) => T2, private readonly map23: (v: T2, i: number) => T3, private readonly map34: (v: T3, i: number) => T4) {
class LazyMap3<T1, T2, T3, T4> implements ISequence<T4> {
constructor(private readonly it: ISequence<T1>, private readonly map12: (v: T1, i: number) => T2, private readonly map23: (v: T2, i: number) => T3, private readonly map34: (v: T3, i: number) => T4) {

}

get length() {
return this.it.length;
}

filter(callback: (v: T4, i: number) => boolean): IIterable<T4> {
filter(callback: (v: T4, i: number) => boolean): ISequence<T4> {
return new LazyFilter(this, [callback]);
}

map<U>(callback: (v: T4, i: number) => U): IIterable<U> {
map<U>(callback: (v: T4, i: number) => U): ISequence<U> {
const map1U = (v: T1, i: number) => callback(this.map34(this.map23(this.map12(v, i), i), i), i);
return new LazyMap1(this.it, map1U);
}
Expand Down Expand Up @@ -202,7 +202,7 @@ class LazyMap3<T1, T2, T3, T4> implements IIterable<T4> {
}
}

export function lazy<T>(it: Iterable<T>): IIterable<T> {
export function lazy<T>(it: Iterable<T>): ISequence<T> {
let v: ReadonlyArray<T> | null = null;
const asArr = () => {
if (v) {
Expand Down Expand Up @@ -242,5 +242,5 @@ export function lazy<T>(it: Iterable<T>): IIterable<T> {
}
});

return <IIterable<T>><any>r;
return <ISequence<T>><any>r;
}
8 changes: 4 additions & 4 deletions src/internal/math.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {histogram, quantile} from 'd3-array';
import {ICategory, isMissingValue} from '../model';
import {IIterable} from './interable';
import {ISequence} from './interable';

export interface INumberBin {
x0: number;
Expand Down Expand Up @@ -68,7 +68,7 @@ export class LazyBoxPlotData implements IStatistics {

private readonly histGen: (data: number[]) => INumberBin[];

constructor(values: IIterable<number>, histGen?: (data: number[]) => INumberBin[]) {
constructor(values: ISequence<number>, histGen?: (data: number[]) => INumberBin[]) {
// filter out NaN
let min = Number.POSITIVE_INFINITY;
let max = Number.NEGATIVE_INFINITY;
Expand Down Expand Up @@ -211,7 +211,7 @@ function cached() {
* @returns {{min: number, max: number, count: number, hist: histogram.Bin<number>[]}}
* @internal
*/
export function computeStats(arr: IIterable<number>, range?: [number, number], bins?: number): IStatistics {
export function computeStats(arr: ISequence<number>, range?: [number, number], bins?: number): IStatistics {
if (arr.length === 0) {
return {
min: NaN,
Expand Down Expand Up @@ -249,7 +249,7 @@ export function computeStats(arr: IIterable<number>, range?: [number, number], b
* @returns {{hist: {cat: string, y: number}[]}}
* @internal
*/
export function computeHist(arr: IIterable<ICategory | null>, categories: ICategory[]): ICategoricalStatistics {
export function computeHist(arr: ISequence<ICategory | null>, categories: ICategory[]): ICategoricalStatistics {
const m = new Map<string, number>();
let missingCount = 0;
categories.forEach((cat) => m.set(cat.name, 0));
Expand Down

0 comments on commit 9d3d0cd

Please sign in to comment.