let reduce xs ~f = match next xs with | Some init -> fold xs ~init ~f | None -> invalid_arg "Stream.reduce: stream should contain at least one element"