s.GetValueAsElement(0) |> Option.ofObj)
|> Option.map (function Some v -> v.GetElement("fieldData") |> Option.ofObj |_ -> None)
|> Option.map (function Some f -> Some (f.GetElementAsFloat64("PX_CLOSE_1D")) |_ -> None)
|> Option.defaultValue None
Епта
Зачем None ?
Половину мапов на бинд можно поменять - сразу проще станет
type optionBuilder() = member __.Bind(opt, f) = Option.bind f opt member __.Bind(obj, f) = Option.bind f (Option.ofObj obj) member __.Bind(obj, f) = Option.bind f (Option.ofNullable obj) member __.Return x = Some x member __.ReturnFrom x = x let option = optionBuilder() option { let! s = msg.AsElement.GetElement "securityData" let! v = s.GetValueAsElement 0 let! f = v.GetElement "fieldData" return f.GetElementAsFloat64 "PX_CLOSE_1D" }
Обсуждают сегодня