Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sanctuary-def

Package Overview
Dependencies
Maintainers
12
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sanctuary-def - npm Package Compare versions

Comparing version 0.14.0 to 0.15.0

21

package.json
{
"name": "sanctuary-def",
"version": "0.14.0",
"version": "0.15.0",
"description": "Run-time type system for JavaScript",

@@ -11,19 +11,14 @@ "license": "MIT",

"scripts": {
"test": "make test lint"
"doctest": "sanctuary-doctest",
"lint": "sanctuary-lint",
"release": "sanctuary-release",
"test": "npm run lint && sanctuary-test && npm run doctest"
},
"dependencies": {
"sanctuary-type-classes": "7.1.x",
"sanctuary-type-classes": "8.1.x",
"sanctuary-type-identifiers": "2.0.x"
},
"devDependencies": {
"eslint": "4.9.x",
"istanbul": "0.4.x",
"mocha": "3.x.x",
"remark-cli": "3.x.x",
"remark-lint-no-undefined-references": "1.x.x",
"remark-lint-no-unused-definitions": "1.x.x",
"remember-bower": "0.1.x",
"sanctuary-style": "1.0.x",
"transcribe": "1.0.x",
"xyz": "2.0.x"
"eslint-plugin-markdown": "1.0.0-beta.7",
"sanctuary-scripts": "1.2.x"
},

@@ -30,0 +25,0 @@ "files": [

@@ -11,3 +11,3 @@ # sanctuary-def

```javascript
const $ = require('sanctuary-def');
const $ = require ('sanctuary-def');
```

@@ -22,9 +22,9 @@

// Integer :: Type
const Integer = ...;
const Integer = '...';
// NonZeroInteger :: Type
const NonZeroInteger = ...;
const NonZeroInteger = '...';
// env :: Array Type
const env = $.env.concat([Integer, NonZeroInteger]);
const env = $.env.concat ([Integer, NonZeroInteger]);
```

@@ -38,9 +38,9 @@

// env :: Array Type
const env = $.env.concat([
List($.Number), // :: Type
List($.String), // :: Type
List(List($.Number)), // :: Type
List(List($.String)), // :: Type
List(List(List($.Number))), // :: Type
List(List(List($.String))), // :: Type
const env = $.env.concat ([
List ($.Number), // :: Type
List ($.String), // :: Type
List (List ($.Number)), // :: Type
List (List ($.String)), // :: Type
List (List (List ($.Number))), // :: Type
List (List (List ($.String))), // :: Type
]);

@@ -54,3 +54,3 @@ ```

// env :: Array Type
const env = $.env.concat([List($.Unknown)]);
const env = $.env.concat ([List ($.Unknown)]);
```

@@ -61,3 +61,3 @@

```javascript
const def = $.create({checkTypes: true, env: env});
const def = $.create ({checkTypes: true, env});
```

@@ -70,5 +70,5 @@

```javascript
const def = $.create({
const def = $.create ({
checkTypes: process.env.NODE_ENV === 'development',
env: env,
env,
});

@@ -82,33 +82,45 @@ ```

const add =
def('add', {}, [$.Number, $.Number, $.Number], (x, y) => x + y);
def ('add')
({})
([$.Number, $.Number, $.Number])
(x => y => x + y);
```
`[$.Number, $.Number, $.Number]` specifies that `add` takes two arguments
of type `Number` and returns a value of type `Number`.
of type `Number`, one at a time, and returns a value of type `Number`.
Applying `add` to two arguments gives the expected result:
Applying `add` to two arguments, one at a time, gives the expected result:
```javascript
add(2, 2);
add (2) (2);
// => 4
```
Applying `add` to greater than two arguments results in an exception being
Applying `add` to multiple arguments at once results in an exception being
thrown:
```javascript
add(2, 2, 2);
// ! TypeError: ‘add’ requires two arguments; received three arguments
add (2, 2, 2);
// ! TypeError: ‘add’ applied to the wrong number of arguments
//
// add :: Number -> Number -> Number
// ^^^^^^
// 1
//
// Expected one argument but received three arguments:
//
// - 2
// - 2
// - 2
```
Applying `add` to fewer than two arguments results in a function
awaiting the remaining arguments. This is known as partial application.
Partial application is convenient as it allows more specific functions
to be defined in terms of more general ones:
Applying `add` to one argument produces a function awaiting the remaining
argument. This is known as partial application. Partial application allows
more specific functions to be defined in terms of more general ones:
```javascript
// inc :: Number -> Number
const inc = add(1);
const inc = add (1);
inc(7);
inc (7);
// => 8

@@ -121,12 +133,11 @@ ```

```javascript
// _add :: (Number, Number) -> Number
const _add = (x, y) => x + y;
// _add :: Number -> Number -> Number
const _add = x => y => x + y;
```
The type signature indicates that `_add` takes two arguments of type
`Number`, but this is not enforced. This allows type errors to be silently
ignored:
The type signature indicates that `_add` takes arguments of type `Number`,
but this is not enforced. This allows type errors to be silently ignored:
```javascript
_add('2', '2');
_add ('2') ('2');
// => '22'

@@ -139,3 +150,3 @@ ```

```javascript
add('2', '2');
add ('2') ('2');
// ! TypeError: Invalid value

@@ -156,3 +167,3 @@ //

```javascript
add('X');
add ('X');
// ! TypeError: Invalid value

@@ -169,22 +180,2 @@ //

<h4 name="__"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L188">__ :: Placeholder</a></code></h4>
The special placeholder value.
One may wish to partially apply a function whose parameters are in the
"wrong" order. Functions defined via sanctuary-def accommodate this by
accepting placeholders for arguments yet to be provided. For example:
```javascript
// concatS :: String -> String -> String
const concatS =
def('concatS', {}, [$.String, $.String, $.String], (x, y) => x + y);
// exclaim :: String -> String
const exclaim = concatS($.__, '!');
exclaim('ahoy');
// => 'ahoy!'
```
### Types

@@ -196,27 +187,40 @@

<h4 name="Any"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L456">Any :: Type</a></code></h4>
<h4 name="Any"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L454">Any :: Type</a></code></h4>
Type comprising every JavaScript value.
<h4 name="AnyFunction"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L461">AnyFunction :: Type</a></code></h4>
<h4 name="AnyFunction"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L459">AnyFunction :: Type</a></code></h4>
Type comprising every Function value.
<h4 name="Arguments"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L466">Arguments :: Type</a></code></h4>
<h4 name="Arguments"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L464">Arguments :: Type</a></code></h4>
Type comprising every [`arguments`][arguments] object.
<h4 name="Array"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L471">Array :: Type -⁠> Type</a></code></h4>
<h4 name="Array"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L469">Array :: Type -⁠> Type</a></code></h4>
Constructor for homogeneous Array types.
<h4 name="Boolean"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L476">Boolean :: Type</a></code></h4>
<h4 name="Array0"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L474">Array0 :: Type</a></code></h4>
Type whose sole member is `[]`.
<h4 name="Array1"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L482">Array1 :: Type -⁠> Type</a></code></h4>
Constructor for singleton Array types.
<h4 name="Array2"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L491">Array2 :: Type -⁠> Type -⁠> Type</a></code></h4>
Constructor for heterogeneous Array types of length 2. `['foo', true]` is
a member of `Array2 String Boolean`.
<h4 name="Boolean"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L502">Boolean :: Type</a></code></h4>
Type comprising `true` and `false`.
<h4 name="Date"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L481">Date :: Type</a></code></h4>
<h4 name="Date"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L507">Date :: Type</a></code></h4>
Type comprising every Date value.
<h4 name="Error"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L486">Error :: Type</a></code></h4>
<h4 name="Error"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L512">Error :: Type</a></code></h4>

@@ -226,3 +230,3 @@ Type comprising every Error value, including values of more specific

<h4 name="FiniteNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L492">FiniteNumber :: Type</a></code></h4>
<h4 name="FiniteNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L518">FiniteNumber :: Type</a></code></h4>

@@ -232,3 +236,3 @@ Type comprising every [`ValidNumber`][] value except `Infinity` and

<h4 name="Function"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L501">Function :: Array Type -⁠> Type</a></code></h4>
<h4 name="Function"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L532">Function :: NonEmpty (Array Type) -⁠> Type</a></code></h4>

@@ -239,7 +243,7 @@ Constructor for Function types.

- `$.Function([$.Date, $.String])` represents the `Date -> String`
- `$.Function ([$.Date, $.String])` represents the `Date -> String`
type; and
- `$.Function([a, b, a])` represents the `(a, b) -> a` type.
- `$.Function ([a, b, a])` represents the `(a, b) -> a` type.
<h4 name="GlobalRegExp"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L538">GlobalRegExp :: Type</a></code></h4>
<h4 name="GlobalRegExp"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L571">GlobalRegExp :: Type</a></code></h4>

@@ -250,3 +254,3 @@ Type comprising every [`RegExp`][] value whose `global` flag is `true`.

<h4 name="Integer"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L548">Integer :: Type</a></code></h4>
<h4 name="Integer"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L581">Integer :: Type</a></code></h4>

@@ -256,17 +260,17 @@ Type comprising every integer in the range

<h4 name="NegativeFiniteNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L562">NegativeFiniteNumber :: Type</a></code></h4>
<h4 name="NegativeFiniteNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L595">NegativeFiniteNumber :: Type</a></code></h4>
Type comprising every [`FiniteNumber`][] value less than zero.
<h4 name="NegativeInteger"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L570">NegativeInteger :: Type</a></code></h4>
<h4 name="NegativeInteger"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L603">NegativeInteger :: Type</a></code></h4>
Type comprising every [`Integer`][] value less than zero.
<h4 name="NegativeNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L578">NegativeNumber :: Type</a></code></h4>
<h4 name="NegativeNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L611">NegativeNumber :: Type</a></code></h4>
Type comprising every [`Number`][] value less than zero.
<h4 name="NonEmpty"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L586">NonEmpty :: Type -⁠> Type</a></code></h4>
<h4 name="NonEmpty"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L619">NonEmpty :: Type -⁠> Type</a></code></h4>
Constructor for non-empty types. `$.NonEmpty($.String)`, for example, is
Constructor for non-empty types. `$.NonEmpty ($.String)`, for example, is
the type comprising every [`String`][] value except `''`.

@@ -276,3 +280,3 @@

<h4 name="NonGlobalRegExp"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L603">NonGlobalRegExp :: Type</a></code></h4>
<h4 name="NonGlobalRegExp"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L635">NonGlobalRegExp :: Type</a></code></h4>

@@ -283,3 +287,3 @@ Type comprising every [`RegExp`][] value whose `global` flag is `false`.

<h4 name="NonNegativeInteger"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L613">NonNegativeInteger :: Type</a></code></h4>
<h4 name="NonNegativeInteger"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L645">NonNegativeInteger :: Type</a></code></h4>

@@ -289,27 +293,27 @@ Type comprising every non-negative [`Integer`][] value (including `-0`).

<h4 name="NonZeroFiniteNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L622">NonZeroFiniteNumber :: Type</a></code></h4>
<h4 name="NonZeroFiniteNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L654">NonZeroFiniteNumber :: Type</a></code></h4>
Type comprising every [`FiniteNumber`][] value except `0` and `-0`.
<h4 name="NonZeroInteger"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L630">NonZeroInteger :: Type</a></code></h4>
<h4 name="NonZeroInteger"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L662">NonZeroInteger :: Type</a></code></h4>
Type comprising every [`Integer`][] value except `0` and `-0`.
<h4 name="NonZeroValidNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L638">NonZeroValidNumber :: Type</a></code></h4>
<h4 name="NonZeroValidNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L670">NonZeroValidNumber :: Type</a></code></h4>
Type comprising every [`ValidNumber`][] value except `0` and `-0`.
<h4 name="Null"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L646">Null :: Type</a></code></h4>
<h4 name="Null"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L678">Null :: Type</a></code></h4>
Type whose sole member is `null`.
<h4 name="Nullable"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L651">Nullable :: Type -⁠> Type</a></code></h4>
<h4 name="Nullable"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L683">Nullable :: Type -⁠> Type</a></code></h4>
Constructor for types which include `null` as a member.
<h4 name="Number"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L663">Number :: Type</a></code></h4>
<h4 name="Number"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L695">Number :: Type</a></code></h4>
Type comprising every primitive Number value (including `NaN`).
<h4 name="Object"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L668">Object :: Type</a></code></h4>
<h4 name="Object"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L700">Object :: Type</a></code></h4>

@@ -324,24 +328,19 @@ Type comprising every "plain" Object value. Specifically, values

<h4 name="Pair"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L679">Pair :: Type -⁠> Type -⁠> Type</a></code></h4>
<h4 name="PositiveFiniteNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L711">PositiveFiniteNumber :: Type</a></code></h4>
Constructor for tuple types of length 2. Arrays are said to represent
tuples. `['foo', 42]` is a member of `Pair String Number`.
<h4 name="PositiveFiniteNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L690">PositiveFiniteNumber :: Type</a></code></h4>
Type comprising every [`FiniteNumber`][] value greater than zero.
<h4 name="PositiveInteger"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L698">PositiveInteger :: Type</a></code></h4>
<h4 name="PositiveInteger"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L719">PositiveInteger :: Type</a></code></h4>
Type comprising every [`Integer`][] value greater than zero.
<h4 name="PositiveNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L706">PositiveNumber :: Type</a></code></h4>
<h4 name="PositiveNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L727">PositiveNumber :: Type</a></code></h4>
Type comprising every [`Number`][] value greater than zero.
<h4 name="RegExp"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L714">RegExp :: Type</a></code></h4>
<h4 name="RegExp"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L735">RegExp :: Type</a></code></h4>
Type comprising every RegExp value.
<h4 name="RegexFlags"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L719">RegexFlags :: Type</a></code></h4>
<h4 name="RegexFlags"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L740">RegexFlags :: Type</a></code></h4>

@@ -359,3 +358,3 @@ Type comprising the canonical RegExp flags:

<h4 name="StrMap"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L736">StrMap :: Type -⁠> Type</a></code></h4>
<h4 name="StrMap"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L757">StrMap :: Type -⁠> Type</a></code></h4>

@@ -367,23 +366,23 @@ Constructor for homogeneous Object types.

<h4 name="String"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L750">String :: Type</a></code></h4>
<h4 name="String"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L771">String :: Type</a></code></h4>
Type comprising every primitive String value.
<h4 name="Symbol"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L755">Symbol :: Type</a></code></h4>
<h4 name="Symbol"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L776">Symbol :: Type</a></code></h4>
Type comprising every Symbol value.
<h4 name="Type"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L760">Type :: Type</a></code></h4>
<h4 name="Type"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L781">Type :: Type</a></code></h4>
Type comprising every `Type` value.
<h4 name="TypeClass"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L765">TypeClass :: Type</a></code></h4>
<h4 name="TypeClass"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L786">TypeClass :: Type</a></code></h4>
Type comprising every [`TypeClass`][] value.
<h4 name="Undefined"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L771">Undefined :: Type</a></code></h4>
<h4 name="Undefined"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L792">Undefined :: Type</a></code></h4>
Type whose sole member is `undefined`.
<h4 name="Unknown"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L776">Unknown :: Type</a></code></h4>
<h4 name="Unknown"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L797">Unknown :: Type</a></code></h4>

@@ -394,3 +393,3 @@ Type used to represent missing type information. The type of `[]`,

May be used with type constructors when defining environments. Given a
type constructor `List :: Type -> Type`, one could use `List($.Unknown)`
type constructor `List :: Type -> Type`, one could use `List ($.Unknown)`
to include an infinite number of types in an environment:

@@ -406,11 +405,11 @@

<h4 name="ValidDate"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L795">ValidDate :: Type</a></code></h4>
<h4 name="ValidDate"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L816">ValidDate :: Type</a></code></h4>
Type comprising every [`Date`][] value except `new Date(NaN)`.
Type comprising every [`Date`][] value except `new Date (NaN)`.
<h4 name="ValidNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L803">ValidNumber :: Type</a></code></h4>
<h4 name="ValidNumber"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L824">ValidNumber :: Type</a></code></h4>
Type comprising every [`Number`][] value except `NaN`.
<h4 name="env"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L811">env :: Array Type</a></code></h4>
<h4 name="env"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L832">env :: Array Type</a></code></h4>

@@ -421,3 +420,3 @@ An array of [types][]:

- <code>[Arguments](#Arguments)</code>
- <code>[Array](#Array)([Unknown](#Unknown))</code>
- <code>[Array](#Array) ([Unknown](#Unknown))</code>
- <code>[Boolean](#Boolean)</code>

@@ -430,3 +429,3 @@ - <code>[Date](#Date)</code>

- <code>[RegExp](#RegExp)</code>
- <code>[StrMap](#StrMap)([Unknown](#Unknown))</code>
- <code>[StrMap](#StrMap) ([Unknown](#Unknown))</code>
- <code>[String](#String)</code>

@@ -436,3 +435,3 @@ - <code>[Symbol](#Symbol)</code>

<h4 name="test"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L1275">test :: Array Type -⁠> Type -⁠> a -⁠> Boolean</a></code></h4>
<h4 name="test"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L1250">test :: Array Type -⁠> Type -⁠> a -⁠> Boolean</a></code></h4>

@@ -449,7 +448,6 @@ Takes an environment, a type, and any value. Returns `true` if the value

// NonNegativeInteger :: Type
const NonNegativeInteger = $.NullaryType(
'my-package/NonNegativeInteger',
'http://example.com/my-package#NonNegativeInteger',
x => $.test([], $.Integer, x) && x >= 0
);
const NonNegativeInteger = $.NullaryType
('my-package/NonNegativeInteger')
('http://example.com/my-package#NonNegativeInteger')
(x => $.test ([]) ($.Integer) (x) && x >= 0);
```

@@ -465,3 +463,3 @@

<h4 name="NullaryType"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L1306">NullaryType :: String -⁠> String -⁠> (Any -⁠> Boolean) -⁠> Type</a></code></h4>
<h4 name="NullaryType"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L1284">NullaryType :: String -⁠> String -⁠> (Any -⁠> Boolean) -⁠> Type</a></code></h4>

@@ -483,26 +481,27 @@ Type constructor for types with no type variables (such as [`Number`][]).

// Integer :: Type
const Integer = $.NullaryType(
'my-package/Integer',
'http://example.com/my-package#Integer',
x => typeof x === 'number' &&
Math.floor(x) === x &&
x >= Number.MIN_SAFE_INTEGER &&
x <= Number.MAX_SAFE_INTEGER
);
const Integer = $.NullaryType
('my-package/Integer')
('http://example.com/my-package#Integer')
(x => typeof x === 'number' &&
Math.floor (x) === x &&
x >= Number.MIN_SAFE_INTEGER &&
x <= Number.MAX_SAFE_INTEGER);
// NonZeroInteger :: Type
const NonZeroInteger = $.NullaryType(
'my-package/NonZeroInteger',
'http://example.com/my-package#NonZeroInteger',
x => $.test([], Integer, x) && x !== 0
);
const NonZeroInteger = $.NullaryType
('my-package/NonZeroInteger')
('http://example.com/my-package#NonZeroInteger')
(x => $.test ([]) (Integer) (x) && x !== 0);
// rem :: Integer -> NonZeroInteger -> Integer
const rem =
def('rem', {}, [Integer, NonZeroInteger, Integer], (x, y) => x % y);
def ('rem')
({})
([Integer, NonZeroInteger, Integer])
(x => y => x % y);
rem(42, 5);
rem (42) (5);
// => 2
rem(0.5);
rem (0.5);
// ! TypeError: Invalid value

@@ -518,3 +517,3 @@ //

rem(42, 0);
rem (42) (0);
// ! TypeError: Invalid value

@@ -531,3 +530,3 @@ //

<h4 name="UnaryType"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L1381">UnaryType :: String -⁠> String -⁠> (Any -⁠> Boolean) -⁠> (t a -⁠> Array a) -⁠> (Type -⁠> Type)</a></code></h4>
<h4 name="UnaryType"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L1364">UnaryType :: String -⁠> String -⁠> (Any -⁠> Boolean) -⁠> (t a -⁠> Array a) -⁠> Type -⁠> Type</a></code></h4>

@@ -554,3 +553,3 @@ Type constructor for types with one type variable (such as [`Array`][]).

```javascript
const type = require('sanctuary-type-identifiers');
const type = require ('sanctuary-type-identifiers');

@@ -561,8 +560,7 @@ // maybeTypeIdent :: String

// Maybe :: Type -> Type
const Maybe = $.UnaryType(
maybeTypeIdent,
'http://example.com/my-package#Maybe',
x => type(x) === maybeTypeIdent,
maybe => maybe.isJust ? [maybe.value] : []
);
const Maybe = $.UnaryType
(maybeTypeIdent)
('http://example.com/my-package#Maybe')
(x => type (x) === maybeTypeIdent)
(maybe => maybe.isJust ? [maybe.value] : []);

@@ -585,3 +583,3 @@ // MaybeTypeRep :: TypeRep Maybe

isNothing: false,
toString: () => 'Just(' + Z.toString(x) + ')',
toString: () => `Just (${Z.toString (x)})`,
value: x,

@@ -592,11 +590,14 @@ });

const fromMaybe =
def('fromMaybe', {}, [a, Maybe(a), a], (x, m) => m.isJust ? m.value : x);
def ('fromMaybe')
({})
([a, Maybe (a), a])
(x => m => m.isJust ? m.value : x);
fromMaybe(0, Just(42));
fromMaybe (0) (Just (42));
// => 42
fromMaybe(0, Nothing);
fromMaybe (0) (Nothing);
// => 0
fromMaybe(0, Just('XXX'));
fromMaybe (0) (Just ('XXX'));
// ! TypeError: Type-variable constraint violation

@@ -615,5 +616,6 @@ //

<h4 name="BinaryType"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L1490">BinaryType :: String -⁠> String -⁠> (Any -⁠> Boolean) -⁠> (t a b -⁠> Array a) -⁠> (t a b -⁠> Array b) -⁠> (Type -⁠> Type -⁠> Type)</a></code></h4>
<h4 name="BinaryType"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L1484">BinaryType :: String -⁠> String -⁠> (Any -⁠> Boolean) -⁠> (t a b -⁠> Array a) -⁠> (t a b -⁠> Array b) -⁠> Type -⁠> Type -⁠> Type</a></code></h4>
Type constructor for types with two type variables (such as [`Pair`][]).
Type constructor for types with two type variables (such as
[`Array2`][]).

@@ -645,3 +647,3 @@ To define a binary type `t a b` one must provide:

```javascript
const type = require('sanctuary-type-identifiers');
const type = require ('sanctuary-type-identifiers');

@@ -652,9 +654,8 @@ // pairTypeIdent :: String

// $Pair :: Type -> Type -> Type
const $Pair = $.BinaryType(
pairTypeIdent,
'http://example.com/my-package#Pair',
x => type(x) === pairTypeIdent,
pair => [pair[0]],
pair => [pair[1]]
);
const $Pair = $.BinaryType
(pairTypeIdent)
('http://example.com/my-package#Pair')
(x => type (x) === pairTypeIdent)
(({fst}) => [fst])
(({snd}) => [snd]);

@@ -665,35 +666,42 @@ // PairTypeRep :: TypeRep Pair

// Pair :: a -> b -> Pair a b
const Pair = def('Pair', {}, [a, b, $Pair(a, b)], (x, y) => ({
'0': x,
'1': y,
constructor: PairTypeRep,
length: 2,
toString: () => 'Pair(' + Z.toString(x) + ', ' + Z.toString(y) + ')',
}));
const Pair =
def ('Pair')
({})
([a, b, $Pair (a) (b)])
(fst => snd => ({
constructor: PairTypeRep,
fst,
snd,
toString: () =>
`Pair (${Z.toString (fst)}) (${Z.toString (snd)})`,
}));
// Rank :: Type
const Rank = $.NullaryType(
'my-package/Rank',
'http://example.com/my-package#Rank',
x => typeof x === 'string' && /^([A23456789JQK]|10)$/.test(x)
);
const Rank = $.NullaryType
('my-package/Rank')
('http://example.com/my-package#Rank')
(x => typeof x === 'string' &&
/^(A|2|3|4|5|6|7|8|9|10|J|Q|K)$/.test (x));
// Suit :: Type
const Suit = $.NullaryType(
'my-package/Suit',
'http://example.com/my-package#Suit',
x => typeof x === 'string' && /^[\u2660\u2663\u2665\u2666]$/.test(x)
);
const Suit = $.NullaryType
('my-package/Suit')
('http://example.com/my-package#Suit')
(x => typeof x === 'string' &&
/^[\u2660\u2663\u2665\u2666]$/.test (x));
// Card :: Type
const Card = $Pair(Rank, Suit);
const Card = $Pair (Rank) (Suit);
// showCard :: Card -> String
const showCard =
def('showCard', {}, [Card, $.String], card => card[0] + card[1]);
def ('showCard')
({})
([Card, $.String])
(card => card.fst + card.snd);
showCard(Pair('A', '♠'));
showCard (Pair ('A') ('♠'));
// => 'A♠'
showCard(Pair('X', '♠'));
showCard (Pair ('X') ('♠'));
// ! TypeError: Invalid value

@@ -710,3 +718,3 @@ //

<h4 name="EnumType"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L1625">EnumType :: String -⁠> String -⁠> Array Any -⁠> Type</a></code></h4>
<h4 name="EnumType"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L1644">EnumType :: String -⁠> String -⁠> Array Any -⁠> Type</a></code></h4>

@@ -727,10 +735,9 @@ Type constructor for [enumerated types][] (such as [`RegexFlags`][]).

// Denomination :: Type
const Denomination = $.EnumType(
'my-package/Denomination',
'http://example.com/my-package#Denomination',
[10, 20, 50, 100, 200]
);
const Denomination = $.EnumType
('my-package/Denomination')
('http://example.com/my-package#Denomination')
([10, 20, 50, 100, 200]);
```
<h4 name="RecordType"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L1654">RecordType :: StrMap Type -⁠> Type</a></code></h4>
<h4 name="RecordType"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L1677">RecordType :: StrMap Type -⁠> Type</a></code></h4>

@@ -748,17 +755,19 @@ `RecordType` is used to construct record types. The type definition

// Point :: Type
const Point = $.RecordType({x: $.FiniteNumber, y: $.FiniteNumber});
const Point = $.RecordType ({x: $.FiniteNumber, y: $.FiniteNumber});
// dist :: Point -> Point -> FiniteNumber
const dist =
def('dist', {}, [Point, Point, $.FiniteNumber],
(p, q) => Math.sqrt(Math.pow(p.x - q.x, 2) +
Math.pow(p.y - q.y, 2)));
def ('dist')
({})
([Point, Point, $.FiniteNumber])
(p => q => Math.sqrt (Math.pow (p.x - q.x, 2) +
Math.pow (p.y - q.y, 2)));
dist({x: 0, y: 0}, {x: 3, y: 4});
dist ({x: 0, y: 0}) ({x: 3, y: 4});
// => 5
dist({x: 0, y: 0}, {x: 3, y: 4, color: 'red'});
dist ({x: 0, y: 0}) ({x: 3, y: 4, color: 'red'});
// => 5
dist({x: 0, y: 0}, {x: NaN, y: NaN});
dist ({x: 0, y: 0}) ({x: NaN, y: NaN});
// ! TypeError: Invalid value

@@ -774,3 +783,3 @@ //

dist(0);
dist (0);
// ! TypeError: Invalid value

@@ -787,3 +796,3 @@ //

<h4 name="TypeVariable"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L1732">TypeVariable :: String -⁠> Type</a></code></h4>
<h4 name="TypeVariable"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L1757">TypeVariable :: String -⁠> Type</a></code></h4>

@@ -798,12 +807,12 @@ Polymorphism is powerful. Not being able to define a function for

```javascript
const a = $.TypeVariable('a');
const b = $.TypeVariable('b');
const a = $.TypeVariable ('a');
const b = $.TypeVariable ('b');
// id :: a -> a
const id = def('id', {}, [a, a], x => x);
const id = def ('id') ({}) ([a, a]) (x => x);
id(42);
id (42);
// => 42
id(null);
id (null);
// => null

@@ -818,14 +827,17 @@ ```

const cmp =
def('cmp', {}, [a, a, $.Number], (x, y) => x < y ? -1 : x > y ? 1 : 0);
def ('cmp')
({})
([a, a, $.Number])
(x => y => x < y ? -1 : x > y ? 1 : 0);
cmp(42, 42);
cmp (42) (42);
// => 0
cmp('a', 'z');
cmp ('a') ('z');
// => -1
cmp('z', 'a');
cmp ('z') ('a');
// => 1
cmp(0, '1');
cmp (0) ('1');
// ! TypeError: Type-variable constraint violation

@@ -844,3 +856,3 @@ //

<h4 name="UnaryTypeVariable"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L1792">UnaryTypeVariable :: String -⁠> (Type -⁠> Type)</a></code></h4>
<h4 name="UnaryTypeVariable"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L1820">UnaryTypeVariable :: String -⁠> Type -⁠> Type</a></code></h4>

@@ -866,15 +878,15 @@ Combines [`UnaryType`][] and [`TypeVariable`][].

```javascript
const $ = require('sanctuary-def');
const Z = require('sanctuary-type-classes');
const $ = require ('sanctuary-def');
const Z = require ('sanctuary-type-classes');
const a = $.TypeVariable('a');
const b = $.TypeVariable('b');
const f = $.UnaryTypeVariable('f');
const a = $.TypeVariable ('a');
const b = $.TypeVariable ('b');
const f = $.UnaryTypeVariable ('f');
// map :: Functor f => (a -> b) -> f a -> f b
const map =
def('map',
{f: [Z.Functor]},
[$.Function([a, b]), f(a), f(b)],
Z.map);
def ('map')
({f: [Z.Functor]})
([$.Function ([a, b]), f (a), f (b)])
(f => functor => Z.map (f, functor));
```

@@ -893,3 +905,3 @@

<h4 name="BinaryTypeVariable"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L1856">BinaryTypeVariable :: String -⁠> (Type -⁠> Type -⁠> Type)</a></code></h4>
<h4 name="BinaryTypeVariable"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L1884">BinaryTypeVariable :: String -⁠> Type -⁠> Type -⁠> Type</a></code></h4>

@@ -909,11 +921,11 @@ Combines [`BinaryType`][] and [`TypeVariable`][].

<h4 name="Thunk"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L1891">Thunk :: Type -⁠> Type</a></code></h4>
<h4 name="Thunk"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L1924">Thunk :: Type -⁠> Type</a></code></h4>
`$.Thunk(T)` is shorthand for `$.Function([T])`, the type comprising
`$.Thunk (T)` is shorthand for `$.Function ([T])`, the type comprising
every nullary function (thunk) which returns a value of type `T`.
<h4 name="Predicate"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.14.0/index.js#L1901">Predicate :: Type -⁠> Type</a></code></h4>
<h4 name="Predicate"><code><a href="https://github.com/sanctuary-js/sanctuary-def/blob/v0.15.0/index.js#L1934">Predicate :: Type -⁠> Type</a></code></h4>
`$.Predicate(T)` is shorthand for `$.Function([T, $.Boolean])`, the type
comprising every predicate function which takes a value of type `T`.
`$.Predicate (T)` is shorthand for `$.Function ([T, $.Boolean])`, the
type comprising every predicate function which takes a value of type `T`.

@@ -931,11 +943,14 @@ ### Type classes

const _concat =
def('_concat', {}, [a, a, a], (x, y) => x.concat(y));
def ('_concat')
({})
([a, a, a])
(x => y => x.concat (y));
_concat('fizz', 'buzz');
_concat ('fizz') ('buzz');
// => 'fizzbuzz'
_concat([1, 2], [3, 4]);
_concat ([1, 2]) ([3, 4]);
// => [1, 2, 3, 4]
_concat([1, 2], 'buzz');
_concat ([1, 2]) ('buzz');
// ! TypeError: Type-variable constraint violation

@@ -962,6 +977,6 @@ //

```javascript
_concat({}, {});
_concat ({}) ({});
// ! TypeError: undefined is not a function
_concat(null, null);
_concat (null) (null);
// ! TypeError: Cannot read property 'concat' of null

@@ -975,6 +990,6 @@ ```

```javascript
const Z = require('sanctuary-type-classes');
const Z = require ('sanctuary-type-classes');
// Semigroup :: TypeClass
const Semigroup = Z.TypeClass(
const Semigroup = Z.TypeClass (
'my-package/Semigroup',

@@ -988,8 +1003,11 @@ 'http://example.com/my-package#Semigroup',

const concat =
def('concat', {a: [Semigroup]}, [a, a, a], (x, y) => x.concat(y));
def ('concat')
({a: [Semigroup]})
([a, a, a])
(x => y => x.concat (y));
concat([1, 2], [3, 4]);
concat ([1, 2]) ([3, 4]);
// => [1, 2, 3, 4]
concat({}, {});
concat ({}) ({});
// ! TypeError: Type-class constraint violation

@@ -1007,3 +1025,3 @@ //

concat(null, null);
concat (null) (null);
// ! TypeError: Type-class constraint violation

@@ -1029,2 +1047,3 @@ //

[`Array`]: #Array
[`Array2`]: #Array2
[`BinaryType`]: #BinaryType

@@ -1038,3 +1057,2 @@ [`Date`]: #Date

[`Object.create`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create
[`Pair`]: #Pair
[`RegExp`]: #RegExp

@@ -1041,0 +1059,0 @@ [`RegexFlags`]: #RegexFlags

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc