Skip to content

Commit

Permalink
Add static onErrorResumeNext()
Browse files Browse the repository at this point in the history
  • Loading branch information
emonkak committed Nov 24, 2016
1 parent 4110112 commit 428ebea
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/Enumerable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Enumerable } from './internal/Enumerable';

export default Enumerable;

14 changes: 14 additions & 0 deletions src/extensions/static/onErrorResumeNext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import onErrorResumeNextFn from '../../static/onErrorResumeNext';
import { Enumerable } from '../../internal/Enumerable';

function onErrorResumeNext<TSource>(...sources: Iterable<TSource>[]): Enumerable<TSource> {
return new Enumerable(onErrorResumeNextFn(...sources));
}

Enumerable.onErrorResumeNext = onErrorResumeNext;

declare module '../../internal/Enumerable' {
namespace Enumerable {
export function onErrorResumeNext<TSource>(...sources: Iterable<TSource>[]): Enumerable<TSource>;
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import './extensions/static/concat';
import './extensions/static/defer';
import './extensions/static/generate';
import './extensions/static/if';
import './extensions/static/onErrorResumeNext';
import './extensions/static/range';
import './extensions/static/repeat';
import './extensions/static/return';
Expand Down
5 changes: 4 additions & 1 deletion src/onErrorResumeNext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ export default function* onErrorResumeNext<TSource>(this: Iterable<TSource>, sec
yield* this;
} catch (error) {
}
yield* second;
try {
yield* second;
} catch (error) {
}
}
8 changes: 8 additions & 0 deletions src/static/onErrorResumeNext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function* onErrorResumeNext<TSource>(...sources: Iterable<TSource>[]) {
for (const source of sources) {
try {
yield* source;
} catch (error) {
}
}
}
8 changes: 7 additions & 1 deletion test/onErrorResumeNextTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ describe('onErrorResumeNext()', () => {
throw new Error()
}
};
const ys = [3, 4];
const ys = {
[Symbol.iterator]: function*() {
yield 3
yield 4
throw new Error()
}
};
assert.deepEqual(new Enumerable(xs).onErrorResumeNext(ys).toArray(), [1, 2, 3, 4]);
});
});
23 changes: 23 additions & 0 deletions test/static/onErrorResumeNext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as assert from 'assert';
import Enumerable from '../../src/';

describe('onErrorResumeNext()', () => {
it('should creates a sequence that concatenates both given sequences', () => {
const xs = {
[Symbol.iterator]: function*() {
yield 1;
yield 2;
throw new Error();
}
};
const ys = {
[Symbol.iterator]: function*() {
yield 3;
yield 4;
throw new Error();
}
};
assert.deepEqual(Enumerable.onErrorResumeNext(xs, ys).toArray(), [1, 2, 3, 4]);
});
});

0 comments on commit 428ebea

Please sign in to comment.