0

I have an array of strings var strs = ['a','b','c'] and I want to use a Bacon.interval(2000) to return the values continuously to onValue

The closest thing I can think of to create this is

var stream = Bacon.interval(2000);
var i = 0;
stream.onValue(function (v) {
    if (i >= strs.length) i=0;
    else i ++;
    strs[i];
})

not a very reactive solution, I am aware

andykais
  • 996
  • 2
  • 10
  • 27

1 Answers1

0
Bacon.repeatedly(2000, ['a', 'b', 'c'])
  .onValue(function(v) {
    console.log(v);
  });
Macil
  • 3,575
  • 1
  • 20
  • 18
  • 2
    OP probably wants [`Bacon.repeatedly`](https://github.com/baconjs/bacon.js/#bacon-repeatedly) rather than sequentially – Paul S. Sep 06 '15 at 20:15
  • thanks! quick follow up, is there also a subscriber for it to immediately output the first item instead of after the first 2 seconds? – andykais Sep 08 '15 at 23:56
  • You could use `Bacon.repeatedly(2000, ['b', 'c']).toProperty('a')` which should give that behavior. – Macil Sep 09 '15 at 19:35