NODE_ENV=production
. Another situation in which tying checkTypes
to NODE_ENV
is problematic is property-based testing. These tests can be slow, so one may wish to disable type checking when running such tests locally. One would not want to set NODE_ENV=production
, though, as this may have other effects such as having the test runner connect to a live database. The general problem is that having different behaviours depend on a single value means one can't adjust one setting independently of the others. A better solution would be to have a dedicated environment variable such as SANCTUARY_CHECK_TYPES
. In fact, there's a module named plaid-sanctuary
in Plaid's private npm registry which simply creates and exports a Sanctuary module with the value of checkTypes
determined by this environment variable.
S.checkTypes = false
, but this would prevent type checking from being used in one module but not another, and would cause problems for projects which depend on Sanctuary both directly and indirectly.
NODE_ENV
outweigh the benefits, but it's possible there's an equally convenient solution with less significant drawbacks.
R.pipe(f, g, h, i)
, and f
might return a null/undefined, then you need to do either do null checks on g
, h
,and i
as well (even though they are safe themselves), or you need to nest everything inside the first null check (losing compositionality)
Maybe
and Either
are not very common in javascript of course, but on the other hand, the basic pattern should be sort of familiar from working with Arrays and Promises
S.Just(3).filter(x => x > 3)
will return S.Nothing()
[3].filter(x => x > 3)
will return []
These things sounds good, would be nice to see a nice write up /video with examples to really understand.
I agree that this would be very useful, @bgvianyc. I currently have my hands full preparing the next release, but I look forward to tackling #210 and #211 (and possibly recording some screencasts) in a week or two.
const {$Maybe} = require('./types')
sanctuary-types
which exports all types currently baked into sanctuary-def
, and a sanctuary-algebraic-types
which exports $Either
and $Maybe
. Or simply export $Either
and $Maybe
from sanctuary the same way $FiniteNumber
is exported from sanctuary-def
.
T = {native: require('sanctuary-types'), algebraic: require('sanctuary-algebraic-types')}
- you get the point. :)
Perhaps it'd be nice to create a
sanctuary-types
which exports all types currently baked intosanctuary-def
, and asanctuary-algebraic-types
which exports$Either
and$Maybe
.
This is close to what I have in mind. I created sanctuary-types several months ago for exactly the purpose you described. I created sanctuary-either and sanctuary-maybe a few days ago. I'd like to move the definitions of the Either and Maybe types (and their associated type constructors) from Sanctuary to these separate projects. Sanctuary will then depend on these packages, but people will be free to use the data types without using Sanctuary.