wonka
Version:
A fast push & pull stream library for Reason, loosely following the [callbag spec](https://github.com/callbag/callbag)
34 lines (28 loc) • 1.06 kB
JavaScript
import * as Wonka_helpers from "../wonka_helpers.js";
function takeLast(max) {
return (function (source) {
return (function (sink) {
var queue = new Array();
return Wonka_helpers.captureTalkback(source, (function (signal, talkback) {
if (typeof signal === "number") {
return Wonka_helpers.makeTrampoline(sink, (function () {
return queue.shift();
}));
} else if (signal.tag) {
var size = queue.length;
if (size >= max && max > 0) {
queue.shift();
}
queue.push(signal[0]);
return talkback(/* Pull */0);
} else {
return talkback(/* Pull */0);
}
}));
});
});
}
export {
takeLast ,
}
/* No side effect */