diff --git a/src/core/CCList.ml b/src/core/CCList.ml index 857512ce..80b8578f 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -792,6 +792,32 @@ module Idx = struct *) end +let range_by ~step i j = + let rec range i j acc = + if i=j then i::acc else range i (j-step) (j::acc) + in + if step = 0 then + raise (Invalid_argument "CCList.range_by") + else if (if step > 0 then i>j else i int -> int -> int t +(** [range_by ~step i j] iterates on integers from [i] to [j] included, + where the difference between successive elements is [step]. + use a negative [step] for a decreasing list. + @raise Invalid_argument if [step=0] + @since NEXT_RELEASE *) + val range : int -> int -> int t (** [range i j] iterates on integers from [i] to [j] included . It works both for decreasing and increasing ranges *)