Star

Created With


startWith



First emit given values to sinks.

1linkfunction startWith<A, T>(...initial: A[]): (src: Source<T>) => Source<A | T>

1linkimport { interval, startWith, map, take, subscribe, pipe } from 'callbag-common';

2link

3linkpipe(

4link interval(1000),

5link map(i => 3 - i),

6link take(3),

7link startWith('Ready?'),

8link subscribe(console.log),

9link)

Ready? 3 2 1
► Try It!



👉 startWith() is useful for pre-populating streams that depend on some external event for their emissions. For example, your stream might be dependent on user clicking a button, but you would want it to have some initial value:

1linkpipe(

2link fromEvent(btn, 'click'),

3link scan(c => ++c, 0),

4link startWith(0), // --> without this, the message will only be displayed after first click

5link subscribe(c =>

6link res.textContent = `You have clicked ${c} times!`

7link )

8link)

► Try It!



Home What Are Callbags?

Source Factorieschevron_right
Operatorschevron_right
Combinationchevron_right
Utilitieschevron_right