"-- tuple --".println
(
  (1, 2, 3, 4),
  n -> n.print
).for_each
"".println

// shorter: we just pass the `print` function directly
(
  (1, 2, 3, 4),
  print
).for_each
"".println

"-- list --".println
(
  (1, 2, 3, 4).as_list,
  print
).for_each
"".println

"-- custom iterator --".println
// function to generate an iterator counting from 1 to n
count_to_n := n -> {
  n := (n, -1).product
  i := 0
  () -> if ((i, n).sum.signum, -1).eq {
    &i = (i, 1).sum
    (i)
  } else {
    ()
  }
}
// 1 to 6
(
  6.count_to_n,
  print
).for_each
"".println
// 1 to 9
(
  9.count_to_n,
  print
).for_each
"".println
"".println

// 1 to 1, 1 to 2, ..., 1 to 9
(
  9.count_to_n,
  max -> {
    (
      max.count_to_n,
      print
    ).for_each
    "".println
  }
).for_each
"".println

"-- ranges --"

range := (min, max, inc) -> {
  if (inc, 0).eq {
    // convert 1 to inc's type (int or float)
    &inc = (inc, 1).sum
  }
  val := min
  () -> {
    // -1 if val > max, 1 if max > val, 0 if max = val
    should_inc := ((val, max).diff.signum, inc.signum).eq
    if should_inc {
      v := val
      &val = (val, inc).sum
      (v)
    }
  }
}

"range 5..11 +2".println
(
  (5, 11, 2).range,
  println
).for_each


"range -1.2..8 +2.7".println
(
  (-1.2, 8.0, 2.7).range,
  println
).for_each
"nice".println
