Search code examples
javascriptfrpbacon.js

continuously loop through values in an array using Baconjs


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


Solution

  • Bacon.repeatedly(2000, ['a', 'b', 'c'])
      .onValue(function(v) {
        console.log(v);
      });