Bacon.js

Created on 2021-02-15T14:38:38-06:00

Return to the Index

This card pertains to a resource available on the internet.

This card can also be read via Gemini.

Event sources

Bus: can push values to it

Poll: polls something in the background and pushes values when they come in

Promise: waits for a promise to resolve, pushes result when ready

Callback: pushes events when a callback is called

Once: emits an event and dies

Later: waits some time and emits an event

Interval: emit the same event over time

From Array: dump an arrays contents to a stream

Sequentially: dump each element of an array with a delay between elements

Repeatedly: Sequentially, but start from the beginning when you run out of elements

Repeat: calls a generator to produce an event

Never: die immediately

Silence: wait a while, then die

Stream kernels

Buffer with count: tumbled window that fills up with count items; flushes to output

Buffer with time: tumbled window that fills up until time has passed; flushes to output

Buffer with time or count: tumbled window that fills up until count items or time has passed; flushes to output

Buffering throttle: accumulates items, pushes one item per interval

Changes: pushes events when they are different than the last event that was sent

Combine: zip two streams; runs a function on both inputs and pushes the result of the function downward

Concat: when the first stream dies, all further values from the next stream.

Debounce: keep only the most recent element, flush after an interval of silence

Debounce immediate: push first element, then debounce until silence, resets after flushing

Delay: holds on to elements for an interval, then pushes them

Diff: pushes events which are the difference between the last element seen and the latest event

Do action: runs a function for every event, but pushes the original event

End on error: die when an error punctuation is seen

Errors: return only error punctuation

Filter: only allow values through which a function approves

First: return the first event and die

Flat *: map/concat/etc but they receive arrays of events, and flatten them to individual events

Fold: starts with a seed, applies a function to the seed and incoming element, saves the seed; flushes when incoming streams die

Group By/Partition: stores incoming events in to separate buckets by some key, events from bucket are flushed on punctuation

Hold when: divert events to buffer when event is truthy, flushes when value is falsy.

Last: keeps only the most recent event; flushes when stream dies

Map: applies a function to each event, pushes value returned by function

Map end: when incoming stream dies, return result of a function before dying

Merge: deliver events from two incoming streams

On error, value, end, etc: adds notifier when something of a given type crosses the stream; returns function to revoke subscription

Reduce/Scan: holds seed, runs function againt seed and incoming value, updates and pushes seed

Sampled by: when stream receives event, take the latest event from the underlying stream/property and push it

Skip: ignore the first count of events

Skip duplicates: ignore events if they are the same as the most recently pushed event

Skip errors: ignore error punctuations

Skip until: skip values until an event equal to the supplied event is encountered

Skip while: skip values until a function is false for the first time

Sliding window: push sliding windows of events

Take: pass through count events then die

Take until: pass events and die when an event goes across another stream

Take while: pass events through and die when a predicate fails

Throttle: emit an event and then drop events until after an interval; basically Debounce but swaps which end of the event spam goes through