Star

Created With


source



When passed argument is not a callbag, source() turns it into a callbag using of(). Otherwise it will return the same callbag.

1linktype MaybeSource<T> = T | Source<T>;

2linkfunction source<T>(maybe: MaybeSource<T>): Source<T>;

1link​import { MaybeSource, source, pipe, map, interval, subscribe } from 'callbag-common'

2link​

3link​function multiplyBy2(n: MaybeSource<number>) {

4link​ return pipe(source(n), map(x => x * 2))

5link​}

6link​

7link​pipe(

8link​ multiplyBy2(42), // --> can accept numbers

9link​ subscribe(console.log)

10link​)

11link​

84
12link​

13link​pipe(

14link​ interval(1000),

15link​ multiplyBy2, // --> can be piped as it accepts callbags as well

16link​ subscribe(console.log)

17link​)

18link​

0 2 4 6 ...
► Try It!

👉 Use source() when your functions want to handle arguments that might be a callbag source or might be a plain value.




Home What Are Callbags?

Source Factorieschevron_right
Operatorschevron_right
Combinationchevron_right
Utilitieschevron_right