diff --git a/expensiveOptimized.ts b/expensiveOptimized.ts new file mode 100644 index 0000000..177cf7b --- /dev/null +++ b/expensiveOptimized.ts @@ -0,0 +1,172 @@ +interface Iterable {} + +const unrelated = Symbol() +type unrelated = typeof unrelated +interface Collections { + [unrelated]: V[] +} + +interface ZipConcatMixin> { + zip(other: Collection): Collections[SelfIdentifier]; + zip(other: Collection, other2: Collection): Collections[SelfIdentifier]; + //zip(other: Collection, other2: Collection, other3: Collection): Collections<[T,U,V,M]>[SelfIdentifier]; + zip(...collections: Array>): Collections[SelfIdentifier]; + + concat(...valuesOrCollections: Array | C>): Collections[SelfIdentifier]; +} + +interface MapFilterMixin> { + map( + mapper: (value: V, key: K, iter: this) => M, + context?: any + ): Collections[SelfIdentifier]; + // flatMap( + // mapper: (value: V, key: K, iter: this) => Iterable, + // context?: any + // ): Collections[SelfIdentifier]; + filter( + predicate: (value: V, index: K, iter: this) => value is F, + context?: any + ): Collections[SelfIdentifier]; + filter( + predicate: (value: V, index: K, iter: this) => any, + context?: any + ): this; +} + +export interface List extends CollectionIndexed { +} +const ListSelf = Symbol() +type ListSelf = typeof ListSelf +interface Collections { + [ListSelf]: List +} + +export interface SeqIndexed extends CollectionIndexed { + toSeq(): this + + zipAll(...collections: Array>): SeqIndexed; +} +const SeqIndexedSelf = Symbol() +type SeqIndexedSelf = typeof SeqIndexedSelf +interface Collections { + [SeqIndexedSelf]: SeqIndexed +} + +export interface CollectionIndexed = CollectionIndexedSelf> extends Collection, ZipConcatMixin { + interpose(separator: T): this; +} +const CollectionIndexedSelf = Symbol() +type CollectionIndexedSelf = typeof CollectionIndexedSelf +interface Collections { + [CollectionIndexedSelf]: CollectionIndexed +} + +export interface Collection = CollectionSelf> extends MapFilterMixin { + + // Conversion to JavaScript types + + toJS(): Array | { [key: string]: any }; + toJSON(): Array | { [key: string]: V }; + + // Conversion to Collections + + toMap(): Collection; + toOrderedMap(): Collection; + toSet(): Collection; + toOrderedSet(): Collection; + toList(): List; + toStack(): Collection; + + // Conversion to Seq + + toSeq(): Collection; + toKeyedSeq(): Collection; + toIndexedSeq(): SeqIndexed; + + // Sequence algorithms + + // map( + // mapper: (value: V, key: K, iter: this) => M, + // context?: any + // ): Collection; + // filter( + // predicate: (value: V, key: K, iter: this) => value is F, + // context?: any + // ): Collection; + // filter( + // predicate: (value: V, key: K, iter: this) => any, + // context?: any + // ): this; + filterNot( + predicate: (value: V, key: K, iter: this) => boolean, + context?: any + ): this; + sort(comparator?: (valueA: V, valueB: V) => number): this; + sortBy( + comparatorValueMapper: (value: V, key: K, iter: this) => C, + comparator?: (valueA: C, valueB: C) => number + ): this; + groupBy( + grouper: (value: V, key: K, iter: this) => G, + context?: any + ): /*Map*/Collection>; + + // Padding + takeUntil0(predicate: (iter: this) => boolean): this; + takeUntil1(predicate: (iter: this) => boolean): this; + takeUntil2(predicate: (iter: this) => boolean): this; + takeUntil3(predicate: (iter: this) => boolean): this; + takeUntil4(predicate: (iter: this) => boolean): this; + takeUntil5(predicate: (iter: this) => boolean): this; + takeUntil6(predicate: (iter: this) => boolean): this; + ttakeUntil0(predicate: (iter: this) => boolean): this; + ttakeUntil1(predicate: (iter: this) => boolean): this; + ttakeUntil2(predicate: (iter: this) => boolean): this; + ttakeUntil3(predicate: (iter: this) => boolean): this; + ttakeUntil4(predicate: (iter: this) => boolean): this; + ttakeUntil5(predicate: (iter: this) => boolean): this; + ttakeUntil6(predicate: (iter: this) => boolean): this; + tttakeUntil0(predicate: (iter: this) => boolean): this; + tttakeUntil1(predicate: (iter: this) => boolean): this; + tttakeUntil2(predicate: (iter: this) => boolean): this; + tttakeUntil3(predicate: (iter: this) => boolean): this; + tttakeUntil4(predicate: (iter: this) => boolean): this; + tttakeUntil5(predicate: (iter: this) => boolean): this; + tttakeUntil6(predicate: (iter: this) => boolean): this; + ttttakeUntil0(predicate: (iter: this) => boolean): this; + ttttakeUntil1(predicate: (iter: this) => boolean): this; + ttttakeUntil2(predicate: (iter: this) => boolean): this; + ttttakeUntil3(predicate: (iter: this) => boolean): this; + ttttakeUntil4(predicate: (iter: this) => boolean): this; + ttttakeUntil5(predicate: (iter: this) => boolean): this; + ttttakeUntil6(predicate: (iter: this) => boolean): this; + + tttttakeUntil0(predicate: (iter: this) => boolean): this; + tttttakeUntil1(predicate: (iter: this) => boolean): this; + tttttakeUntil2(predicate: (iter: this) => boolean): this; + tttttakeUntil3(predicate: (iter: this) => boolean): this; + tttttakeUntil4(predicate: (iter: this) => boolean): this; + tttttakeUntil5(predicate: (iter: this) => boolean): this; + tttttakeUntil6(predicate: (iter: this) => boolean): this; +} +const CollectionSelf = Symbol() +type CollectionSelf = typeof CollectionSelf +interface Collections { + [CollectionSelf]: Collection +} + +function a () { + const a: SeqIndexed = 0 as any + const b: CollectionIndexed = a + + const c: CollectionIndexed = 0 as any + c.zip(0 as any as Collection) + const d: CollectionIndexed = c + d.zip(0 as any as Collection) + + return b +} + +const b: SeqIndexed<(number | string)> = 0 as any +const c = b.filter((v): v is number => typeof v !== "string") \ No newline at end of file