let rec fold f accum s =
    match peek s with
      None -> accum
    | Some a -> (junk s; fold f (f accum a) s)