'avoiding nesting `Result<'T,'TError>`

Suppose we have this input:

let input =
    [
        "0.10"
        "0.21"
        "forty"
        "5.32"
        "q6.20"
    ]

Mapping this input to F# results leads to Result<'T,'TError> list:

open System

let output =
    input
    |> List.map (
        fun s ->
            match Decimal.TryParse s with
            | true, i -> Ok i
            | _ -> Error $"failed to parse `{s}`"
        )

output |> printf "%A"
[Ok 0.10M; Ok 0.21M; Error "failed to parse `forty`"; Ok 5.32M;
 Error "failed to parse `q6.20`"]

Is this is a generally accepted way to collect results?

Or, is there a concern for scalability and performance such that only one aggregate Result is returned for the entire list? Something like Result<'T,'TError list>? Would FsToolkit.ErrorHandling [GitHub] be available for this or am I missing a pattern baked into the language?

Would this solution handle lists of lists to avoid returning Result<Result<'T,'TError> list>, 'TError>?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source