Hello all!
I have been stuck with this function “validateOrder” for a while ". This portion of code is from the “Domain Driven Design made functional (Scott Wlaschin)”.
I tried to post my issue on Prag Prog “The website where I got the book from”; but it looks like some legislation in the USA has caused them to make the forum unavailable.
Bellow is the piece of code that seems not to be working:
let validateOrder : ValidateOrder =
fun checkProductCodeExists checkAddressExists unvalidatedOrder ->
printfn "IN validate order unvalidatedOrder = %A" unvalidatedOrder
printfn "IN validate order unvalidatedOrder.OrderId = %A" unvalidatedOrder.OrderId
asyncResult {
//printfn "IN validate order customerInfo = %A" customerInfo
let! orderId =
unvalidatedOrder.OrderId
|> toOrderId
|> AsyncResult.ofResult
printfn "orderId = %A" orderId
let! customerInfo =
let unvalidateCustomerInfo = unvalidatedOrder.CustomerInfo
unvalidateCustomerInfo
|> toCustomerInfo
|> AsyncResult.ofResult
let! checkedShippingAddress =
let unvalidateShippingAddress = unvalidatedOrder.ShippingAddress
unvalidatedOrder.ShippingAddress
|> toCheckedAddress checkAddressExists
let! shippingAddress =
checkedShippingAddress
|> toAddress
|> AsyncResult.ofResult
let! checkedBillingAddress =
unvalidatedOrder.BillingAddress
|> toCheckedAddress checkAddressExists
let! billingAddress =
checkedBillingAddress
|> toAddress
|> AsyncResult.ofResult
let! lines =
unvalidatedOrder.Lines
|> List.map (toValidatedOrderLine checkProductCodeExists)
|> Result.sequence // convert list of Results to a single Result
|> AsyncResult.ofResult
let validatedOrder : ValidatedOrder = {
OrderId = orderId
CustomerInfo = customerInfo
ShippingAddress = shippingAddress
BillingAddress = billingAddress
Lines = lines
}
return validatedOrder
}
This instruction
let! orderId =
unvalidatedOrder.OrderId
|> toOrderId
|> AsyncResult.ofResult
runs the unvalidatedOrder.OrderId
|> toOrderId …
function with no problem then it gets stuck at
|> AsyncResult.ofResult.
I would appreciate if you could help me figure out what the issue is with
AsyncResult.ofResult as I feel like it is there that everything is stuck. I am available to porvide more details in case it’s needed