early-cheepers
v1.0.0
Published
type checking combinator birds
Downloads
8
Maintainers
Readme
early-cheepers
early-cheepers uses sanctuary-def to provide early-birds combinators with optional type checking.
By default, type checking is done under the condition process.env.NODE_ENV !== 'production'
.
If this is not desirable, the condition can be changed using the cheepers
function with
a configuration object as follows:
const aviary = cheepers ({
checkTypes: process.env.NODE_ENV !== 'production'`, // change the predicate here
})
// now all available combinators are members of aviary, e.g. aviary.bluebird
If only a subset of the combinators is required, another option key, names
, may be
set to an array of the desired combinators' names, e.g.
const aviary = cheepers ({
checkTypes: process.env.NODE_ENV === 'development'`,
names: [ bluebird, psi, ],
})
// now aviary.bluebird and aviary.psi are available with the changed predicate
Eager evaluation
Intermediate results for early-cheepers combinators, like those of early-birds, are eagerly evaluated, see early-birds
for more information regarding the eager evaluation. In short, if the use case
relies on side-effects, careful consideration should be given on how the impure
functions are being used with the combinators. If eager evaluation is not desired,
then fantasy-birds
may fit the use case. The cheepers
function can be used with fantasy-birds (v0.1.0)
using a third option key, implementations
, as follows:
const F = require ('fantasy-birds') // NOTE: not included as a dependency, must be installed seperately
import { cheepers } from 'early-cheepers'
const aviary = cheepers({
implementations: F
})
// now type checking fantasy-birds combinators are available, e.g. aviary.bluebird
Install
npm i early-cheepers
Integrating with Sanctuary
No special action is required for integration with Sanctuary.
Simply import the desired combinators from early-cheapers, e.g.
import { bluebird } from 'early-cheepers'
.
Comparison between early-cheepers combinators and sanctuary combinators
The early-cheepers combinators are specialized on functions whereas the
sanctuary combinators are more general. For example, sanctuary's compose
can be used to compose Pair types (or any other Semigroupoid) as well as
functions; however, early-cheaper's bluebird
(compose) combinator only
composes functions.
Consideration of type checking functions as parameters
Currently (for sanctuary-def v0.22.0), when functions are passed as parameters,
the passed function's type is not checked (in general, this would require
knowledge which is simply not available at the time of the call), but rather
it seems that sanctuary-def checks that the parameter is a function type. In
short, this means that type errors, when thrown, will likely identify the
error for an invalid parameter to the passed function rather than the passed
function as an invalid parameter for the combinator. For example,
warbler (idstar)
will not throw an error (and shouldn't); however,
warbler (idstar) (3)
will throw an error that identifies 3 :: Number
as
an invalid first parameter for idstar
. Also, warbler (3)
will throw an
error since 3 :: Number
is not a valid first parameter for wabler
itself.
This behavior also holds for functions of concrete types. For example, let
concatNumber :: Number -> String -> String
, then warbler (concatNumber)
will not throw an error (although the type information is actionable for a
throw); however warbler (concatNumber) (3)
will throw an error identifying
3 :: Number
as an invalid second parameter for concatNumber
.
The Aviary
See the early-birds aviary.