I'm currently generating a sequence in a similar way to:
migrators
|> Seq.map (fun m -> m())
The migrator
function is ultimately returning a discriminated union like:
type MigratorResult =
| Success of string * TimeSpan
| Error of string * Exception
I want to stop the map
once I encounter my first Error
but I need to include the Error
in the final sequence.
I have something like the following to display a final message to the user
match results |> List.rev with
| [] -> "No results equals no migrators"
| head :: _ ->
match head with
| Success (dt, t) -> "All migrators succeeded"
| Error (dt, ex) -> "Migration halted owing to error"
So I need:
- A way to stop the mapping when one of the map steps produces an
Error
- A way to have that error be the final element added to the sequence
I appreciate there may be a different sequence method other than map
that will do this, I'm new to F# and searching online hasn't yielded anything as yet!