Skip to main content

Date_Range.fold

foldinitfunction

Documentation

Combines all the elements of the range, by iteratively applying the passed function with next elements of the range.

Arguments

  • init: The initial value for the fold.
  • function: A binary function taking an item and a date, and returning an item.

Examples

In the following example, we'll compute how many days in the range are

a Monday.

      (Date.new 2020 10 01).up_to (Date.new 2020 10 31) . fold 0 acc-> date->
if date.day_of_week == Day_Of_Week.Monday then acc+1 else acc