Is there a `cycle` function in ReasonML


#1

I try to do the Advent of Code challenges in different languages.
Already with Day 1 part 2 I have some problems with ReasonML.

The challenge asks to repeat multiple times over a list of numbers until a specific result is found.
I looked at the solutions of different languages and I saw some functions to make the iteration over the list possible.

In Clojure there is a cycle function.
In Elixir there is also a Stream.cycle function.
In F# I could implement my own cycle function with the help of lazy sequences.

Is there a similar function available in ReasonML?

I now that an implementation of this function is probably only possible with some kind of a “lazy” list.

There is another question that I have:
I know about the existence of the Belt library. But I did not find in it if there is an implementation of a lazy list and/or sequence type in there…


#2

You can see one solution here without use lazy list


#3

For lazy list I just find this link

Example of custom implementation of lazy list with ocaml lazy:

type t('a) = Lazy.t(node('a))
and node('a) =
  | Nil
  | Cons('a, t('a));

let rec toInfinity = n => Cons(n, lazy (toInfinity(n + 1)));
let rec printN = (n, list) =>
  n <= 0 ?
    () :
    (
      switch (list) {
      | lazy Nil => Js.log("[]")
      | lazy (Cons(a, list)) =>
        Js.log(a);
        printN(n - 1, list);
      }
    );

let i = lazy toInfinity(10);

printN(50, i);