UNPKG
@matatbread/typia
Version:
latest (9.7.2-nrc)
9.7.2-nrc
7.0.1-nrc
6.11.1
6.11.0
6.11.0-p1
6.8.0
Superfast runtime validators with only one line
typia.io
samchon/typia
@matatbread/typia
/
src
/
utils
/
MapUtil.ts
15 lines
(13 loc)
•
298 B
text/typescript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export
namespace
MapUtil
{
export
const
take = <
Key
, T>(
dict
:
Map
<
Key
, T>,
key
:
Key
,
generator
:
() =>
T, ):
T
=>
{
const
oldbie
: T |
undefined
= dict.
get
(key);
if
(oldbie)
return
oldbie;
const
value
: T =
generator
(); dict.
set
(key, value);
return
value; }; }