title: Getting every Friday until a certain date, but in a functional style?
body: <p>For example, I want to get the dates of every Friday from now until 30 days from now.</p>
  
  <p>Currently, I can make use of the underscore library and moment.js to do this. But the result is super verbose and annoyingly procedural/imperative. Observe:</p>
  
  <pre><code>var initDate = moment().day("Friday");
  var endDate = moment().add(30, 'days');
  
  var result = [];
  result.push(initDate);
  
  while (_.last(result).isBefore(endDate)) {
      var x = _.last(result);
      result.push(nextWeek(x));
  }
  
  alert(result);    // answer here
  
  // create a new moment from given moment and add 7 days
  function nextWeek(initMoment) {
      var x = moment(initMoment);
      return x.add(7,'days');    
  }
  </code></pre>
  
  <p>Here is the corresponding fiddle: <a href="http://jsfiddle.net/aafsh5xa/" rel="nofollow">http://jsfiddle.net/aafsh5xa/</a></p>
  
  <p>I was wondering if there's a way to use Haskell-like features such as list comprehensions or infinite lists (lazy evaluation) to make this a lot more concise. Maybe something like:</p>
  
  <pre><code>var initDate = moment();
  var endDate = moment().add(30,days);
  
  var everyFriday = genLazyList(initDate, nextFridayFrom);
  var result = _.filter(everyFriday, function(input){ return input.isBefore(endDate); });
  </code></pre>
  
  <p>Note that everyFriday is an infinite list generated by genLazyList and is not evaluated until the _.filter() function is called upon it. And nextFridayFrom() is a function that genLazyList uses to make the lazy list.</p>