"take" (mapping::take)

Returns the value at the given key and removes the key from the mapping.

Synopsis

T take(T key, T defaultValue = anytype());

Parameters

Parameter Description
key Mapping key
defaultValue Value that is returned if key does not exist.

Return Value

Value at the given key. If the key is not found, the function returns the defaultValue.

Description

Returns the value at the given key and removes the key/value pair from the mapping. If the key does not exist, the optional defaultValue is returned and the mapping remains unchanged.

Example

main()
{
  mapping m = makeMapping("city", "Vienna", "country", "Austria");
  string val = m.take("city");
  DebugN(val);           // "Vienna"
  DebugN(m.count());     // 1 (city was removed)
  DebugN(m.take("name", "unknown")); // "unknown"
}

Assignment

Mapping Methods