Version: v0.8.1 - Beta.  We welcome contributors & feedback.

Map.default

default($value) -> self

Description

Set the default value that will be returned when a missing key is accessed.

$numBirds = {}.default(0)

$numBirds['cardinals'] += 1

$numBirds['bluejays'] += 1
$numBirds['bluejays'] += 1

print($numBirds)
//= { cardinals: 1, bluejays: 2 }

See Also