Last active
April 24, 2017 12:45
-
-
Save mattpodwysocki/a227f49cb72242b063888bac526a68a7 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
export function* buffer<TSource>( | |
source: Iterable<TSource>, | |
count: number, | |
skip?: number): Iterable<TSource[]> { | |
if (skip == null) { skip = count; } | |
let buffers: TSource[][] = [], i = 0; | |
for (let item of source) | |
{ | |
if (i % skip === 0) { | |
buffers.push([]); | |
} | |
for (let buffer of buffers) { | |
buffer.push(item); | |
} | |
if (buffers.length > 0 && buffers[0].length === count) { | |
yield buffers.shift()!; | |
} | |
i++; | |
} | |
while (buffers.length > 0) { | |
yield buffers.shift()!; | |
} | |
} |
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
'use strict'; | |
import { bindCallback } from '../internal/bindcallback'; | |
export function* filter<T>( | |
source: Iterable<T>, | |
predicate: (value: T, index: number) => boolean, | |
thisArg?: any): Iterable<T> { | |
let fn = bindCallback(predicate, thisArg, 2), i = 0; | |
for (let item of source) { | |
if (fn(item, i++)) { | |
yield item; | |
} | |
} | |
} |
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
'use strict'; | |
export function* _finally<TSource>( | |
source: Iterable<TSource>, | |
action: () => void) { | |
try { | |
for (let item of source) { | |
yield item; | |
} | |
} finally { | |
action(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
I mentioned some time ago about https://github.com/marcinnajder/powerseq (ReactiveX/IxJS#1) This is a complete implementation of all IxJS in RxJS5 style. Maybe it will be useful.
Marcin