2 ms·
> let value = match dict.TryGetValue("foo") with > | (true,val) -> val > | (false,_) -> "default" groan let value = findWithDefault "d
by masklinn 16y ago
> let value = match dict.TryGetValue("foo") with
> | (true,val) -> val
> | (false,_) -> "default"
groan
let value = findWithDefault "default" "foo" dict
or
case M.lookup key dict of
Just v -> v
Nothing -> "default"
(and for anybody who wants to whine about parameters order, please remember — or discover — that partial application is extremely frequent in Haskell and MLs, and try to read the parameters order in this light, you will be enlightened)
- timrobinson 16y agodict.TryGetValue is an odd example here -- idiomatic F# for a map lookup would be: let value = defaultArg (Map.tryFind "foo" dict) "default" or match Map.tryFind "foo" dict with | Some v -> v | None -> "default"
- masklinn 16y ago> dict.TryGetValue is an odd example here I sure as hell hope so, but that's what fleitz used.