When dealing with collections of Results it can in some cases be useful partition Ok cases from Error cases. For instance when doing something that can error partially during batch processing or similar I have found myself having to work with a Result<'A, 'B>[] where it would make a lot of sense to return a data structure indicating "Partial Success" and including the Ok cases and Error cases separately.
Therefore, I would find it very useful to have a partition function which also destructures the result types such that I can deal with both ok cases and error cases. I have solved this using this implementation which I thought might be nice to have in this project. The below implementation should of course be extended to other collections as well.
[<RequireQualifiedAccess>]
module Array =
let partitionResults (input: Result<'a,'b>[]) : 'a[] * 'b[] =
input |> Array.choose (function Ok v -> Some v | _ -> None),
input |> Array.choose (function Error e -> Some e | _ -> None)
Perhaps there is a smarter way of doing this, and if so, I would love to be enlightened.
When dealing with collections of Results it can in some cases be useful partition Ok cases from Error cases. For instance when doing something that can error partially during batch processing or similar I have found myself having to work with a
Result<'A, 'B>[]where it would make a lot of sense to return a data structure indicating "Partial Success" and including the Ok cases and Error cases separately.Therefore, I would find it very useful to have a partition function which also destructures the result types such that I can deal with both ok cases and error cases. I have solved this using this implementation which I thought might be nice to have in this project. The below implementation should of course be extended to other collections as well.
Perhaps there is a smarter way of doing this, and if so, I would love to be enlightened.