<commit_before>h2#create-stream Create a stream





+descr-method('never', 'never', 'Kefir.never()').
  Creates a stream that already ended and will never produce any events.

pre.javascript(title='example').
  var stream = Kefir.never();
  stream.log();

pre(title='console output')
  :escapehtml
    > [never] <end:current>

pre(title='events in time').
  stream:  X
div




+descr-method('later', 'later', 'Kefir.later(wait, value)').
  Creates a stream that produces a single #[b value]
  after #[b wait] milliseconds, then ends.

pre.javascript(title='example').
  var stream = Kefir.later(1000, 1);
  stream.log();

pre(title='console output (after 1 second)')
  :escapehtml
    > [later] <value> 1
    > [later] <end>

pre(title='events in time').
  stream:  ----1X
div




+descr-method('interval', 'interval', 'Kefir.interval(interval, value)').
  Creates a stream that produces the same #[b value]
  each #[b interval] milliseconds. Never ends.

pre.javascript(title='example').
  var stream = Kefir.interval(1000, 1);
  stream.log();

pre(title='console output')
  :escapehtml
    > [interval] <value> 1
    > [interval] <value> 1
    > [interval] <value> 1
    ...

pre(title='events in time').
  stream:  ----1----1----1----1---
div


+descr-method('sequentially', 'sequentially', 'Kefir.sequentially(interval, values)').
  Creates a stream containing the given #[b values] (array),
  delivered with the given #[b interval] in milliseconds.
  Ends after all #[b values] are delivered.

pre.javascript(title='example').
  var stream = Kefir.sequentially(1000, [1, 2, 3]);
  stream.log();

pre(title='console output')
  :escapehtml
    > [sequentially] <value> 1
    > [sequentially] <value> 2
    > [sequentially] <value> 3
    > [sequentially] <end>

pre(title='events in time').
  stream:  ----1----2----3X
div



+descr-method('from-poll', 'fromPoll', 'Kefir.fromPoll(interval, fn)').
  Creates a stream that polls the given #[b fn] function,
  with the given #[b interval] in milliseconds,
  and emits the values returned by #[b fn].
  Never ends.

pre.javascript(title='example').
  var start = new Date();
  var stream = Kefir.fromPoll(1000, function(){ return new Date() - start });
  stream.log();

pre(title='console output')
  :escapehtml
    > [fromPoll] <value> 1001
    > [fromPoll] <value> 2002
    > [fromPoll] <value> 3004
    > [fromPoll] <value> 4006
    > [fromPoll] <value> 5007
    > [fromPoll] <value> 6007
    ...

pre(title='events in time').
  stream:  ----•----•----•----•---
            1001 2002 3004 4006
div


+descr-method('with-interval', 'withInterval', 'Kefir.withInterval(interval, handler)').
  General method to create an interval based stream.
  Creates a stream that calls the given #[b handler] function,
  with the given #[b interval] in milliseconds.
  The #[b handler] function is called with one argument —
  an #[a(href="#emitter-object") emitter].

pre.javascript(title='example')
  :escapehtml
    var start = new Date();
    var stream = Kefir.withInterval(1000, function(emitter) {
      var time = new Date() - start;
      if (time < 4000) {
        emitter.emit(time);   // emit a value
      } else {
        emitter.end();        // end the stream
      }
    });
    stream.log();

pre(title='console output')
  :escapehtml
    > [withInterval] <value> 1002
    > [withInterval] <value> 2003
    > [withInterval] <value> 3005
    > [withInterval] <end>

pre(title='events in time').
  stream:  ----•----•----•----X
            1002 2003 3005
div

p.
  You may call #[b emitter] methods several times on each interval tick,
  or not call them at all.



+descr-method('from-callback', 'fromCallback', 'Kefir.fromCallback(fn)').
  Convert a function than accepts a #[b callback]
  as the first argument to a stream.
  Emits at most one value when #[b callback] is called, then ends.
  The #[b fn] function will be called at most once,
  when the first subscriber will be added to the stream.
<commit_msg>Fix typo<commit_after>h2#create-stream Create a stream





+descr-method('never', 'never', 'Kefir.never()').
  Creates a stream that already ended and will never produce any events.

