-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: getOrThrow / deleteOrThrowを追加 (#2055)
* Add: StrictMapを追加 * Change: phrasesをmustGetベースに * Change: 型定義の場所を変える * Change: mustGet -> getOrThrow * Change: prototype汚染をやめる * Apply suggestions from code review --------- Co-authored-by: Hiroshiba <hihokaruta@gmail.com>
- Loading branch information
1 parent
a406005
commit 595d108
Showing
3 changed files
with
41 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** Mapのヘルパー関数 */ | ||
|
||
/** Mapから値を取得する。指定したキーが存在しない場合は例外を投げる */ | ||
export const getOrThrow = <K, V>(map: Map<K, V>, key: K) => { | ||
if (!map.has(key)) { | ||
throw new Error(`Key not found: ${key}`); | ||
} | ||
return map.get(key) as V; | ||
}; | ||
|
||
/** Mapから値を削除する。指定したキーが存在しない場合は例外を投げる */ | ||
export const deleteOrThrow = <K, V>(map: Map<K, V>, key: K) => { | ||
if (!map.has(key)) { | ||
throw new Error(`Key not found: ${key}`); | ||
} | ||
map.delete(key); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters