Skip to content

Instantly share code, notes, and snippets.

@guillaumewuip
Last active February 20, 2020 08:13
Show Gist options
  • Save guillaumewuip/5e8cdc20f512a6d9f1f4d659546f41ef to your computer and use it in GitHub Desktop.
Save guillaumewuip/5e8cdc20f512a6d9f1f4d659546f41ef to your computer and use it in GitHub Desktop.
How to model your entities - 11
import { createFold } from ‘@iadvize-oss/foldable-helpers’;
// fold :: (TextMessage -> R) -> (ImageMessage -> R) -> (AudioMessage -> R) -> Message -> R
// “feeding” the fold-creator with our previously created type guards
const fold = createFold(isText, isImage, isAudio);
// or, passing function with an object to give them names
import { createFoldObject } from ‘@iadvize-oss/foldable-helpers’;
// fold :: ({
// isText: TextMessage -> R,
// isImage: ImageMessage -> R,
// isAudio: AudioMessage -> R
// }) -> Message -> R
const fold = createFoldObject({ isText, isImage, isAudio });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment