Add value-returning match expressions
This commit is contained in:
parent
b0a52de4ea
commit
ab783c33ed
12 changed files with 384 additions and 14 deletions
|
|
@ -82,7 +82,7 @@ for (const declaration of [
|
|||
|
||||
const prefixes = new Set(Object.values(snippets).map((snippet) => snippet.prefix));
|
||||
for (const prefix of [
|
||||
"dataclass", "tablerow", "embed", "coroutinescope", "launch", "async", "enum", "match", "mapto", "safe", "nonnull", "resultfun", "resultmatch", "defer", "foreach", "sqlfetch",
|
||||
"dataclass", "tablerow", "embed", "coroutinescope", "launch", "async", "enum", "match", "matchvalue", "mapto", "safe", "nonnull", "resultfun", "resultmatch", "defer", "foreach", "sqlfetch",
|
||||
"sqlsingle", "sqliterator", "sqlinsertnothing", "sqlinsertupdate", "sqlupdatereturning"
|
||||
]) {
|
||||
assert(prefixes.has(prefix), `snippets are missing prefix ${prefix}`);
|
||||
|
|
|
|||
|
|
@ -80,6 +80,17 @@
|
|||
],
|
||||
"description": "Exhaustive match over enum variants"
|
||||
},
|
||||
"Exhaustive Match Expression": {
|
||||
"prefix": "matchvalue",
|
||||
"body": [
|
||||
"val ${1:value} = match (${2:result}) {",
|
||||
" ${3:Result}::${4:Success}(${5:item}) -> ${5:item}",
|
||||
" ${3:Result}::${6:Failure}(${7:reason}) -> ${7:reason}",
|
||||
" $0",
|
||||
"}"
|
||||
],
|
||||
"description": "Return a typed value from an exhaustive enum match"
|
||||
},
|
||||
"Recursive Structural Mapping": {
|
||||
"prefix": "mapto",
|
||||
"body": ["val ${1:target} = ${2:source}.mapTo<${3:Target}>()"],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue