sanctuary-js / sanctuary

:see_no_evil: Refuge from unsafe JavaScript
https://sanctuary.js.org
MIT License
3.03k stars 94 forks source link

Either with Buffer Type #575

Closed Ken-LiuL closed 6 years ago

Ken-LiuL commented 6 years ago

when use Buffer type in S.either, it will throw type unsupported error, if type check is open

davidchambers commented 6 years ago

You'll need to define a Buffer type, then create a Sanctuary module with a custom environment which includes that type:

const {create, env} = require ('sanctuary');
const $ = require ('sanctuary-def');

//    BufferType :: Type
const BufferType = $.NullaryType
  ('my-package/Buffer')
  ('https://my-package.org/#Buffer')
  (Buffer.isBuffer);

const S = create ({checkTypes: true, env: env.concat ([BufferType])});

Let me know if this approach works for you, @Charles-Lau-.

Ken-LiuL commented 6 years ago

it seems I need to define this for each types that are not defined in 'sanctuary-def', this works after I define all of them

davidchambers commented 6 years ago

That's right, @Charles-Lau-. If you believe some of your type definitions are general enough to warrant inclusion in $.env, please raise an issue.

jceb commented 4 years ago

@davidchambers This is really useful when using sanctuary with NodeJS. Would love to see it become part of $.env. What's necessary to get it in there?