const {create, env} = require('sanctuary')
part ?
withdraw :: PositiveFiniteNumber -> BankAccount -> BankAccount
may not be important during development, but would be crucial in production to prevent negative withdrawals (i.e. deposits).
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')