-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(endWith): adds endWith operator
- Loading branch information
1 parent
740d401
commit f967e3b
Showing
8 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as Ix from '../Ix'; | ||
import * as test from 'tape'; | ||
const { range } = Ix.asynciterable; | ||
const { sequenceEqual } = Ix.asynciterable; | ||
const { endWith } = Ix.asynciterable; | ||
|
||
test('AsyncIterable#endWith adds to end', async t => { | ||
const e = range(0, 5); | ||
const r = endWith(e, 6, 7); | ||
t.true(await sequenceEqual(r, range(0, 7))); | ||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as Ix from '../Ix'; | ||
import * as test from 'tape'; | ||
const { range } = Ix.iterable; | ||
const { sequenceEqual } = Ix.iterable; | ||
const { endWith } = Ix.iterable; | ||
|
||
test('Iterable#endWith adds to end', t => { | ||
const e = range(0, 5); | ||
const r = endWith(e, 6, 7); | ||
t.true(sequenceEqual(r, range(0, 7))); | ||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { AsyncIterableX } from '../../asynciterable'; | ||
import { endWith } from '../../asynciterable/endwith'; | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
export function endWithProto<T>( | ||
this: AsyncIterableX<T>, | ||
...args: T[]) { | ||
return endWith(this, ...args); | ||
} | ||
|
||
AsyncIterableX.prototype.endWith = endWithProto; | ||
|
||
declare module '../../asynciterable' { | ||
interface AsyncIterableX<T> { | ||
endWith: typeof endWithProto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { IterableX } from '../../iterable'; | ||
import { endWith } from '../../iterable/endwith'; | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
export function endWithProto<T>( | ||
this: IterableX<T>, | ||
...args: T[]) { | ||
return endWith(this, ...args); | ||
} | ||
|
||
IterableX.prototype.endWith = endWithProto; | ||
|
||
declare module '../../iterable' { | ||
interface IterableX<T> { | ||
endWith: typeof endWithProto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { AsyncIterableX } from '../asynciterable'; | ||
|
||
class EndWithAsyncIterable<TSource> extends AsyncIterableX<TSource> { | ||
private _source: AsyncIterable<TSource>; | ||
private _args: TSource[]; | ||
|
||
constructor(source: AsyncIterable<TSource>, args: TSource[]) { | ||
super(); | ||
this._source = source; | ||
this._args = args; | ||
} | ||
|
||
async *[Symbol.asyncIterator]() { | ||
for await (let item of this._source) { yield item; } | ||
for (let x of this._args) { yield x; } | ||
} | ||
} | ||
|
||
export function endWith<TSource>( | ||
source: AsyncIterable<TSource>, | ||
...args: TSource[]): AsyncIterableX<TSource> { | ||
return new EndWithAsyncIterable<TSource>(source, args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { IterableX } from '../iterable'; | ||
|
||
class EndWithIterable<TSource> extends IterableX<TSource> { | ||
private _source: Iterable<TSource>; | ||
private _args: TSource[]; | ||
|
||
constructor(source: Iterable<TSource>, args: TSource[]) { | ||
super(); | ||
this._source = source; | ||
this._args = args; | ||
} | ||
|
||
*[Symbol.iterator]() { | ||
for (let item of this._source) { yield item; } | ||
for (let x of this._args) { yield x; } | ||
} | ||
} | ||
|
||
export function endWith<TSource>( | ||
source: Iterable<TSource>, | ||
...args: TSource[]): IterableX<TSource> { | ||
return new EndWithIterable<TSource>(source, args); | ||
} |