Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# TryGetValue, can't access the value?

Tags:

f#

I am using TryGetValue on a Dictionary in F# and it returns an object bool * Dictionary<int, object>

I have been googling for hours but how do I access the bool component of this object so I can check if it has returned a value?

Please save me from going postal...

like image 344
Oliver Giess Avatar asked Apr 17 '16 05:04

Oliver Giess


People also ask

What is Mtouch Facebook?

Facebook Touch is an advanced Facebook app that has many distinct features. H5 apps developed it as an app made especially for touchscreen phones. Available and applicable across all smartphones, Facebook Touch offers a fine user interface and serves as an alternative to the typical Facebook App.


1 Answers

There are a few options.

The simplest is probably:

let found, value = dict.TryGetValue key

Alternatively:

let pair = dict.TryGetValue key
let found = fst pair
let value = snd pair

The most common pattern is this:

match dict.TryGetValue key with
  | true, value -> (* do something with value *)
  | _           -> (* handle the case of value not found *)
like image 166
Foole Avatar answered Oct 18 '22 02:10

Foole