traverseResult
Option.traverseResult
Namespace: FsToolkit.ErrorHandling
Function Signature:
Note that traverse
is the same as map >> sequence
. See also Option.sequenceResult.
See also Scott Wlaschin's Understanding traverse and sequence.
Examples
Example 1
If we have a value of type string option
and want to call the tryParseInt
function that we defined in the Result.map2 example, we can achieve it using the traverseResult
function as below:
Example 2
The CreatePostRequest
type that we defined in Result.map3 example contains a Location option
. The corresponding DTO objects would look like this:
Let's assume that we have this function to convert a LocationDto
to a Location
:
Then in order to create a similar function to convert a CreatePostRequestDto
to a CreatePostRequest
, we can make use of traverseResult
as below:
See also the example 2 of ResultOption.map2.
Last updated