pre.javascript(title='example').
  var stream = Kefir.never();
  stream.log();

pre(title='console output')
  :escapehtml
    > [never] <end:current>

pre(title='events in time').
  stream:  X
div




+descr-method('later', 'later', 'Kefir.later(wait, value)').
  Creates a stream that produces a single #[b value]
  after #[b wait] milliseconds, then ends.

pre.javascript(title='example').
  var stream = Kefir.later(1000, 1);
  stream.log();

pre(title='console output (after 1 second)')
  :escapehtml
    > [later] <value> 1
    > [later] <end>

pre(title='events in time').
  stream:  ----1X
div




+descr-method('interval', 'interval', 'Kefir.interval(interval, value)').
  Creates a stream that produces the same #[b value]
  each #[b interval] milliseconds. Never ends.

pre.javascript(title='example').
  var stream = Kefir.interval(1000, 1);
  stream.log();

pre(title='console output')
  :escapehtml
    > [interval] <value> 1
    > [interval] <value> 1
    > [interval] <value> 1
    ...

pre(title='events in time').
  stream:  ----1----1----1----1---
div


+descr-method('sequentially', 'sequentially', 'Kefir.sequentially(interval, values)').
  Creates a stream containing the given #[b values] (array),
  delivered with the given #[b interval] in milliseconds.
  Ends after all #[b values] are delivered.

pre.javascript(title='example').
  var stream = Kefir.sequentially(1000, [1, 2, 3]);
  stream.log();

pre(title='console output')
  :escapehtml
    > [sequentially] <value> 1
    > [sequentially] <value> 2
    > [sequentially] <value> 3
    > [sequentially] <end>

pre(title='events in time').
  stream:  ----1----2----3X
div



+descr-method('from-poll', 'fromPoll', 'Kefir.fromPoll(interval, fn)').
  Creates a stream that polls the given #[b fn] function,
  with the given #[b interval] in milliseconds,
  and emits the values returned by #[b fn].
  Never ends.

pre.javascript(title='example').
  var start = new Date();
  var stream = Kefir.fromPoll(1000, function(){ return new Date() - start });
  stream.log();

pre(title='console output')
  :escapehtml
    > [fromPoll] <value> 1001
    > [fromPoll] <value> 2002
    > [fromPoll] <value> 3004
    > [fromPoll] <value> 4006
    > [fromPoll] <value> 5007
    > [fromPoll] <value> 6007
    ...

pre(title='events in time').
  stream:  ----•----•----•----•---
            1001 2002 3004 4006
div


+descr-method('with-interval', 'withInterval', 'Kefir.withInterval(interval, handler)').
  General method to create an interval based stream.
  Creates a stream that calls the given #[b handler] function,
  with the given #[b interval] in milliseconds.
  The #[b handler] function is called with one argument —
  an #[a(href="#emitter-object") emitter].

pre.javascript(title='example')
  :escapehtml
    var start = new Date();
    var stream = Kefir.withInterval(1000, function(emitter) {
      var time = new Date() - start;
      if (time < 4000) {
        emitter.emit(time);   // emit a value
      } else {
        emitter.end();        // end the stream
      }
    });
    stream.log();

pre(title='console output')
  :escapehtml
    > [withInterval] <value> 1002
    > [withInterval] <value> 2003
    > [withInterval] <value> 3005
    > [withInterval] <end>

pre(title='events in time').
  stream:  ----•----•----•----X
            1002 2003 3005
div

p.
  You may call #[b emitter] methods several times on each interval tick,
  or not call them at all.



+descr-method('from-callback', 'fromCallback', 'Kefir.fromCallback(fn)').
  Convert a function that accepts a #[b callback]
  as the first argument to a stream.
  Emits at most one value when #[b callback] is called, then ends.
  The #[b fn] function will be called at most once,
  when the first subscriber will be added to the stream.

{'fraction_non_alphanumeric': 0.1575299306868305, 'fraction_numerical': 0.027725267800882167, 'mean_word_length': 3.2483940042826553, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '106145', 'n_tokens_mistral': 2779, 'n_tokens_neox': 2592, 'n_words': 829}