Slide 23
Slide 23 text
3FBM8PSMEVTBHF8FC4IPQ1BZNFOU0QUJPOT
const [Cash, CreditCard, Transfer, match] = Choice(3); // generalized sum type
const pay = payment => match(payment)
( () =>
amount => 'pay ' + amount + ' cash')
( ( { number, sec } ) =>
amount => 'pay ' + amount + ' with credit card ' + number + ' / ' + sec)
( ( [ from, to ] ) =>
amount => 'pay ' + amount + ' by wire from ' + from + ' to ' + to);
let payment = Cash();
assert.is( pay(payment)(50), 'pay 50 cash');
payment = CreditCard( { number: '0000 1111 2222 3333', sec: '123' } );
assert.is( pay(payment)(50), 'pay 50 with credit card 0000 1111 2222 3333 / 123');
payment = Transfer(['Account 1', 'Account 2']);
assert.is( pay(payment)(50), 'pay 50 by wire from Account 1 to Account 2');