import { Subscription, StreamOps } from './index' declare module '.' { interface S_ { 'ArrayStream': Array } } declare module '../fantasy/typeclasses' { interface _ { 'ArrayStream': Array } } StreamOps.prototype.empty = function() { return [] } StreamOps.prototype.just = function(a) { return [a] } StreamOps.prototype.scan = function(f, base, fa) { return fa.scan(f, base) } StreamOps.prototype.combine = function ( f: (...a: any[]) => C, ...v: any[] ): Array { return f.apply(null, v) } StreamOps.prototype.filter = function (f: (a: A) => boolean, fa: Array): Array { return fa.filter(f) } StreamOps.prototype.map = function (f: (a: A) => B, fa: Array): Array { return fa.map(f) } StreamOps.prototype.flatMap = function (f: (a: A) => Array, fa: Array): Array { return fa.reduce((acc, a) => acc.concat(f(a)), [] as B[]) } function Subject() { } Subject.prototype = Array.prototype Subject.prototype.next = function(a: any) { this.push(a) } Subject.prototype.complete = function() { } StreamOps.prototype.subject = function () { return new (Subject)() } StreamOps.prototype.subscribe = function (fa: Array, next: (v: A) => void, complete?: () => void) { throw Error("you don't need to subscribe a Array, just iterate it") } StreamOps.prototype.merge = function (a: Array, b: Array): Array { return (a).concat(b) } StreamOps.prototype.fromPromise = function(p) { if (p.then) { throw Error("You're not using real Promise aren't you, expecting Id Monad") } return [p.valueOf()] } StreamOps.prototype.from = function(fa) { return [fa.valueOf()] }