[Issue 14386] New: add setOrGet to AA
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Mar 31 14:28:23 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14386
Issue ID: 14386
Summary: add setOrGet to AA
Product: D
Version: unspecified
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: code at dawg.eu
The function is called setdefault in python and getOrElseUpdate in Scala.
Allows to lookup a key or set a value with a single hash.
This is also possible in C++ using iterators.
https://docs.python.org/2/library/stdtypes.html#dict.setdefault
http://www.scala-lang.org/api/2.10.1-RC1/scala/collection/mutable/HashMap.html#getOrElseUpdate(A,⇒B):B
Another primitive that could work here is getLValue, but it requires the value
type to have a distinct null value, so it's less nice to work with.
--
More information about the Digitalmars-d-bugs
mailing list