Skip to content

Instantly share code, notes, and snippets.

@stuf
Created January 15, 2018 15:13
Show Gist options
  • Save stuf/f5d93ab56ef03900c841a73b4bdde65b to your computer and use it in GitHub Desktop.
Save stuf/f5d93ab56ef03900c841a73b4bdde65b to your computer and use it in GitHub Desktop.
const $ = require('sanctuary-def');
const Ratio =
$.NullaryType('package-name/Ratio',
'https://package.url.io/Ratio',
x => typeof x === 'number' && (x >= 0 && x <= 1));
//
const def = $.create({
env: $.env.concat([Ratio]),
checkTypes: true
});
//
const getPct =
def('getPct', {},
[Ratio, $.String],
x => `${x * 100}%');
> getPct(0.5)
'50%'
> getPct(100)
TypeError: Invalid value

getPct :: Ratio -> String
          ^^^^^
            1

1)  100 :: Number

The value at position 1 is not a member of ‘Ratio’.

See https://package.url.io/Ratio for information about the package-name/Ratio type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment