简体   繁体   English

有没有更简洁的方法来处理F#中的双重可空类型?

[英]Is there a cleaner way to deal with double nullable types in F#?

I have these two lines: 我有这两行:

if not start.IsNone && not stop.IsNone then
    let times = TimeArray start.Value stop.Value interval

Is there a cleaner way to do this? 有更清洁的方法吗? if it's a single value, I can use match, but what about 2 values? 如果它是单个值,我可以使用匹配,但是2个值呢? (F# day 3 here..) (F#day 3 here ..)

You can still use pattern matching. 您仍然可以使用模式匹配。 Consider this quite meaningless example which can help you understand the overall pattern. 考虑这个毫无意义的例子,它可以帮助你理解整体模式。

let start = Some 1
let stop = Some 2    
let res =
    match start, stop with
    | Some _a, Some _b -> (_a,_b)
    | _, _ -> (0, 0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM