I'm currently working on a project which requires ingesting, normalizing, processing, and maximizing some data. I expected to be able to write a simple pipeline like
fn process(input) -> Result<FinalAnswer, ErrorType> {
Ok(ingest(input)?.into_iter().map(normalize)?.map(process)?.fold(maximize))
}
(obviously, this is pseudocode). In reality, because each of ingest, normalize, and process can fail and thus return a Result
, I had to .collect()
each one to flatten the output before I could use the ?
operator (or any other early return method).
As reproduced in the playground, this is very ugly and introduces multible extra Vec
s that I don't want.
What is the idiomatic, non-allocating way to do this, if there is one?