Skip to content

Commit

Permalink
Small bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottArbeit committed Dec 2, 2023
1 parent 31768a3 commit a36c037
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Grace.Shared/Validation/Utilities.Validation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ module Utilities =
/// Returns the first validation that matches the predicate, or None if none match.
let tryFind<'T> (predicate: 'T -> bool) (validations : ValueTask<'T> array) =
task {
return validations
|> Seq.map (fun validation -> validation.Result)
|> Seq.tryFind predicate
match validations |> Seq.tryFindIndex (fun validation -> predicate validation.Result) with
| Some index -> return Some (validations[index].Result)
| None -> return None
}

/// Retrieves the first error from a list of validations.
let getFirstError (validations: ValueTask<Result<'T, 'TError>> array) =
task {
let! firstError = validations |> tryFind(fun validation -> Result.isError validation)
return match firstError with
| Some result -> match result with | Ok _ -> None | Error error -> Some error // This line can't return None, because we'll always have an error if we get here.
| Some result -> match result with | Ok _ -> None | Error error -> Some error // This line can't actually return None, because we'll always have an error if we get here.
| None -> None
}

Expand Down

0 comments on commit a36c037

Please sign in to comment.