Skip to content

Instantly share code, notes, and snippets.

@guillaumewuip
Created July 1, 2020 20:21
Show Gist options
  • Save guillaumewuip/28da4ef66f174cf0c79d142c5317b82f to your computer and use it in GitHub Desktop.
Save guillaumewuip/28da4ef66f174cf0c79d142c5317b82f to your computer and use it in GitHub Desktop.
export function addSignature(signature: string) {
return (text: Text) => {
const $text = MessageUnion.Text.iso.unwrap(text); // get private type
const $newText = {
…$text,
text: `${$message.text} - ${signature}`,
};
return MessageUnion.Text.iso.wrap($newText); // get opaque type
};
}
// Iso even offers shortcuts, the same result can be achieved like so:
export const addSignature = (signature: string) => MessageUnion.Text.iso.modify(
($text) => ({ ...$text, text: `${$text.text} - ${signature}` })
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment