let map f s =
    let f _ =
      try Some (f (next s))
      with Failure -> None
    in from f