The OpenD Programming Language

require

Looks up key; if it exists returns corresponding value else evaluates value, adds it to the associative array and returns it.

ref
V
require
(
K
V
)
(
ref V[K] aa
,
K key
,
lazy V value = V.init
)

Parameters

aa V[K]

The associative array.

key K

The key.

value V

The required value.

Return Value

Type: V

The value.

Examples

auto aa = ["k1": 1];
assert(aa.require("k1", 0) == 1);
assert(aa.require("k2", 0) == 0);
assert(aa["k2"] == 0);

Meta