Created
February 20, 2020 07:57
-
-
Save guillaumewuip/8290a2a9cc66ed95b56ebe867dc740bf to your computer and use it in GitHub Desktop.
How to model your entities - 9
This file contains hidden or 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
// Message.ts | |
function fold<R>( | |
onText: (message: TextMessage) => R, | |
onImage: (message: ImageMessage) => R, | |
onAudio: (message: AudioMessage) => R, | |
) => { | |
return (message: Message): R => { | |
switch (message.messageType) { | |
case ‘TEXT’: | |
return onText(message); | |
case ‘IMAGE’: | |
return onImage(message); | |
case ‘AUDIO’: | |
return onAudio(message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment