Skip to content

Instantly share code, notes, and snippets.

@kikuchy
Created February 17, 2022 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kikuchy/55bf5894f7c777d5f20e163f864d1631 to your computer and use it in GitHub Desktop.
Save kikuchy/55bf5894f7c777d5f20e163f864d1631 to your computer and use it in GitHub Desktop.
Enum live template with when method like freezed sealed classes
enum $NAME$ {
$V1$,
$V2$,
}
extension $NAME$X on $NAME$ {
T when<T>({
required T Function() $V1$,
required T Function() $V2$,
}) {
switch (this) {
case $NAME$.$V1$:
return $V1$();
case $NAME$.$V2$:
return $V2$();
}
}
}
@kikuchy
Copy link
Author

kikuchy commented Feb 17, 2022

Each variable settings
スクリーンショット 2022-02-17 21 03 17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment