Skip to content

Commit

Permalink
feat: add some sink utils to contrib/most
Browse files Browse the repository at this point in the history
  • Loading branch information
baetheus committed Mar 17, 2024
1 parent fce9464 commit eae5565
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion contrib/most.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { $, Kind, Nest, Out } from "../kind.ts";
import type { Applicable } from "../applicable.ts";
import type { Bind, Flatmappable, Tap } from "../flatmappable.ts";
import type { BindTo, Mappable } from "../mappable.ts";
import type { Scheduler, Stream } from "npm:@most/types@1.1.0";
import type { Scheduler, Sink, Stream } from "npm:@most/types@1.1.0";
import type { Wrappable } from "../wrappable.ts";

import * as M from "npm:@most/core@1.6.1";
Expand Down Expand Up @@ -70,6 +70,23 @@ export async function collect<A>(
return as;
}

export function sink<A>(
event: (time: number, value: A) => void,
error: (e: unknown) => void,
end: () => void,
): Sink<A> {
return { event, end, error };
}

export const debugSink: Sink<unknown> = sink(
console.log,
console.error,
console.log,
);

const noop = () => {};
export const voidSink: Sink<unknown> = sink(noop, noop, noop);

export const wrap: Wrappable<KindStream>["wrap"] = M.now;

export const map: Mappable<KindStream>["map"] = M.map;
Expand Down

0 comments on commit eae5565

Please sign in to comment.