Enhanced C#
Language of your choice: library documentation
Public fields | Properties | Public Member Functions | List of all members
Loyc.Collections.SelectDictionaryFromKeys< K, V > Class Template Reference

An adapter that converts a collection of keys to an IReadOnlyDictionary. Used by EnumerableExt.AsReadOnlyDictionarybased on a function that can obtain a value for a given key. More...


Source file:
Inheritance diagram for Loyc.Collections.SelectDictionaryFromKeys< K, V >:

Remarks

An adapter that converts a collection of keys to an IReadOnlyDictionary. Used by EnumerableExt.AsReadOnlyDictionarybased on a function that can obtain a value for a given key.

Template Parameters
KKey type
VValue type

Public fields

IEnumerable< K > Keys => _keys
 
IEnumerable< V > Values
 
int Count => _keys.Count
 

Properties

this[K key] [get]
 

Public Member Functions

 SelectDictionaryFromKeys (IReadOnlyCollection< K > keys, Func< K, Maybe< V >> tryGetValue, Func< K, V > getValue=null)
 Initializes the adapter. More...
 
bool ContainsKey (K key)
 
IEnumerator< KeyValuePair< K, V > > GetEnumerator ()
 
bool TryGetValue (K key, out V value)
 

Constructor & Destructor Documentation

◆ SelectDictionaryFromKeys()

Loyc.Collections.SelectDictionaryFromKeys< K, V >.SelectDictionaryFromKeys ( IReadOnlyCollection< K >  keys,
Func< K, Maybe< V >>  tryGetValue,
Func< K, V >  getValue = null 
)
inline

Initializes the adapter.

Parameters
keysA collection of dictionary keys.
tryGetValueThis function is used both to test membership and to get values.
getValueThis function is optional. It is used to get values when it is known in advance that the key exists (in GetEnumerator() and in the Values property). If this is null, tryGetValue is used instead. Providing this function can increase performance.

Member Data Documentation

◆ Values

IEnumerable<V> Loyc.Collections.SelectDictionaryFromKeys< K, V >.Values
Initial value:
=> _getValue != null
? _keys.Select(k => _getValue(k))
: _keys.Select(k => _tryGetValue(k).Or(default(V)))