let rec foldi xs ~init ~f = match next xs with | None -> init | Some x -> foldi xs ~init:(f (count xs - 1) init x) ~f