Created
October 23, 2019 19:16
Revisions
-
lupuszr revised this gist
Oct 23, 2019 . 1 changed file with 0 additions and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,6 @@ abstract class Season { type constraintsT = keyof typeof match; switch (this.constructor.name as unknown as constraintsT) { case 'Winter': { return match['Winter']() } case 'Summer': { -
lupuszr created this gist
Oct 23, 2019 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ abstract class Season { cata<W, Su, Sp, Au>(match: { Winter: () => W, Summer: () => Su, Autumn: () => Au, Spring: () => Sp }) { type constraintsT = keyof typeof match; switch (this.constructor.name as unknown as constraintsT) { case 'Winter': { const t = this as unknown as Winter; return match['Winter']() } case 'Summer': { return match['Summer'](); } case 'Autumn': { return match['Autumn'](); } case 'Spring': { return match['Spring'](); } } } } class Summer extends Season { constructor() { super() } } class Autumn extends Season { constructor() { super() } } class Winter extends Season { constructor() { super() } } class Spring extends Season { constructor() { super() } } const la = new Summer(); const next = la.cata({ Winter: () => new Spring(), Summer: () => new Autumn(), Autumn: () => new Winter(), Spring: () => new Summer(), })