Map ( [key, value] ) - HiStructClient/femcad-doc GitHub Wiki
Map is intended for fast searching of object using predefined keys.
The Fcs.Types.ObjectMap has 4 constructors with these parameters:
public ObjectMap(IEnumerable sourceArray, ICallableType elementToKeyFn, ICallableType elementToValueFn, bool allowDupliacteLastWins)
public ObjectMap(IEnumerable sourceArray, ICallableType elementToKeyFn, ICallableType elementToValueFn)
public ObjectMap(IList keysArray, IList valuesArray)
public ObjectMap(IList keysArray, IList valuesArray, bool allowDupliacteLastWins)
ICallableType are lambdas representing keys and values of the sourceArray.
Example:
nameKeys = [ "John", "Paul", "George", "Ringo"]
ageValues = [ 12, 22, 32, 42]
map1 = Fcs.Types.ObjectMap(nameKeys, ageValues)
ageJohn = map1["John"]
koko = map1.ContainsKey("John")
Another example:
sourceArray = [
{object = "Emil", idInt = 0, },
{object = "Stacy", idInt = 1, },
{object = "Susan", idInt = 2, },
{object = "Mike", idInt = 3, },
]
objectMap := Fcs.Types.ObjectMap( (sourceArray), (o => o.idInt), (o => o.object) )
result = objectMap[1] --> "Stacy"
Take care ! There need to be the brackets " ( ) " between arguments. Otherwise the parser interpretes the "sourceArray, o" as 2 parameters in lambda.
Pak ještě existuje ObjectLazyMap, kde je jen jediný konstruktor
public ObjectLazyMap(IEnumerable sourceArray, ICallableType elementToKeyFn, ICallableType elementToValueFn)
A u té je garantováno, že ta elementToValueFn nepoběží, dokud nikdo na ten odpovídající klíč nešáhne, tzn, zde mohou být naházeny i drahé hodnoty
U normální mapy se naopak vše vyhodnotí hned jak se ta mapa založí