Skip to content

Commit

Permalink
refactor(iterators): remove default exports
Browse files Browse the repository at this point in the history
BREAKING CHANGE: switch back to named function exports for project consistency
and following lead from tslint (https://palantir.github.io/tslint/rules/no-default-export/)
  • Loading branch information
postspectacular committed Jan 29, 2018
1 parent 1e9dc85 commit 651d07c
Show file tree
Hide file tree
Showing 51 changed files with 147 additions and 147 deletions.
4 changes: 2 additions & 2 deletions packages/iterators/src/butlast.ts
@@ -1,6 +1,6 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export default function* butLast<T>(input: Iterable<T>) {
export function* butLast<T>(input: Iterable<T>) {
let iter = iterator(input),
v: IteratorResult<T>,
prev: T,
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/cached.ts
@@ -1,6 +1,6 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export default function cached<T>(input: Iterable<T>) {
export function cached<T>(input: Iterable<T>) {
let cache: T[] = [],
iter = iterator(input),
done = false;
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/concat.ts
@@ -1,7 +1,7 @@
import iterator from "./iterator";
import { iterator } from "./iterator";
import { ensureIterable } from "./ensure";

export default function* concat<T>(...inputs: Iterable<T>[]) {
export function* concat<T>(...inputs: Iterable<T>[]) {
let iter = iterator(inputs),
v: IteratorResult<Iterable<T>>;
while (((v = iter.next()), !v.done)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/iterators/src/constantly.ts
@@ -1,3 +1,3 @@
export default function constantly<T>(x: T): (...args: any[]) => T {
export function constantly<T>(x: T): (...args: any[]) => T {
return () => x;
}
2 changes: 1 addition & 1 deletion packages/iterators/src/consume.ts
@@ -1,4 +1,4 @@
export default function consume(iter: Iterator<any>, n = Number.POSITIVE_INFINITY) {
export function consume(iter: Iterator<any>, n = Number.POSITIVE_INFINITY) {
while (n-- > 0 && !iter.next().done) { }
return iter;
}
4 changes: 2 additions & 2 deletions packages/iterators/src/cycle.ts
@@ -1,6 +1,6 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export default function* cycle<T>(input: Iterable<T>) {
export function* cycle<T>(input: Iterable<T>) {
let cache: T[] = [],
iter = iterator(input),
v: IteratorResult<T>;
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/dedupe-with.ts
@@ -1,6 +1,6 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export default function* dedupeWith<T>(equiv: (a: T, b: T) => boolean, input: Iterable<T>) {
export function* dedupeWith<T>(equiv: (a: T, b: T) => boolean, input: Iterable<T>) {
let iter = iterator(input),
v: IteratorResult<T>,
prev: T;
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/dedupe.ts
@@ -1,6 +1,6 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export default function* dedupe<T>(input: Iterable<T>) {
export function* dedupe<T>(input: Iterable<T>) {
let iter = iterator(input),
v: IteratorResult<T>,
prev: T;
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/dense.ts
@@ -1,5 +1,5 @@
import filter from "./filter";
import { filter } from "./filter";

export default function dense<T>(input: Iterable<T>) {
export function dense<T>(input: Iterable<T>) {
return filter(x => x != null, input);
}
6 changes: 3 additions & 3 deletions packages/iterators/src/drop-nth.ts
@@ -1,8 +1,8 @@
import iterator from "./iterator";
import take from "./take";
import { iterator } from "./iterator";
import { take } from "./take";
import { ensureIterable } from "./ensure";

export default function* dropNth<T>(n: number, input: Iterable<T>) {
export function* dropNth<T>(n: number, input: Iterable<T>) {
let iter = ensureIterable(iterator(input));
do {
yield* take(n - 1, iter);
Expand Down
2 changes: 1 addition & 1 deletion packages/iterators/src/drop-while.ts
@@ -1,6 +1,6 @@
import { ensureIterator } from "./ensure";

export default function* dropWhile<T>(pred: (x: T) => boolean, input: Iterable<T>) {
export function* dropWhile<T>(pred: (x: T) => boolean, input: Iterable<T>) {
let iter = ensureIterator(input),
v: IteratorResult<T>;
while (((v = iter.next()), !v.done && pred(v.value) === true)) { }
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/drop.ts
@@ -1,7 +1,7 @@
import consume from "./consume";
import { consume } from "./consume";
import { ensureIterator } from "./ensure";

export default function* drop<T>(n: number, input: Iterable<T>) {
export function* drop<T>(n: number, input: Iterable<T>) {
let iter = ensureIterator(input);
consume(iter, n);
yield* iter;
Expand Down
2 changes: 1 addition & 1 deletion packages/iterators/src/ensure.ts
@@ -1,4 +1,4 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export function ensureIterable(x: any): IterableIterator<any> {
if (!(x != null && x[Symbol.iterator])) {
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/every.ts
@@ -1,6 +1,6 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export default function every<T>(pred: (x: T) => boolean, input: Iterable<T>) {
export function every<T>(pred: (x: T) => boolean, input: Iterable<T>) {
let iter = iterator(input),
v: IteratorResult<T>,
empty = true;
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/filter.ts
@@ -1,6 +1,6 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export default function* filter<T>(pred: (x: T) => boolean, input: Iterable<T>) {
export function* filter<T>(pred: (x: T) => boolean, input: Iterable<T>) {
let iter = iterator(input),
v: IteratorResult<T>;
while (((v = iter.next()), !v.done)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/flatten-with.ts
@@ -1,6 +1,6 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export default function* flattenWith(tx: (x: any) => any, input: Iterable<any>): IterableIterator<any> {
export function* flattenWith(tx: (x: any) => any, input: Iterable<any>): IterableIterator<any> {
let iter = iterator(input),
v: IteratorResult<any>, val, res;
while (((v = iter.next()), !v.done)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/flatten.ts
@@ -1,8 +1,8 @@
import flattenWith from "./flatten-with";
import { flattenWith } from "./flatten-with";
import { maybeIterator } from "./iterator";
import { maybeObjectIterator } from "./object-iterator";

export default function flatten(input: Iterable<any>, includeObjects = true) {
export function flatten(input: Iterable<any>, includeObjects = true) {
return flattenWith(
(x) =>
(typeof x !== "string" &&
Expand Down
2 changes: 1 addition & 1 deletion packages/iterators/src/fnil.ts
@@ -1,4 +1,4 @@
export default function fnil(fn: (...args: any[]) => any, ...ctors: (() => any)[]) {
export function fnil(fn: (...args: any[]) => any, ...ctors: (() => any)[]) {
let [cta, ctb, ctc] = ctors;
switch (ctors.length) {
case 1:
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/fork.ts
@@ -1,8 +1,8 @@
import { DCons } from "@thi.ng/dcons";

import iterator from "./iterator";
import { iterator } from "./iterator";

export default function fork<T>(src: Iterable<T>, cacheLimit = 16) {
export function fork<T>(src: Iterable<T>, cacheLimit = 16) {
const iter = iterator(src),
cache = new DCons<T>(),
forks = [];
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/frequencies.ts
@@ -1,11 +1,11 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export interface FrequencyPair<T> {
[0]: T;
[1]: number;
}

export default function* frequencies<T>(input: Iterable<T>, key?: (v: T) => any): IterableIterator<FrequencyPair<T>[]> {
export function* frequencies<T>(input: Iterable<T>, key?: (v: T) => any): IterableIterator<FrequencyPair<T>[]> {
let freqs = {},
iter = iterator(input),
v: IteratorResult<any>;
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/group-by.ts
@@ -1,6 +1,6 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export default function groupBy<T>(key: (v) => any, input: Iterable<T>): { [id: string]: T[] } {
export function groupBy<T>(key: (v) => any, input: Iterable<T>): { [id: string]: T[] } {
let groups = {},
iter = iterator(input),
v: IteratorResult<any>;
Expand Down
2 changes: 1 addition & 1 deletion packages/iterators/src/identity.ts
@@ -1,3 +1,3 @@
export default function identity<T>(x: T) {
export function identity<T>(x: T) {
return x;
}
100 changes: 50 additions & 50 deletions packages/iterators/src/index.ts
@@ -1,50 +1,50 @@
export { default as butLast } from "./butlast";
export { default as cached } from "./cached";
export { default as concat } from "./concat";
export { default as constantly } from "./constantly";
export { default as consume } from "./consume";
export { default as cycle } from "./cycle";
export { default as dedupeWith } from "./dedupe-with";
export { default as dedupe } from "./dedupe";
export { default as dense } from "./dense";
export { default as dropNth } from "./drop-nth";
export { default as dropWhile } from "./drop-while";
export { default as drop } from "./drop";
export { ensureIterable, ensureIterator } from "./ensure";
export { default as every } from "./every";
export { default as filter } from "./filter";
export { default as flattenWith } from "./flatten-with";
export { default as flatten } from "./flatten";
export { default as fnil } from "./fnil";
export { default as fork } from "./fork";
export { default as frequencies } from "./frequencies";
export { default as groupBy } from "./group-by";
export { default as identity } from "./identity";
export { default as indexed } from "./indexed";
export { default as interleave } from "./interleave";
export { default as interpose } from "./interpose";
export { default as iterate } from "./iterate";
export { default as iterator, maybeIterator } from "./iterator";
export { default as juxt } from "./juxt";
export { default as last } from "./last";
export { default as mapIndexed } from "./map-indexed";
export { default as map } from "./map";
export { default as mapcat } from "./mapcat";
export { default as objectIterator, maybeObjectIterator } from "./object-iterator";
export { default as partitionBy } from "./partition-by";
export { default as partition } from "./partition";
export { default as randomSample } from "./random-sample";
export { default as range } from "./range";
export { default as reduce, reduced, ReducedValue } from "./reduce";
export { default as reductions } from "./reductions";
export { default as repeat } from "./repeat";
export { default as repeatedly } from "./repeatedly";
export { default as reverse } from "./reverse";
export { default as run } from "./run";
export { default as some } from "./some";
export { default as takeLast } from "./take-last";
export { default as takeNth } from "./take-nth";
export { default as takeWhile } from "./take-while";
export { default as take } from "./take";
export { default as walk, walkIterator } from "./walk";
export { default as zip } from "./zip";
export * from "./butlast";
export * from "./cached";
export * from "./concat";
export * from "./constantly";
export * from "./consume";
export * from "./cycle";
export * from "./dedupe-with";
export * from "./dedupe";
export * from "./dense";
export * from "./drop-nth";
export * from "./drop-while";
export * from "./drop";
export * from "./ensure";
export * from "./every";
export * from "./filter";
export * from "./flatten-with";
export * from "./flatten";
export * from "./fnil";
export * from "./fork";
export * from "./frequencies";
export * from "./group-by";
export * from "./identity";
export * from "./indexed";
export * from "./interleave";
export * from "./interpose";
export * from "./iterate";
export * from "./iterator";
export * from "./juxt";
export * from "./last";
export * from "./map-indexed";
export * from "./map";
export * from "./mapcat";
export * from "./object-iterator";
export * from "./partition-by";
export * from "./partition";
export * from "./random-sample";
export * from "./range";
export * from "./reduce";
export * from "./reductions";
export * from "./repeat";
export * from "./repeatedly";
export * from "./reverse";
export * from "./run";
export * from "./some";
export * from "./take-last";
export * from "./take-nth";
export * from "./take-while";
export * from "./take";
export * from "./walk";
export * from "./zip";
4 changes: 2 additions & 2 deletions packages/iterators/src/indexed.ts
@@ -1,5 +1,5 @@
import mapIndexed from "./map-indexed";
import { mapIndexed } from "./map-indexed";

export default function indexed<T>(input: Iterable<T>): IterableIterator<[number, T]> {
export function indexed<T>(input: Iterable<T>): IterableIterator<[number, T]> {
return mapIndexed((i, x) => [i, x], input);
}
8 changes: 4 additions & 4 deletions packages/iterators/src/interleave.ts
@@ -1,8 +1,8 @@
import cycle from "./cycle";
import map from "./map";
import iterator from "./iterator";
import { cycle } from "./cycle";
import { map } from "./map";
import { iterator } from "./iterator";

export default function* interleave(...inputs: Iterable<any>[]) {
export function* interleave(...inputs: Iterable<any>[]) {
let n = inputs.length;
if (n === 0) {
throw new Error(`no inputs given`);
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/interpose.ts
@@ -1,6 +1,6 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export default function* interpose(x: any, input: Iterable<any>) {
export function* interpose(x: any, input: Iterable<any>) {
let iter = iterator(input),
v: IteratorResult<any> = iter.next();
while (!v.done) {
Expand Down
2 changes: 1 addition & 1 deletion packages/iterators/src/iterate.ts
@@ -1,4 +1,4 @@
export default function* iterate<T>(fn: (x: T) => T, seed: T) {
export function* iterate<T>(fn: (x: T) => T, seed: T) {
while (true) {
yield seed;
seed = fn(seed);
Expand Down
2 changes: 1 addition & 1 deletion packages/iterators/src/iterator.ts
@@ -1,4 +1,4 @@
export default function iterator<T>(x: Iterable<T>) {
export function iterator<T>(x: Iterable<T>) {
return x[Symbol.iterator]();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/iterators/src/juxt.ts
@@ -1,4 +1,4 @@
export default function juxt<T>(...fns: ((x: T) => any)[]) {
export function juxt<T>(...fns: ((x: T) => any)[]) {
return function (x: T) {
let res = [];
for (let i = 0; i < fns.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/last.ts
@@ -1,6 +1,6 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export default function last<T>(input: Iterable<T>) {
export function last<T>(input: Iterable<T>) {
let iter = iterator(input),
v: IteratorResult<T>,
prev: T;
Expand Down
6 changes: 3 additions & 3 deletions packages/iterators/src/map-indexed.ts
@@ -1,6 +1,6 @@
import map from "./map";
import range from "./range";
import { map } from "./map";
import { range } from "./range";

export default function mapIndexed<T>(fn: (i: number, ...args: any[]) => T[], ...inputs: Iterable<any>[]): IterableIterator<T> {
export function mapIndexed<T>(fn: (i: number, ...args: any[]) => T[], ...inputs: Iterable<any>[]): IterableIterator<T> {
return map.apply(null, ([fn, range()] as any[]).concat(inputs));
}
4 changes: 2 additions & 2 deletions packages/iterators/src/map.ts
@@ -1,6 +1,6 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export default function* map<T>(fn: (...args: any[]) => T, ...inputs: Iterable<any>[]) {
export function* map<T>(fn: (...args: any[]) => T, ...inputs: Iterable<any>[]) {
let v: IteratorResult<T>,
n = inputs.length;
switch (n) {
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/mapcat.ts
@@ -1,7 +1,7 @@
import map from "./map";
import { map } from "./map";
import { ensureIterable } from "./ensure";

export default function* mapcat<T>(fn: (...args: any[]) => Iterable<T>, ...inputs: Iterable<any>[]): IterableIterator<T> {
export function* mapcat<T>(fn: (...args: any[]) => Iterable<T>, ...inputs: Iterable<any>[]): IterableIterator<T> {
(inputs as any[]).unshift(fn);
let iter = map.apply(null, inputs),
v: IteratorResult<Iterable<T>>;
Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/object-iterator.ts
@@ -1,6 +1,6 @@
import map from "./map";
import { map } from "./map";

export default function objectIterator(x: any) {
export function objectIterator(x: any) {
return map((k) => [k, x[k]], Object.keys(x));
}

Expand Down
4 changes: 2 additions & 2 deletions packages/iterators/src/partition-by.ts
@@ -1,6 +1,6 @@
import iterator from "./iterator";
import { iterator } from "./iterator";

export default function* partitionBy<T>(fn: (x: T) => any, input: Iterable<T>) {
export function* partitionBy<T>(fn: (x: T) => any, input: Iterable<T>) {
let iter = iterator(input),
chunk: T[] = [],
v: IteratorResult<T>,
Expand Down

0 comments on commit 651d07c

Please sign in to comment.