From 359240f472224d6511c686cbf5283214172aa707 Mon Sep 17 00:00:00 2001 From: David Chambers Date: Tue, 6 Mar 2018 14:17:04 +0100 Subject: [PATCH] abandon Ramda-style currying in favour of simple currying --- .eslintrc.json | 2 +- bower.json | 2 +- eslint/es3.js | 12 + eslint/es6.js | 41 + eslint/rules/indent.js | 13 + index.js | 2570 +++++++++++++++-------------- karma.conf.js | 29 +- package.json | 3 +- scripts/lint | 39 + test/Either/Either.js | 210 +-- test/Either/EitherType.js | 18 +- test/Either/Left.js | 136 +- test/Either/Right.js | 136 +- test/I.js | 22 +- test/K.js | 18 +- test/Maybe/Just.js | 122 +- test/Maybe/Maybe.js | 236 +-- test/Maybe/MaybeType.js | 18 +- test/Maybe/Nothing.js | 100 +- test/T.js | 17 +- test/add.js | 20 +- test/allPass.js | 30 +- test/alt.js | 38 +- test/and.js | 20 +- test/anyPass.js | 30 +- test/ap.js | 40 +- test/apFirst.js | 16 +- test/apSecond.js | 16 +- test/append.js | 26 +- test/at.js | 28 +- test/bimap.js | 16 +- test/chain.js | 20 +- test/chainRec.js | 26 +- test/complement.js | 16 +- test/compose.js | 14 +- test/concat.js | 44 +- test/contramap.js | 14 +- test/create.js | 81 +- test/curry2.js | 19 +- test/curry3.js | 18 +- test/curry4.js | 22 +- test/curry5.js | 30 +- test/div.js | 14 +- test/drop.js | 28 +- test/dropLast.js | 28 +- test/dropWhile.js | 24 +- test/duplicate.js | 24 +- test/either.js | 16 +- test/eitherToMaybe.js | 16 +- test/elem.js | 26 +- test/empty.js | 18 +- test/encase.js | 18 +- test/encase2.js | 18 +- test/encase3.js | 18 +- test/encaseEither.js | 20 +- test/encaseEither2.js | 20 +- test/encaseEither3.js | 20 +- test/env.js | 12 +- test/equals.js | 36 +- test/even.js | 22 +- test/extend.js | 26 +- test/extract.js | 16 +- test/filter.js | 44 +- test/find.js | 26 +- test/flip.js | 18 +- test/fromEither.js | 16 +- test/fromMaybe.js | 16 +- test/fromMaybe_.js | 20 +- test/fromPairs.js | 20 +- test/get.js | 36 +- test/gets.js | 40 +- test/groupBy.js | 30 +- test/gt.js | 14 +- test/gte.js | 14 +- test/head.js | 20 +- test/id.js | 14 +- test/ifElse.js | 16 +- test/init.js | 20 +- test/insert.js | 32 +- test/internal/$.js | 2 +- test/internal/Compose.js | 30 +- test/internal/EitherArb.js | 10 +- test/internal/Identity.js | 30 +- test/internal/IdentityArb.js | 8 +- test/internal/List.js | 69 +- test/internal/MaybeArb.js | 10 +- test/internal/Sum.js | 29 +- test/internal/alt.js | 6 +- test/internal/ap.js | 6 +- test/internal/area.js | 6 +- test/internal/area_.js | 4 +- test/internal/bimap.js | 6 +- test/internal/chain.js | 6 +- test/internal/composeK.js | 4 +- test/internal/compose_.js | 2 +- test/internal/concat.js | 6 +- test/internal/curry2.js | 2 +- test/internal/curry3.js | 2 +- test/internal/eq.js | 19 +- test/internal/equals.js | 6 +- test/internal/extend.js | 6 +- test/internal/factorial.js | 4 +- test/internal/forall.js | 25 +- test/internal/laws/Alt.js | 20 +- test/internal/laws/Alternative.js | 22 +- test/internal/laws/Applicative.js | 30 +- test/internal/laws/Apply.js | 16 +- test/internal/laws/Bifunctor.js | 20 +- test/internal/laws/Chain.js | 14 +- test/internal/laws/Extend.js | 14 +- test/internal/laws/Foldable.js | 12 +- test/internal/laws/Functor.js | 20 +- test/internal/laws/Monad.js | 20 +- test/internal/laws/Monoid.js | 18 +- test/internal/laws/Plus.js | 24 +- test/internal/laws/Semigroup.js | 12 +- test/internal/laws/Setoid.js | 12 +- test/internal/laws/Traversable.js | 34 +- test/internal/laws/index.js | 30 +- test/internal/map.js | 6 +- test/internal/of.js | 6 +- test/internal/reduce.js | 6 +- test/internal/rem.js | 2 +- test/internal/rem_.js | 4 +- test/internal/sanctuary.js | 41 +- test/internal/squareRoot.js | 6 +- test/internal/throws.js | 17 +- test/internal/toString.js | 2 +- test/internal/traverse.js | 6 +- test/invert.js | 18 +- test/is.js | 76 +- test/isJust.js | 16 +- test/isLeft.js | 16 +- test/isNothing.js | 16 +- test/isRight.js | 16 +- test/join.js | 30 +- test/joinWith.js | 26 +- test/justs.js | 50 +- test/keys.js | 20 +- test/last.js | 20 +- test/lefts.js | 50 +- test/lift2.js | 32 +- test/lift3.js | 28 +- test/lines.js | 24 +- test/lt.js | 14 +- test/lte.js | 14 +- test/map.js | 32 +- test/mapLeft.js | 16 +- test/mapMaybe.js | 48 +- test/match.js | 42 +- test/matchAll.js | 26 +- test/max.js | 40 +- test/maybe.js | 16 +- test/maybeToEither.js | 16 +- test/maybeToNullable.js | 16 +- test/maybe_.js | 22 +- test/mean.js | 26 +- test/min.js | 40 +- test/mult.js | 24 +- test/negate.js | 16 +- test/not.js | 16 +- test/odd.js | 22 +- test/of.js | 24 +- test/on.js | 18 +- test/or.js | 20 +- test/pairs.js | 20 +- test/parseDate.js | 16 +- test/parseFloat.js | 72 +- test/parseInt.js | 252 ++- test/parseJson.js | 24 +- test/pipe.js | 34 +- test/pipeK.js | 30 +- test/pow.js | 18 +- test/prepend.js | 26 +- test/product.js | 28 +- test/promap.js | 20 +- test/prop.js | 39 +- test/properties.js | 16 +- test/props.js | 35 +- test/range.js | 22 +- test/reduce.js | 26 +- test/regex.js | 28 +- test/regexEscape.js | 24 +- test/reject.js | 44 +- test/remove.js | 32 +- test/reverse.js | 30 +- test/rights.js | 50 +- test/sequence.js | 44 +- test/singleton.js | 12 +- test/size.js | 34 +- test/slice.js | 38 +- test/sort.js | 22 +- test/sortBy.js | 30 +- test/splitOn.js | 40 +- test/splitOnRegex.js | 80 +- test/stripPrefix.js | 28 +- test/stripSuffix.js | 28 +- test/sub.js | 14 +- test/sum.js | 28 +- test/tagBy.js | 16 +- test/tail.js | 20 +- test/take.js | 28 +- test/takeLast.js | 28 +- test/takeWhile.js | 24 +- test/test.js | 24 +- test/toEither.js | 18 +- test/toLower.js | 16 +- test/toMaybe.js | 20 +- test/toString.js | 96 +- test/toUpper.js | 16 +- test/traverse.js | 48 +- test/trim.js | 26 +- test/type.js | 81 +- test/unfoldr.js | 20 +- test/unless.js | 18 +- test/unlines.js | 24 +- test/unwords.js | 26 +- test/values.js | 20 +- test/when.js | 18 +- test/words.js | 24 +- test/zero.js | 18 +- test/zip.js | 16 +- test/zipWith.js | 20 +- 223 files changed, 4501 insertions(+), 4250 deletions(-) create mode 100644 eslint/es3.js create mode 100644 eslint/es6.js create mode 100644 eslint/rules/indent.js create mode 100755 scripts/lint diff --git a/.eslintrc.json b/.eslintrc.json index d3c776ba..5c948fff 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,4 +1,4 @@ { "root": true, - "extends": ["./node_modules/sanctuary-style/eslint-es3.json"] + "extends": ["./eslint/es3.js"] } diff --git a/bower.json b/bower.json index bd163dad..40332a09 100644 --- a/bower.json +++ b/bower.json @@ -22,7 +22,7 @@ "types" ], "dependencies": { - "sanctuary-def": "0.14.0", + "sanctuary-def": "0.15.0", "sanctuary-type-classes": "8.1.1", "sanctuary-type-identifiers": "2.0.1" }, diff --git a/eslint/es3.js b/eslint/es3.js new file mode 100644 index 00000000..263d19dd --- /dev/null +++ b/eslint/es3.js @@ -0,0 +1,12 @@ +'use strict'; + +module.exports = { + root: true, + extends: ['../node_modules/sanctuary-style/eslint-es3.json'], + rules: { + 'func-call-spacing': ['error', 'always', {allowNewlines: true}], + 'indent': require ('./rules/indent'), + 'no-extra-parens': ['off'], + 'no-unexpected-multiline': ['off'], + }, +}; diff --git a/eslint/es6.js b/eslint/es6.js new file mode 100644 index 00000000..c9eb4821 --- /dev/null +++ b/eslint/es6.js @@ -0,0 +1,41 @@ +'use strict'; + +module.exports = { + root: true, + extends: ['../node_modules/sanctuary-style/eslint-es6.json'], + env: {node: true}, + rules: { + 'func-call-spacing': ['error', 'always', {allowNewlines: true}], + 'indent': require ('./rules/indent'), + 'no-extra-parens': ['off'], + 'no-unexpected-multiline': ['off'], + }, + overrides: [ + { + files: ['*.md'], + plugins: ['markdown'], + globals: { + $: false, + Cons: false, + Just: false, + Left: false, + Nil: false, + Nothing: false, + R: false, + Right: false, + S: false, + Sum: false, + }, + rules: { + 'array-bracket-spacing': ['off'], + 'indent': ['off'], + 'no-eval': ['off'], + 'no-extra-semi': ['off'], + 'no-unused-vars': ['off'], + 'object-shorthand': ['error', 'always'], + 'prefer-template': ['off'], + 'strict': ['off'], + }, + }, + ], +}; diff --git a/eslint/rules/indent.js b/eslint/rules/indent.js new file mode 100644 index 00000000..6192e3d4 --- /dev/null +++ b/eslint/rules/indent.js @@ -0,0 +1,13 @@ +'use strict'; + +const common = require ('sanctuary-style/eslint-common.json'); + + +const indent = (JSON.parse (JSON.stringify (common))).rules['indent']; +indent[2].ignoredNodes.push ( + 'CallExpression', + 'CallExpression > *', + 'CallExpression > ArrowFunctionExpression ArrowFunctionExpression > *', + 'CallExpression > FunctionExpression > BlockStatement' +); +module.exports = indent; diff --git a/index.js b/index.js index 7a6fa963..b773047c 100644 --- a/index.js +++ b/index.js @@ -151,7 +151,7 @@ //. silent failures due to type coercion (at worst). For example: //. //. ```javascript -//. S.add(2, true); +//. S.add (2, true); //. // ! TypeError: Invalid value //. // //. // add :: FiniteNumber -> FiniteNumber -> FiniteNumber @@ -168,7 +168,7 @@ //. Compare this to the behaviour of Ramda's unchecked equivalent: //. //. ```javascript -//. R.add(2, true); +//. R.add (2, true); //. // => 3 //. ``` //. @@ -181,10 +181,10 @@ //. perform type checking: //. //. ```javascript -//. const {create, env} = require('sanctuary'); +//. const {create, env} = require ('sanctuary'); //. //. const checkTypes = process.env.NODE_ENV !== 'production'; -//. const S = create({checkTypes, env}); +//. const S = create ({checkTypes, env}); //. ``` //. //. ## API @@ -195,21 +195,21 @@ /* istanbul ignore else */ if (typeof module === 'object' && typeof module.exports === 'object') { - module.exports = f(require('sanctuary-def'), - require('sanctuary-type-classes'), - require('sanctuary-type-identifiers')); + module.exports = f (require ('sanctuary-def'), + require ('sanctuary-type-classes'), + require ('sanctuary-type-identifiers')); } else if (typeof define === 'function' && define.amd != null) { - define(['sanctuary-def', - 'sanctuary-type-classes', - 'sanctuary-type-identifiers'], - f); + define (['sanctuary-def', + 'sanctuary-type-classes', + 'sanctuary-type-identifiers'], + f); } else { - self.sanctuary = f(self.sanctuaryDef, - self.sanctuaryTypeClasses, - self.sanctuaryTypeIdentifiers); + self.sanctuary = f (self.sanctuaryDef, + self.sanctuaryTypeClasses, + self.sanctuaryTypeIdentifiers); } -}(function($, Z, type) { +} (function($, Z, type) { 'use strict'; @@ -217,23 +217,42 @@ /* istanbul ignore if */ if (typeof __doctest !== 'undefined') { /* eslint-disable no-unused-vars */ - var Nil = __doctest.require('./test/internal/List').Nil; - var Cons = __doctest.require('./test/internal/List').Cons; - var Sum = __doctest.require('./test/internal/Sum'); + var Nil = (__doctest.require ('./test/internal/List')).Nil; + var Cons = (__doctest.require ('./test/internal/List')).Cons; + var Sum = __doctest.require ('./test/internal/Sum'); var S = (function(S) { - return S.create({ + return S.create ({ checkTypes: true, - env: S.env.concat([ - __doctest.require('./test/internal/List').Type($.Unknown), + env: S.env.concat ([ + (__doctest.require ('./test/internal/List')).Type ($.Unknown), Sum.Type ]) }); - }(require('.'))); + } (require ('.'))); /* eslint-enable no-unused-vars */ } - // Fn :: (Type, Type) -> Type - function Fn(x, y) { return $.Function([x, y]); } + // B :: (b -> c) -> (a -> b) -> a -> c + function B(f) { + return function(g) { + return function(x) { + return f (g (x)); + }; + }; + } + + // Fn :: Type -> Type -> Type + function Fn(x) { + return function(y) { + return $.Function ([x, y]); + }; + } + + // get_ :: String -> a -> Maybe b + function get_(key) { + return B (function(obj) { return key in obj ? Just (obj[key]) : Nothing; }) + (toObject); + } // pair :: a -> b -> Pair a b function pair(x) { @@ -244,20 +263,13 @@ // toObject :: a -> Object function toObject(x) { - return x == null ? Object.create(null) : Object(x); + return x == null ? Object.create (null) : Object (x); } // typeEq :: String -> a -> Boolean function typeEq(typeIdent) { return function(x) { - return type(x) === typeIdent; - }; - } - - // uncurry2 :: (a -> b -> c) -> ((a, b) -> c) - function uncurry2(f) { - return function(x, y) { - return f(x)(y); + return type (x) === typeIdent; }; } @@ -274,78 +286,75 @@ } // :: Type - var a = $.TypeVariable('a'); - var b = $.TypeVariable('b'); - var c = $.TypeVariable('c'); - var d = $.TypeVariable('d'); - var e = $.TypeVariable('e'); - var g = $.TypeVariable('g'); - var l = $.TypeVariable('l'); - var r = $.TypeVariable('r'); + var a = $.TypeVariable ('a'); + var b = $.TypeVariable ('b'); + var c = $.TypeVariable ('c'); + var d = $.TypeVariable ('d'); + var e = $.TypeVariable ('e'); + var g = $.TypeVariable ('g'); + var l = $.TypeVariable ('l'); + var r = $.TypeVariable ('r'); // :: Type -> Type - var f = $.UnaryTypeVariable('f'); - var m = $.UnaryTypeVariable('m'); - var t = $.UnaryTypeVariable('t'); - var w = $.UnaryTypeVariable('w'); + var f = $.UnaryTypeVariable ('f'); + var m = $.UnaryTypeVariable ('m'); + var t = $.UnaryTypeVariable ('t'); + var w = $.UnaryTypeVariable ('w'); // :: Type -> Type -> Type - var p = $.BinaryTypeVariable('p'); - var s = $.BinaryTypeVariable('s'); + var p = $.BinaryTypeVariable ('p'); + var s = $.BinaryTypeVariable ('s'); // eitherTypeIdent :: String var eitherTypeIdent = 'sanctuary/Either'; // $Either :: Type -> Type -> Type - var $Either = $.BinaryType( - eitherTypeIdent, - readmeUrl('EitherType'), - typeEq(eitherTypeIdent), - function(either) { return either.isLeft ? [either.value] : []; }, - function(either) { return either.isRight ? [either.value] : []; } - ); + var $Either = $.BinaryType + (eitherTypeIdent) + (readmeUrl ('EitherType')) + (typeEq (eitherTypeIdent)) + (either (of (Array)) (K ([]))) + (either (K ([])) (of (Array))); // maybeTypeIdent :: String var maybeTypeIdent = 'sanctuary/Maybe'; // $Maybe :: Type -> Type - var $Maybe = $.UnaryType( - maybeTypeIdent, - readmeUrl('MaybeType'), - typeEq(maybeTypeIdent), - function(maybe) { return maybe.isJust ? [maybe.value] : []; } - ); + var $Maybe = $.UnaryType + (maybeTypeIdent) + (readmeUrl ('MaybeType')) + (typeEq (maybeTypeIdent)) + (maybe ([]) (of (Array))); // TypeRep :: Type -> Type - var TypeRep = $.UnaryType( - 'sanctuary/TypeRep', - readmeUrl('type-representatives'), - function(x) { - return $.AnyFunction._test(x) || - x != null && $.String._test(x['@@type']); - }, - function(typeRep) { return []; } - ); + var TypeRep = $.UnaryType + ('sanctuary/TypeRep') + (readmeUrl ('type-representatives')) + (function(x) { + return $.AnyFunction._test (x) || + x != null && $.String._test (x['@@type']); + }) + (K ([])); // defaultEnv :: Array Type - var defaultEnv = Z.concat($.env, [ + var defaultEnv = Z.concat ($.env, [ $.FiniteNumber, $.NonZeroFiniteNumber, - $Either($.Unknown, $.Unknown), - Fn($.Unknown, $.Unknown), + $Either ($.Unknown) ($.Unknown), + Fn ($.Unknown) ($.Unknown), $.GlobalRegExp, $.NonGlobalRegExp, $.Integer, $.NonNegativeInteger, - $Maybe($.Unknown), - $.Pair($.Unknown, $.Unknown), + $Maybe ($.Unknown), + $.Array2 ($.Unknown) ($.Unknown), $.RegexFlags, $.ValidDate, $.ValidNumber ]); // Options :: Type - var Options = $.RecordType({checkTypes: $.Boolean, env: $.Array($.Any)}); + var Options = $.RecordType ({checkTypes: $.Boolean, env: $.Array ($.Any)}); var _ = {}; @@ -365,53 +374,53 @@ //. `create` to produce a Sanctuary module which is aware of that type: //. //. ```javascript - //. const {create, env} = require('sanctuary'); - //. const $ = require('sanctuary-def'); - //. const type = require('sanctuary-type-identifiers'); + //. const {create, env} = require ('sanctuary'); + //. const $ = require ('sanctuary-def'); + //. const type = require ('sanctuary-type-identifiers'); //. //. // Identity :: a -> Identity a - //. const Identity = function Identity(x) { - //. if (!(this instanceof Identity)) return new Identity(x); + //. function Identity(x) { + //. if (!(this instanceof Identity)) return new Identity (x); //. this.value = x; - //. }; + //. } //. //. Identity['@@type'] = 'my-package/Identity@1'; //. //. Identity.prototype['fantasy-land/map'] = function(f) { - //. return Identity(f(this.value)); + //. return Identity (f (this.value)); //. }; //. //. // IdentityType :: Type -> Type - //. const IdentityType = $.UnaryType( + //. const IdentityType = $.UnaryType ( //. Identity['@@type'], //. 'http://example.com/my-package#Identity', - //. x => type(x) === Identity['@@type'], + //. x => type (x) === Identity['@@type'], //. identity => [identity.value] //. ); //. - //. const S = create({ + //. const S = create ({ //. checkTypes: process.env.NODE_ENV !== 'production', - //. env: env.concat([IdentityType($.Unknown)]), + //. env: env.concat ([IdentityType ($.Unknown)]), //. }); //. - //. S.map(S.sub(1), Identity(43)); - //. // => Identity(42) + //. S.map (S.sub (1), Identity (43)); + //. // => Identity (42) //. ``` //. //. See also [`env`](#env). function create(opts) { - var def = $.create(opts); + var def = $.create (opts); var S = { env: defaultEnv, - is: def('is', {}, [$.Type, $.Any, $.Boolean], $.test(opts.env)), + is: def ('is') ({}) ([$.Type, $.Any, $.Boolean]) ($.test (opts.env)), MaybeType: $Maybe, Maybe: Maybe, Nothing: Nothing, EitherType: $Either, Either: Either }; - Object.keys(_).forEach(function(name) { - S[name] = def(name, _[name].consts, _[name].types, _[name].impl); + (Object.keys (_)).forEach (function(name) { + S[name] = def (name) (_[name].consts) (_[name].types) (_[name].impl); }); return S; } @@ -433,23 +442,23 @@ //. Returns the result of parsing the [type identifier][] of the given value. //. //. ```javascript - //. > S.type(S.Just(42)) - //. {namespace: Just('sanctuary'), name: 'Maybe', version: 0} + //. > S.type (S.Just (42)) + //. {namespace: Just ('sanctuary'), name: 'Maybe', version: 0} //. - //. > S.type([1, 2, 3]) + //. > S.type ([1, 2, 3]) //. {namespace: Nothing, name: 'Array', version: 0} //. ``` function type_(x) { - var r = type.parse(type(x)); - r.namespace = toMaybe(r.namespace); + var r = type.parse (type (x)); + r.namespace = toMaybe (r.namespace); return r; } _.type = { consts: {}, types: [$.Any, - $.RecordType({namespace: $Maybe($.String), - name: $.String, - version: $.NonNegativeInteger})], + $.RecordType ({namespace: $Maybe ($.String), + name: $.String, + version: $.NonNegativeInteger})], impl: type_ }; @@ -459,10 +468,10 @@ //. See [`$.test`][] for details. //. //. ```javascript - //. > S.is($.Array($.Integer), [1, 2, 3]) + //. > S.is ($.Array ($.Integer)) ([1, 2, 3]) //. true //. - //. > S.is($.Array($.Integer), [1, 2, 3.14]) + //. > S.is ($.Array ($.Integer)) ([1, 2, 3.14]) //. false //. ``` @@ -473,16 +482,16 @@ //. Alias of [`Z.toString`][]. //. //. ```javascript - //. > S.toString(-0) + //. > S.toString (-0) //. '-0' //. - //. > S.toString(['foo', 'bar', 'baz']) + //. > S.toString (['foo', 'bar', 'baz']) //. '["foo", "bar", "baz"]' //. - //. > S.toString({x: 1, y: 2, z: 3}) + //. > S.toString ({x: 1, y: 2, z: 3}) //. '{"x": 1, "y": 2, "z": 3}' //. - //. > S.toString(S.Left(S.Right(S.Just(S.Nothing)))) + //. > S.toString (S.Left (S.Right (S.Just (S.Nothing)))) //. 'Left(Right(Just(Nothing)))' //. ``` _.toString = { @@ -505,103 +514,101 @@ //. module's `equals` function. //. //. ```javascript - //. > S.equals(0, -0) + //. > S.equals (0) (-0) //. true //. - //. > S.equals(NaN, NaN) + //. > S.equals (NaN) (NaN) //. true //. - //. > S.equals(S.Just([1, 2, 3]), S.Just([1, 2, 3])) + //. > S.equals (S.Just ([1, 2, 3])) (S.Just ([1, 2, 3])) //. true //. - //. > S.equals(S.Just([1, 2, 3]), S.Just([1, 2, 4])) + //. > S.equals (S.Just ([1, 2, 3])) (S.Just ([1, 2, 4])) //. false //. ``` _.equals = { consts: {a: [Z.Setoid]}, types: [a, a, $.Boolean], - impl: Z.equals + impl: curry2 (Z.equals) }; - //# lt :: Ord a => a -> (a -> Boolean) + //# lt :: Ord a => a -> a -> Boolean //. //. Returns `true` [iff][] the *second* argument is less than the first - //. according to [`Z.lt`][]. The arguments must be provided one at a time. + //. according to [`Z.lt`][]. //. //. ```javascript - //. > S.filter(S.lt(3), [1, 2, 3, 4, 5]) + //. > S.filter (S.lt (3)) ([1, 2, 3, 4, 5]) //. [1, 2] //. ``` function lt(y) { return function(x) { - return Z.lt(x, y); + return Z.lt (x, y); }; } _.lt = { consts: {a: [Z.Ord]}, - types: [a, $.Predicate(a)], + types: [a, a, $.Boolean], impl: lt }; - //# lte :: Ord a => a -> (a -> Boolean) + //# lte :: Ord a => a -> a -> Boolean //. //. Returns `true` [iff][] the *second* argument is less than or equal to - //. the first according to [`Z.lte`][]. The arguments must be provided one - //. at a time. + //. the first according to [`Z.lte`][]. //. //. ```javascript - //. > S.filter(S.lte(3), [1, 2, 3, 4, 5]) + //. > S.filter (S.lte (3)) ([1, 2, 3, 4, 5]) //. [1, 2, 3] //. ``` function lte(y) { return function(x) { - return Z.lte(x, y); + return Z.lte (x, y); }; } _.lte = { consts: {a: [Z.Ord]}, - types: [a, $.Predicate(a)], + types: [a, a, $.Boolean], impl: lte }; - //# gt :: Ord a => a -> (a -> Boolean) + //# gt :: Ord a => a -> a -> Boolean //. //. Returns `true` [iff][] the *second* argument is greater than the first - //. according to [`Z.gt`][]. The arguments must be provided one at a time. + //. according to [`Z.gt`][]. //. //. ```javascript - //. > S.filter(S.gt(3), [1, 2, 3, 4, 5]) + //. > S.filter (S.gt (3)) ([1, 2, 3, 4, 5]) //. [4, 5] //. ``` function gt(y) { return function(x) { - return Z.gt(x, y); + return Z.gt (x, y); }; } _.gt = { consts: {a: [Z.Ord]}, - types: [a, $.Predicate(a)], + types: [a, a, $.Boolean], impl: gt }; - //# gte :: Ord a => a -> (a -> Boolean) + //# gte :: Ord a => a -> a -> Boolean //. //. Returns `true` [iff][] the *second* argument is greater than or equal - //. to the first according to [`Z.gte`][]. The arguments must be provided - //. one at a time. + //. to the first according to [`Z.gte`][]. //. //. ```javascript - //. > S.filter(S.gte(3), [1, 2, 3, 4, 5]) + //. > S.filter (S.gte (3)) ([1, 2, 3, 4, 5]) //. [3, 4, 5] //. ``` function gte(y) { return function(x) { - return Z.gte(x, y); + return Z.gte (x, y); }; } _.gte = { consts: {a: [Z.Ord]}, - types: [a, $.Predicate(a)], + types: [a, a, $.Boolean], impl: gte }; @@ -612,19 +619,19 @@ //. See also [`max`](#max). //. //. ```javascript - //. > S.min(10, 2) + //. > S.min (10) (2) //. 2 //. - //. > S.min(new Date('1999-12-31'), new Date('2000-01-01')) - //. new Date('1999-12-31') + //. > S.min (new Date ('1999-12-31')) (new Date ('2000-01-01')) + //. new Date ('1999-12-31') //. - //. > S.min('10', '2') + //. > S.min ('10') ('2') //. '10' //. ``` _.min = { consts: {a: [Z.Ord]}, types: [a, a, a], - impl: Z.min + impl: curry2 (Z.min) }; //# max :: Ord a => a -> a -> a @@ -634,19 +641,19 @@ //. See also [`min`](#min). //. //. ```javascript - //. > S.max(10, 2) + //. > S.max (10) (2) //. 10 //. - //. > S.max(new Date('1999-12-31'), new Date('2000-01-01')) - //. new Date('2000-01-01') + //. > S.max (new Date ('1999-12-31')) (new Date ('2000-01-01')) + //. new Date ('2000-01-01') //. - //. > S.max('10', '2') + //. > S.max ('10') ('2') //. '2' //. ``` _.max = { consts: {a: [Z.Ord]}, types: [a, a, a], - impl: Z.max + impl: curry2 (Z.max) }; //# id :: Category c => TypeRep c -> c @@ -654,12 +661,12 @@ //. [Type-safe][sanctuary-def] version of [`Z.id`][]. //. //. ```javascript - //. > S.id(Function)(42) + //. > S.id (Function) (42) //. 42 //. ``` _.id = { consts: {c: [Z.Category]}, - types: [TypeRep(c), c], + types: [TypeRep (c), c], impl: Z.id }; @@ -668,25 +675,25 @@ //. Curried version of [`Z.concat`][]. //. //. ```javascript - //. > S.concat('abc', 'def') + //. > S.concat ('abc') ('def') //. 'abcdef' //. - //. > S.concat([1, 2, 3], [4, 5, 6]) + //. > S.concat ([1, 2, 3]) ([4, 5, 6]) //. [1, 2, 3, 4, 5, 6] //. - //. > S.concat({x: 1, y: 2}, {y: 3, z: 4}) + //. > S.concat ({x: 1, y: 2}) ({y: 3, z: 4}) //. {x: 1, y: 3, z: 4} //. - //. > S.concat(S.Just([1, 2, 3]), S.Just([4, 5, 6])) - //. Just([1, 2, 3, 4, 5, 6]) + //. > S.concat (S.Just ([1, 2, 3])) (S.Just ([4, 5, 6])) + //. Just ([1, 2, 3, 4, 5, 6]) //. - //. > S.concat(Sum(18), Sum(24)) - //. Sum(42) + //. > S.concat (Sum (18)) (Sum (24)) + //. Sum (42) //. ``` _.concat = { consts: {a: [Z.Semigroup]}, types: [a, a, a], - impl: Z.concat + impl: curry2 (Z.concat) }; //# empty :: Monoid a => TypeRep a -> a @@ -694,21 +701,21 @@ //. [Type-safe][sanctuary-def] version of [`Z.empty`][]. //. //. ```javascript - //. > S.empty(String) + //. > S.empty (String) //. '' //. - //. > S.empty(Array) + //. > S.empty (Array) //. [] //. - //. > S.empty(Object) + //. > S.empty (Object) //. {} //. - //. > S.empty(Sum) - //. Sum(0) + //. > S.empty (Sum) + //. Sum (0) //. ``` _.empty = { consts: {a: [Z.Monoid]}, - types: [TypeRep(a), a], + types: [TypeRep (a), a], impl: Z.empty }; @@ -717,8 +724,8 @@ //. [Type-safe][sanctuary-def] version of [`Z.invert`][]. //. //. ```javascript - //. > S.invert(Sum(5)) - //. Sum(-5) + //. > S.invert (Sum (5)) + //. Sum (-5) //. ``` _.invert = { consts: {g: [Z.Group]}, @@ -734,25 +741,30 @@ //. See also [`reject`](#reject). //. //. ```javascript - //. > S.filter(S.odd, [1, 2, 3]) + //. > S.filter (S.odd) ([1, 2, 3]) //. [1, 3] //. - //. > S.filter(S.odd, {x: 1, y: 2, z: 3}) + //. > S.filter (S.odd) ({x: 1, y: 2, z: 3}) //. {x: 1, z: 3} //. - //. > S.filter(S.odd, S.Nothing) + //. > S.filter (S.odd) (S.Nothing) //. Nothing //. - //. > S.filter(S.odd, S.Just(0)) + //. > S.filter (S.odd) (S.Just (0)) //. Nothing //. - //. > S.filter(S.odd, S.Just(1)) - //. Just(1) + //. > S.filter (S.odd) (S.Just (1)) + //. Just (1) //. ``` + function filter(pred) { + return function(filterable) { + return Z.filter (pred, filterable); + }; + } _.filter = { consts: {f: [Z.Filterable]}, - types: [$.Predicate(a), f(a), f(a)], - impl: Z.filter + types: [$.Predicate (a), f (a), f (a)], + impl: filter }; //# reject :: Filterable f => (a -> Boolean) -> f a -> f a @@ -763,25 +775,25 @@ //. See also [`filter`](#filter). //. //. ```javascript - //. > S.reject(S.odd, [1, 2, 3]) + //. > S.reject (S.odd) ([1, 2, 3]) //. [2] //. - //. > S.reject(S.odd, {x: 1, y: 2, z: 3}) + //. > S.reject (S.odd) ({x: 1, y: 2, z: 3}) //. {y: 2} //. - //. > S.reject(S.odd, S.Nothing) + //. > S.reject (S.odd) (S.Nothing) //. Nothing //. - //. > S.reject(S.odd, S.Just(0)) - //. Just(0) + //. > S.reject (S.odd) (S.Just (0)) + //. Just (0) //. - //. > S.reject(S.odd, S.Just(1)) + //. > S.reject (S.odd) (S.Just (1)) //. Nothing //. ``` _.reject = { consts: {f: [Z.Filterable]}, - types: [$.Predicate(a), f(a), f(a)], - impl: Z.reject + types: [$.Predicate (a), f (a), f (a)], + impl: curry2 (Z.reject) }; //# takeWhile :: Filterable f => (a -> Boolean) -> f a -> f a @@ -792,16 +804,16 @@ //. See also [`dropWhile`](#dropWhile). //. //. ```javascript - //. > S.takeWhile(S.odd, [3, 3, 3, 7, 6, 3, 5, 4]) + //. > S.takeWhile (S.odd) ([3, 3, 3, 7, 6, 3, 5, 4]) //. [3, 3, 3, 7] //. - //. > S.takeWhile(S.even, [3, 3, 3, 7, 6, 3, 5, 4]) + //. > S.takeWhile (S.even) ([3, 3, 3, 7, 6, 3, 5, 4]) //. [] //. ``` _.takeWhile = { consts: {f: [Z.Filterable]}, - types: [$.Predicate(a), f(a), f(a)], - impl: Z.takeWhile + types: [$.Predicate (a), f (a), f (a)], + impl: curry2 (Z.takeWhile) }; //# dropWhile :: Filterable f => (a -> Boolean) -> f a -> f a @@ -812,16 +824,16 @@ //. See also [`takeWhile`](#takeWhile). //. //. ```javascript - //. > S.dropWhile(S.odd, [3, 3, 3, 7, 6, 3, 5, 4]) + //. > S.dropWhile (S.odd) ([3, 3, 3, 7, 6, 3, 5, 4]) //. [6, 3, 5, 4] //. - //. > S.dropWhile(S.even, [3, 3, 3, 7, 6, 3, 5, 4]) + //. > S.dropWhile (S.even) ([3, 3, 3, 7, 6, 3, 5, 4]) //. [3, 3, 3, 7, 6, 3, 5, 4] //. ``` _.dropWhile = { consts: {f: [Z.Filterable]}, - types: [$.Predicate(a), f(a), f(a)], - impl: Z.dropWhile + types: [$.Predicate (a), f (a), f (a)], + impl: curry2 (Z.dropWhile) }; //# map :: Functor f => (a -> b) -> f a -> f b @@ -829,17 +841,17 @@ //. Curried version of [`Z.map`][]. //. //. ```javascript - //. > S.map(Math.sqrt, [1, 4, 9]) + //. > S.map (Math.sqrt) ([1, 4, 9]) //. [1, 2, 3] //. - //. > S.map(Math.sqrt, {x: 1, y: 4, z: 9}) + //. > S.map (Math.sqrt) ({x: 1, y: 4, z: 9}) //. {x: 1, y: 2, z: 3} //. - //. > S.map(Math.sqrt, S.Just(9)) - //. Just(3) + //. > S.map (Math.sqrt) (S.Just (9)) + //. Just (3) //. - //. > S.map(Math.sqrt, S.Right(9)) - //. Right(3) + //. > S.map (Math.sqrt) (S.Right (9)) + //. Right (3) //. ``` //. //. Replacing `Functor f => f` with `Function x` produces the B combinator @@ -853,13 +865,18 @@ //. (b -> c) -> (a -> b) -> (a -> c) //. //. ```javascript - //. > S.map(Math.sqrt, S.add(1))(99) + //. > S.map (Math.sqrt) (S.add (1)) (99) //. 10 //. ``` + function map(f) { + return function(functor) { + return Z.map (f, functor); + }; + } _.map = { consts: {f: [Z.Functor]}, - types: [Fn(a, b), f(a), f(b)], - impl: Z.map + types: [Fn (a) (b), f (a), f (b)], + impl: map }; //# bimap :: Bifunctor f => (a -> b) -> (c -> d) -> f a c -> f b d @@ -867,16 +884,16 @@ //. Curried version of [`Z.bimap`][]. //. //. ```javascript - //. > S.bimap(S.toUpper, Math.sqrt, S.Left('foo')) - //. Left('FOO') + //. > S.bimap (S.toUpper) (Math.sqrt) (S.Left ('foo')) + //. Left ('FOO') //. - //. > S.bimap(S.toUpper, Math.sqrt, S.Right(64)) - //. Right(8) + //. > S.bimap (S.toUpper) (Math.sqrt) (S.Right (64)) + //. Right (8) //. ``` _.bimap = { consts: {p: [Z.Bifunctor]}, - types: [Fn(a, b), Fn(c, d), p(a, c), p(b, d)], - impl: Z.bimap + types: [Fn (a) (b), Fn (c) (d), p (a) (c), p (b) (d)], + impl: curry3 (Z.bimap) }; //# mapLeft :: Bifunctor f => (a -> b) -> f a c -> f b c @@ -885,16 +902,16 @@ //. side of a Bifunctor. //. //. ```javascript - //. > S.mapLeft(S.toUpper, S.Left('foo')) - //. Left('FOO') + //. > S.mapLeft (S.toUpper) (S.Left ('foo')) + //. Left ('FOO') //. - //. > S.mapLeft(S.toUpper, S.Right(64)) - //. Right(64) + //. > S.mapLeft (S.toUpper) (S.Right (64)) + //. Right (64) //. ``` _.mapLeft = { consts: {p: [Z.Bifunctor]}, - types: [Fn(a, b), p(a, c), p(b, c)], - impl: Z.mapLeft + types: [Fn (a) (b), p (a) (c), p (b) (c)], + impl: curry2 (Z.mapLeft) }; //# promap :: Profunctor p => (a -> b) -> (c -> d) -> p b c -> p a d @@ -902,13 +919,13 @@ //. Curried version of [`Z.promap`][]. //. //. ```javascript - //. > S.promap(Math.abs, S.add(1), Math.sqrt)(-100) + //. > S.promap (Math.abs) (S.add (1)) (Math.sqrt) (-100) //. 11 //. ``` _.promap = { consts: {p: [Z.Profunctor]}, - types: [Fn(a, b), Fn(c, d), p(b, c), p(a, d)], - impl: Z.promap + types: [Fn (a) (b), Fn (c) (d), p (b) (c), p (a) (d)], + impl: curry3 (Z.promap) }; //# alt :: Alt f => f a -> f a -> f a @@ -916,22 +933,22 @@ //. Curried version of [`Z.alt`][]. //. //. ```javascript - //. > S.alt(S.Nothing, S.Just(1)) - //. Just(1) + //. > S.alt (S.Nothing) (S.Just (1)) + //. Just (1) //. - //. > S.alt(S.Just(2), S.Just(3)) - //. Just(2) + //. > S.alt (S.Just (2)) (S.Just (3)) + //. Just (2) //. - //. > S.alt(S.Left('X'), S.Right(1)) - //. Right(1) + //. > S.alt (S.Left ('X')) (S.Right (1)) + //. Right (1) //. - //. > S.alt(S.Right(2), S.Right(3)) - //. Right(2) + //. > S.alt (S.Right (2)) (S.Right (3)) + //. Right (2) //. ``` _.alt = { consts: {f: [Z.Alt]}, - types: [f(a), f(a), f(a)], - impl: Z.alt + types: [f (a), f (a), f (a)], + impl: curry2 (Z.alt) }; //# zero :: Plus f => TypeRep f -> f a @@ -939,18 +956,18 @@ //. [Type-safe][sanctuary-def] version of [`Z.zero`][]. //. //. ```javascript - //. > S.zero(Array) + //. > S.zero (Array) //. [] //. - //. > S.zero(Object) + //. > S.zero (Object) //. {} //. - //. > S.zero(S.Maybe) + //. > S.zero (S.Maybe) //. Nothing //. ``` _.zero = { consts: {f: [Z.Plus]}, - types: [TypeRep($.TypeVariable('f')), f(a)], + types: [TypeRep ($.TypeVariable ('f')), f (a)], impl: Z.zero }; @@ -965,18 +982,24 @@ //. otherwise. //. //. ```javascript - //. > S.reduce(S.add, 0, [1, 2, 3, 4, 5]) + //. > S.reduce (S.add) (0) ([1, 2, 3, 4, 5]) //. 15 //. - //. > S.reduce(xs => x => [x].concat(xs), [], [1, 2, 3, 4, 5]) + //. > S.reduce (xs => x => S.prepend (x) (xs)) ([]) ([1, 2, 3, 4, 5]) //. [5, 4, 3, 2, 1] //. ``` - function reduce(f, initial, foldable) { - return Z.reduce(uncurry2(f), initial, foldable); + function reduce(f) { + return function(initial) { + return function(foldable) { + return Z.reduce (function(y, x) { return f (y) (x); }, + initial, + foldable); + }; + }; } _.reduce = { consts: {f: [Z.Foldable]}, - types: [Fn(a, Fn(b, a)), a, f(b), a], + types: [Fn (a) (Fn (b) (a)), a, f (b), a], impl: reduce }; @@ -985,28 +1008,28 @@ //. Curried version of [`Z.traverse`][]. //. //. ```javascript - //. > S.traverse(Array, S.words, S.Just('foo bar baz')) - //. [Just('foo'), Just('bar'), Just('baz')] + //. > S.traverse (Array) (S.words) (S.Just ('foo bar baz')) + //. [Just ('foo'), Just ('bar'), Just ('baz')] //. - //. > S.traverse(Array, S.words, S.Nothing) + //. > S.traverse (Array) (S.words) (S.Nothing) //. [Nothing] //. - //. > S.traverse(S.Maybe, S.parseInt(16), ['A', 'B', 'C']) - //. Just([10, 11, 12]) + //. > S.traverse (S.Maybe) (S.parseInt (16)) (['A', 'B', 'C']) + //. Just ([10, 11, 12]) //. - //. > S.traverse(S.Maybe, S.parseInt(16), ['A', 'B', 'C', 'X']) + //. > S.traverse (S.Maybe) (S.parseInt (16)) (['A', 'B', 'C', 'X']) //. Nothing //. - //. > S.traverse(S.Maybe, S.parseInt(16), {a: 'A', b: 'B', c: 'C'}) - //. Just({a: 10, b: 11, c: 12}) + //. > S.traverse (S.Maybe) (S.parseInt (16)) ({a: 'A', b: 'B', c: 'C'}) + //. Just ({a: 10, b: 11, c: 12}) //. - //. > S.traverse(S.Maybe, S.parseInt(16), {a: 'A', b: 'B', c: 'C', x: 'X'}) + //. > S.traverse (S.Maybe) (S.parseInt (16)) ({a: 'A', b: 'B', c: 'C', x: 'X'}) //. Nothing //. ``` _.traverse = { consts: {f: [Z.Applicative], t: [Z.Traversable]}, - types: [TypeRep($.TypeVariable('f')), Fn(a, f(b)), t(a), f(t(b))], - impl: Z.traverse + types: [TypeRep ($.TypeVariable ('f')), Fn (a) (f (b)), t (a), f (t (b))], + impl: curry3 (Z.traverse) }; //# sequence :: (Applicative f, Traversable t) => TypeRep f -> t (f a) -> f (t a) @@ -1015,25 +1038,25 @@ //. to produce an `f (t a)`. //. //. ```javascript - //. > S.sequence(Array, S.Just([1, 2, 3])) - //. [Just(1), Just(2), Just(3)] + //. > S.sequence (Array) (S.Just ([1, 2, 3])) + //. [Just (1), Just (2), Just (3)] //. - //. > S.sequence(S.Maybe, [S.Just(1), S.Just(2), S.Just(3)]) - //. Just([1, 2, 3]) + //. > S.sequence (S.Maybe) ([S.Just (1), S.Just (2), S.Just (3)]) + //. Just ([1, 2, 3]) //. - //. > S.sequence(S.Maybe, [S.Just(1), S.Just(2), S.Nothing]) + //. > S.sequence (S.Maybe) ([S.Just (1), S.Just (2), S.Nothing]) //. Nothing //. - //. > S.sequence(S.Maybe, {a: S.Just(1), b: S.Just(2), c: S.Just(3)}) - //. Just({a: 1, b: 2, c: 3}) + //. > S.sequence (S.Maybe) ({a: S.Just (1), b: S.Just (2), c: S.Just (3)}) + //. Just ({a: 1, b: 2, c: 3}) //. - //. > S.sequence(S.Maybe, {a: S.Just(1), b: S.Just(2), c: S.Nothing}) + //. > S.sequence (S.Maybe) ({a: S.Just (1), b: S.Just (2), c: S.Nothing}) //. Nothing //. ``` _.sequence = { consts: {f: [Z.Applicative], t: [Z.Traversable]}, - types: [TypeRep($.TypeVariable('f')), t(f(a)), f(t(a))], - impl: Z.sequence + types: [TypeRep ($.TypeVariable ('f')), t (f (a)), f (t (a))], + impl: curry2 (Z.sequence) }; //# ap :: Apply f => f (a -> b) -> f a -> f b @@ -1041,14 +1064,14 @@ //. Curried version of [`Z.ap`][]. //. //. ```javascript - //. > S.ap([Math.sqrt, x => x * x], [1, 4, 9, 16, 25]) + //. > S.ap ([Math.sqrt, x => x * x]) ([1, 4, 9, 16, 25]) //. [1, 2, 3, 4, 5, 1, 16, 81, 256, 625] //. - //. > S.ap({x: Math.sqrt, y: S.add(1), z: S.sub(1)}, {w: 4, x: 4, y: 4}) + //. > S.ap ({x: Math.sqrt, y: S.add (1), z: S.sub (1)}) ({w: 4, x: 4, y: 4}) //. {x: 2, y: 5} //. - //. > S.ap(S.Just(Math.sqrt), S.Just(64)) - //. Just(8) + //. > S.ap (S.Just (Math.sqrt)) (S.Just (64)) + //. Just (8) //. ``` //. //. Replacing `Apply f => f` with `Function x` produces the S combinator @@ -1062,13 +1085,13 @@ //. (a -> b -> c) -> (a -> b) -> (a -> c) //. //. ```javascript - //. > S.ap(s => n => s.slice(0, n), s => Math.ceil(s.length / 2))('Haskell') + //. > S.ap (s => n => s.slice (0, n)) (s => Math.ceil (s.length / 2)) ('Haskell') //. 'Hask' //. ``` _.ap = { consts: {f: [Z.Apply]}, - types: [f(Fn(a, b)), f(a), f(b)], - impl: Z.ap + types: [f (Fn (a) (b)), f (a), f (b)], + impl: curry2 (Z.ap) }; //# lift2 :: Apply f => (a -> b -> c) -> f a -> f b -> f c @@ -1077,22 +1100,22 @@ //. [Apply][]s. //. //. ```javascript - //. > S.lift2(S.add, S.Just(2), S.Just(3)) - //. Just(5) + //. > S.lift2 (S.add) (S.Just (2)) (S.Just (3)) + //. Just (5) //. - //. > S.lift2(S.add, S.Just(2), S.Nothing) + //. > S.lift2 (S.add) (S.Just (2)) (S.Nothing) //. Nothing //. - //. > S.lift2(S.and, S.Just(true), S.Just(true)) - //. Just(true) + //. > S.lift2 (S.and) (S.Just (true)) (S.Just (true)) + //. Just (true) //. - //. > S.lift2(S.and, S.Just(true), S.Just(false)) - //. Just(false) + //. > S.lift2 (S.and) (S.Just (true)) (S.Just (false)) + //. Just (false) //. ``` _.lift2 = { consts: {f: [Z.Apply]}, - types: [Fn(a, Fn(b, c)), f(a), f(b), f(c)], - impl: Z.lift2 + types: [Fn (a) (Fn (b) (c)), f (a), f (b), f (c)], + impl: curry3 (Z.lift2) }; //# lift3 :: Apply f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d @@ -1101,16 +1124,16 @@ //. [Apply][]s. //. //. ```javascript - //. > S.lift3(S.reduce, S.Just(S.add), S.Just(0), S.Just([1, 2, 3])) - //. Just(6) + //. > S.lift3 (S.reduce) (S.Just (S.add)) (S.Just (0)) (S.Just ([1, 2, 3])) + //. Just (6) //. - //. > S.lift3(S.reduce, S.Just(S.add), S.Just(0), S.Nothing) + //. > S.lift3 (S.reduce) (S.Just (S.add)) (S.Just (0)) (S.Nothing) //. Nothing //. ``` _.lift3 = { consts: {f: [Z.Apply]}, - types: [Fn(a, Fn(b, Fn(c, d))), f(a), f(b), f(c), f(d)], - impl: Z.lift3 + types: [Fn (a) (Fn (b) (Fn (c) (d))), f (a), f (b), f (c), f (d)], + impl: curry4 (Z.lift3) }; //# apFirst :: Apply f => f a -> f b -> f a @@ -1122,16 +1145,16 @@ //. See also [`apSecond`](#apSecond). //. //. ```javascript - //. > S.apFirst([1, 2], [3, 4]) + //. > S.apFirst ([1, 2]) ([3, 4]) //. [1, 1, 2, 2] //. - //. > S.apFirst(S.Just(1), S.Just(2)) - //. Just(1) + //. > S.apFirst (S.Just (1)) (S.Just (2)) + //. Just (1) //. ``` _.apFirst = { consts: {f: [Z.Apply]}, - types: [f(a), f(b), f(a)], - impl: Z.apFirst + types: [f (a), f (b), f (a)], + impl: curry2 (Z.apFirst) }; //# apSecond :: Apply f => f a -> f b -> f b @@ -1143,16 +1166,16 @@ //. See also [`apFirst`](#apFirst). //. //. ```javascript - //. > S.apSecond([1, 2], [3, 4]) + //. > S.apSecond ([1, 2]) ([3, 4]) //. [3, 4, 3, 4] //. - //. > S.apSecond(S.Just(1), S.Just(2)) - //. Just(2) + //. > S.apSecond (S.Just (1)) (S.Just (2)) + //. Just (2) //. ``` _.apSecond = { consts: {f: [Z.Apply]}, - types: [f(a), f(b), f(b)], - impl: Z.apSecond + types: [f (a), f (b), f (b)], + impl: curry2 (Z.apSecond) }; //# of :: Applicative f => TypeRep f -> a -> f a @@ -1160,22 +1183,27 @@ //. Curried version of [`Z.of`][]. //. //. ```javascript - //. > S.of(Array, 42) + //. > S.of (Array) (42) //. [42] //. - //. > S.of(Function, 42)(null) + //. > S.of (Function) (42) (null) //. 42 //. - //. > S.of(S.Maybe, 42) - //. Just(42) + //. > S.of (S.Maybe) (42) + //. Just (42) //. - //. > S.of(S.Either, 42) - //. Right(42) + //. > S.of (S.Either) (42) + //. Right (42) //. ``` + function of(typeRep) { + return function(x) { + return Z.of (typeRep, x); + }; + } _.of = { consts: {f: [Z.Applicative]}, - types: [TypeRep($.TypeVariable('f')), a, f(a)], - impl: Z.of + types: [TypeRep ($.TypeVariable ('f')), a, f (a)], + impl: of }; //# chain :: Chain m => (a -> m b) -> m a -> m b @@ -1183,22 +1211,22 @@ //. Curried version of [`Z.chain`][]. //. //. ```javascript - //. > S.chain(x => [x, x], [1, 2, 3]) + //. > S.chain (x => [x, x]) ([1, 2, 3]) //. [1, 1, 2, 2, 3, 3] //. - //. > S.chain(n => s => s.slice(0, n), s => Math.ceil(s.length / 2))('slice') + //. > S.chain (n => s => s.slice (0, n)) (s => Math.ceil (s.length / 2)) ('slice') //. 'sli' //. - //. > S.chain(S.parseInt(10), S.Just('123')) - //. Just(123) + //. > S.chain (S.parseInt (10)) (S.Just ('123')) + //. Just (123) //. - //. > S.chain(S.parseInt(10), S.Just('XXX')) + //. > S.chain (S.parseInt (10)) (S.Just ('XXX')) //. Nothing //. ``` _.chain = { consts: {m: [Z.Chain]}, - types: [Fn(a, m(b)), m(a), m(b)], - impl: Z.chain + types: [Fn (a) (m (b)), m (a), m (b)], + impl: curry2 (Z.chain) }; //# join :: Chain m => m (m a) -> m a @@ -1207,14 +1235,14 @@ //. Removes one level of nesting from a nested monadic structure. //. //. ```javascript - //. > S.join([[1], [2], [3]]) + //. > S.join ([[1], [2], [3]]) //. [1, 2, 3] //. - //. > S.join([[[1, 2, 3]]]) + //. > S.join ([[[1, 2, 3]]]) //. [[1, 2, 3]] //. - //. > S.join(S.Just(S.Just(1))) - //. S.Just(1) + //. > S.join (S.Just (S.Just (1))) + //. S.Just (1) //. ``` //. //. Replacing `Chain m => m` with `Function x` produces the W combinator @@ -1225,12 +1253,12 @@ //. (x -> x -> a) -> (x -> a) //. //. ```javascript - //. > S.join(S.concat)('abc') + //. > S.join (S.concat) ('abc') //. 'abcabc' //. ``` _.join = { consts: {m: [Z.Chain]}, - types: [m(m(a)), m(a)], + types: [m (m (a)), m (a)], impl: Z.join }; @@ -1241,21 +1269,28 @@ //. use of the Either type to indicate completion (via a Right). //. //. ```javascript - //. > S.chainRec(Array, - //. . s => s.length === 2 ? S.map(S.Right, [s + '!', s + '?']) - //. . : S.map(S.Left, [s + 'o', s + 'n']), - //. . '') + //. > S.chainRec (Array) + //. . (s => s.length === 2 ? S.map (S.Right) ([s + '!', s + '?']) + //. . : S.map (S.Left) ([s + 'o', s + 'n'])) + //. . ('') //. ['oo!', 'oo?', 'on!', 'on?', 'no!', 'no?', 'nn!', 'nn?'] //. ``` - function chainRec(typeRep, f, x) { - function step(next, done, x) { - return Z.map(function(e) { return either(next, done, e); }, f(x)); - } - return Z.chainRec(typeRep, step, x); + function chainRec(typeRep) { + return function(f) { + return function(x) { + return Z.chainRec (typeRep, step, x); + }; + function step(next, done, x) { + return Z.map (either (next) (done), f (x)); + } + }; } _.chainRec = { consts: {m: [Z.ChainRec]}, - types: [TypeRep($.TypeVariable('m')), Fn(a, m($Either(a, b))), a, m(b)], + types: [TypeRep ($.TypeVariable ('m')), + Fn (a) (m ($Either (a) (b))), + a, + m (b)], impl: chainRec }; @@ -1264,16 +1299,16 @@ //. Curried version of [`Z.extend`][]. //. //. ```javascript - //. > S.extend(S.joinWith(''), ['x', 'y', 'z']) + //. > S.extend (S.joinWith ('')) (['x', 'y', 'z']) //. ['xyz', 'yz', 'z'] //. - //. > S.extend(f => f([3, 4]), S.reverse)([1, 2]) + //. > S.extend (f => f ([3, 4])) (S.reverse) ([1, 2]) //. [4, 3, 2, 1] //. ``` _.extend = { consts: {w: [Z.Extend]}, - types: [Fn(w(a), b), w(a), w(b)], - impl: Z.extend + types: [Fn (w (a)) (b), w (a), w (b)], + impl: curry2 (Z.extend) }; //# duplicate :: Extend w => w a -> w (w a) @@ -1282,21 +1317,21 @@ //. Adds one level of nesting to a comonadic structure. //. //. ```javascript - //. > S.duplicate(S.Just(1)) - //. S.Just(S.Just(1)) + //. > S.duplicate (S.Just (1)) + //. S.Just (S.Just (1)) //. - //. > S.duplicate([1]) + //. > S.duplicate ([1]) //. [[1]] //. - //. > S.duplicate([1, 2, 3]) + //. > S.duplicate ([1, 2, 3]) //. [[1, 2, 3], [2, 3], [3]] //. - //. > S.duplicate(S.reverse)([1, 2])([3, 4]) + //. > S.duplicate (S.reverse) ([1, 2]) ([3, 4]) //. [4, 3, 2, 1] //. ``` _.duplicate = { consts: {w: [Z.Extend]}, - types: [w(a), w(w(a))], + types: [w (a), w (w (a))], impl: Z.duplicate }; @@ -1305,7 +1340,7 @@ //. [Type-safe][sanctuary-def] version of [`Z.extract`][]. _.extract = { consts: {w: [Z.Comonad]}, - types: [w(a), a], + types: [w (a), a], impl: Z.extract }; @@ -1314,13 +1349,13 @@ //. [Type-safe][sanctuary-def] version of [`Z.contramap`][]. //. //. ```javascript - //. > S.contramap(s => s.length, Math.sqrt)('Sanctuary') + //. > S.contramap (s => s.length) (Math.sqrt) ('Sanctuary') //. 3 //. ``` _.contramap = { consts: {f: [Z.Contravariant]}, - types: [Fn(b, a), f(a), f(b)], - impl: Z.contramap + types: [Fn (b) (a), f (a), f (b)], + impl: curry2 (Z.contramap) }; //. ### Combinator @@ -1331,7 +1366,7 @@ //. function. //. //. ```javascript - //. > S.I('foo') + //. > S.I ('foo') //. 'foo' //. ``` function I(x) { @@ -1349,14 +1384,16 @@ //. Haskell's `const` function. //. //. ```javascript - //. > S.K('foo', 'bar') + //. > S.K ('foo') ('bar') //. 'foo' //. - //. > S.map(S.K(42), S.range(0, 5)) + //. > S.map (S.K (42)) (S.range (0) (5)) //. [42, 42, 42, 42, 42] //. ``` - function K(x, y) { - return x; + function K(x) { + return function(y) { + return x; + }; } _.K = { consts: {}, @@ -1371,18 +1408,20 @@ //. `(&)` function. //. //. ```javascript - //. > S.T(42, S.add(1)) + //. > S.T (42) (S.add (1)) //. 43 //. - //. > S.map(S.T(100), [S.add(1), Math.sqrt]) + //. > S.map (S.T (100)) ([S.add (1), Math.sqrt]) //. [101, 10] //. ``` - function T(x, f) { - return f(x); + function T(x) { + return function(f) { + return f (x); + }; } _.T = { consts: {}, - types: [a, Fn(a, b), b], + types: [a, Fn (a) (b), b], impl: T }; @@ -1393,18 +1432,19 @@ //. Curries the given binary function. //. //. ```javascript - //. > S.map(S.curry2(Math.pow)(10), [1, 2, 3]) - //. [10, 100, 1000] - //. - //. > S.map(S.curry2(Math.pow, 10), [1, 2, 3]) + //. > S.map (S.curry2 (Math.pow) (10)) ([1, 2, 3]) //. [10, 100, 1000] //. ``` - function curry2(f, x, y) { - return f(x, y); + function curry2(f) { + return function(x) { + return function(y) { + return f (x, y); + }; + }; } _.curry2 = { consts: {}, - types: [$.Function([a, b, c]), a, b, c], + types: [$.Function ([a, b, c]), a, b, c], impl: curry2 }; @@ -1413,22 +1453,25 @@ //. Curries the given ternary function. //. //. ```javascript - //. > const replaceString = S.curry3((what, replacement, string) => - //. . string.replace(what, replacement) + //. > const replaceString = S.curry3 ((what, replacement, string) => + //. . string.replace (what, replacement) //. . ) //. - //. > replaceString('banana')('orange')('banana icecream') - //. 'orange icecream' - //. - //. > replaceString('banana', 'orange', 'banana icecream') + //. > replaceString ('banana') ('orange') ('banana icecream') //. 'orange icecream' //. ``` - function curry3(f, x, y, z) { - return f(x, y, z); + function curry3(f) { + return function(x) { + return function(y) { + return function(z) { + return f (x, y, z); + }; + }; + }; } _.curry3 = { consts: {}, - types: [$.Function([a, b, c, d]), a, b, c, d], + types: [$.Function ([a, b, c, d]), a, b, c, d], impl: curry3 }; @@ -1437,22 +1480,27 @@ //. Curries the given quaternary function. //. //. ```javascript - //. > const createRect = S.curry4((x, y, width, height) => + //. > const createRect = S.curry4 ((x, y, width, height) => //. . ({x, y, width, height}) //. . ) //. - //. > createRect(0)(0)(10)(10) - //. {x: 0, y: 0, width: 10, height: 10} - //. - //. > createRect(0, 0, 10, 10) + //. > createRect (0) (0) (10) (10) //. {x: 0, y: 0, width: 10, height: 10} //. ``` - function curry4(f, w, x, y, z) { - return f(w, x, y, z); + function curry4(f) { + return function(w) { + return function(x) { + return function(y) { + return function(z) { + return f (w, x, y, z); + }; + }; + }; + }; } _.curry4 = { consts: {}, - types: [$.Function([a, b, c, d, e]), a, b, c, d, e], + types: [$.Function ([a, b, c, d, e]), a, b, c, d, e], impl: curry4 }; @@ -1461,26 +1509,33 @@ //. Curries the given quinary function. //. //. ```javascript - //. > const toUrl = S.curry5((protocol, creds, hostname, port, pathname) => + //. > const toUrl = S.curry5 ((protocol, creds, hostname, port, pathname) => //. . protocol + '//' + - //. . S.maybe('', _ => _.username + ':' + _.password + '@', creds) + + //. . S.maybe ('') (S.flip (S.concat) ('@')) (creds) + //. . hostname + - //. . S.maybe('', S.concat(':'), port) + + //. . S.maybe ('') (S.concat (':')) (port) + //. . pathname //. . ) //. - //. > toUrl('https:')(S.Nothing)('example.com')(S.Just('443'))('/foo/bar') - //. 'https://example.com:443/foo/bar' - //. - //. > toUrl('https:', S.Nothing, 'example.com', S.Just('443'), '/foo/bar') + //. > toUrl ('https:') (S.Nothing) ('example.com') (S.Just ('443')) ('/foo/bar') //. 'https://example.com:443/foo/bar' //. ``` - function curry5(f, v, w, x, y, z) { - return f(v, w, x, y, z); + function curry5(f) { + return function(v) { + return function(w) { + return function(x) { + return function(y) { + return function(z) { + return f (v, w, x, y, z); + }; + }; + }; + }; + }; } _.curry5 = { consts: {}, - types: [$.Function([a, b, c, d, e, r]), a, b, c, d, e, r], + types: [$.Function ([a, b, c, d, e, r]), a, b, c, d, e, r], impl: curry5 }; @@ -1492,15 +1547,19 @@ //. This is the C combinator from combinatory logic. //. //. ```javascript - //. > S.flip(S.concat, 'foo', 'bar') + //. > S.flip (S.concat) ('foo') ('bar') //. 'barfoo' //. ``` - function flip(f, x, y) { - return f(y)(x); + function flip(f) { + return function(x) { + return function(y) { + return f (y) (x); + }; + }; } _.flip = { consts: {}, - types: [Fn(a, Fn(b, c)), b, a, c], + types: [Fn (a) (Fn (b) (c)), b, a, c], impl: flip }; @@ -1519,13 +1578,13 @@ //. See also [`pipe`](#pipe). //. //. ```javascript - //. > S.compose(Math.sqrt, S.add(1))(99) + //. > S.compose (Math.sqrt) (S.add (1)) (99) //. 10 //. ``` _.compose = { consts: {s: [Z.Semigroupoid]}, - types: [s(b, c), s(a, b), s(a, c)], - impl: Z.compose + types: [s (b) (c), s (a) (b), s (a) (c)], + impl: curry2 (Z.compose) }; //# pipe :: Foldable f => f (Any -> Any) -> a -> b @@ -1538,15 +1597,17 @@ //. of functions. `pipe([f, g, h], x)` is equivalent to `h(g(f(x)))`. //. //. ```javascript - //. > S.pipe([S.add(1), Math.sqrt, S.sub(1)], 99) + //. > S.pipe ([S.add (1), Math.sqrt, S.sub (1)]) (99) //. 9 //. ``` - function pipe(fs, x) { - return Z.reduce(function(x, f) { return f(x); }, x, fs); + function pipe(fs) { + return function(x) { + return reduce (T) (x) (fs); + }; } _.pipe = { consts: {f: [Z.Foldable]}, - types: [f(Fn($.Any, $.Any)), a, b], + types: [f (Fn ($.Any) ($.Any)), a, b], impl: pipe }; @@ -1561,15 +1622,17 @@ //. `chain(h, chain(g, chain(f, x)))`. //. //. ```javascript - //. > S.pipeK([S.tail, S.tail, S.head], S.Just([1, 2, 3, 4])) - //. Just(3) + //. > S.pipeK ([S.tail, S.tail, S.head]) (S.Just ([1, 2, 3, 4])) + //. Just (3) //. ``` - function pipeK(fs, x) { - return Z.reduce(function(x, f) { return Z.chain(f, x); }, x, fs); + function pipeK(fs) { + return function(x) { + return Z.reduce (function(x, f) { return Z.chain (f, x); }, x, fs); + }; } _.pipeK = { consts: {f: [Z.Foldable], m: [Z.Chain]}, - types: [f(Fn($.Any, m($.Any))), m(a), m(b)], + types: [f (Fn ($.Any) (m ($.Any))), m (a), m (b)], impl: pipeK }; @@ -1581,15 +1644,21 @@ //. This is the P combinator from combinatory logic. //. //. ```javascript - //. > S.on(S.concat, S.reverse, [1, 2, 3], [4, 5, 6]) + //. > S.on (S.concat) (S.reverse) ([1, 2, 3]) ([4, 5, 6]) //. [3, 2, 1, 6, 5, 4] //. ``` - function on(f, g, x, y) { - return f(g(x))(g(y)); + function on(f) { + return function(g) { + return function(x) { + return function(y) { + return f (g (x)) (g (y)); + }; + }; + }; } _.on = { consts: {}, - types: [Fn(b, Fn(b, c)), Fn(a, b), a, a, c], + types: [Fn (b) (Fn (b) (c)), Fn (a) (b), a, a, c], impl: on }; @@ -1619,15 +1688,15 @@ // Add "fantasy-land/concat" method conditionally so that Just('abc') // satisfies the requirements of Semigroup but Just(123) does not. - if (this.isNothing || Z.Semigroup.test(this.value)) { + if (this.isNothing || Z.Semigroup.test (this.value)) { this['fantasy-land/concat'] = Maybe$prototype$concat; } - if (this.isNothing || Z.Setoid.test(this.value)) { + if (this.isNothing || Z.Setoid.test (this.value)) { this['fantasy-land/equals'] = Maybe$prototype$equals; } - if (this.isNothing || Z.Ord.test(this.value)) { + if (this.isNothing || Z.Ord.test (this.value)) { this['fantasy-land/lte'] = Maybe$prototype$lte; } } @@ -1640,22 +1709,22 @@ //. > S.Nothing //. Nothing //. ``` - var Nothing = new _Maybe('Nothing'); + var Nothing = new _Maybe ('Nothing'); //# Just :: a -> Maybe a //. //. Takes a value of any type and returns a Just with the given value. //. //. ```javascript - //. > S.Just(42) - //. Just(42) + //. > S.Just (42) + //. Just (42) //. ``` function Just(x) { - return new _Maybe('Just', x); + return new _Maybe ('Just', x); } _.Just = { consts: {}, - types: [a, $Maybe(a)], + types: [a, $Maybe (a)], impl: Just }; @@ -1672,7 +1741,7 @@ //. directly. //. //. ```javascript - //. > S.empty(S.Maybe) + //. > S.empty (S.Maybe) //. Nothing //. ``` Maybe['fantasy-land/empty'] = function() { return Nothing; }; @@ -1685,8 +1754,8 @@ //. directly. //. //. ```javascript - //. > S.of(S.Maybe, 42) - //. Just(42) + //. > S.of (S.Maybe) (42) + //. Just (42) //. ``` Maybe['fantasy-land/of'] = Just; @@ -1698,7 +1767,7 @@ //. directly. //. //. ```javascript - //. > S.zero(S.Maybe) + //. > S.zero (S.Maybe) //. Nothing //. ``` Maybe['fantasy-land/zero'] = function() { return Nothing; }; @@ -1711,7 +1780,7 @@ //. > S.Nothing.isNothing //. true //. - //. > S.Just(42).isNothing + //. > (S.Just (42)).isNothing //. false //. ``` @@ -1720,7 +1789,7 @@ //. `true` if `this` is a Just; `false` if `this` is Nothing. //. //. ```javascript - //. > S.Just(42).isJust + //. > (S.Just (42)).isJust //. true //. //. > S.Nothing.isJust @@ -1732,14 +1801,14 @@ //. Returns the string representation of the Maybe. //. //. ```javascript - //. > S.toString(S.Nothing) + //. > S.toString (S.Nothing) //. 'Nothing' //. - //. > S.toString(S.Just([1, 2, 3])) + //. > S.toString (S.Just ([1, 2, 3])) //. 'Just([1, 2, 3])' //. ``` Maybe.prototype.toString = function() { - return this.isJust ? 'Just(' + Z.toString(this.value) + ')' : 'Nothing'; + return this.isJust ? 'Just(' + Z.toString (this.value) + ')' : 'Nothing'; }; //# Maybe#inspect :: Maybe a ~> () -> String @@ -1750,13 +1819,13 @@ //. See also [`Maybe#toString`][]. //. //. ```javascript - //. > S.Nothing.inspect() + //. > S.Nothing.inspect () //. 'Nothing' //. - //. > S.Just([1, 2, 3]).inspect() + //. > (S.Just ([1, 2, 3])).inspect () //. 'Just([1, 2, 3])' //. ``` - Maybe.prototype.inspect = function() { return this.toString(); }; + Maybe.prototype.inspect = function() { return this.toString (); }; //# Maybe#fantasy-land/equals :: Setoid a => Maybe a ~> Maybe a -> Boolean //. @@ -1771,21 +1840,21 @@ //. directly. //. //. ```javascript - //. > S.equals(S.Nothing, S.Nothing) + //. > S.equals (S.Nothing) (S.Nothing) //. true //. - //. > S.equals(S.Just([1, 2, 3]), S.Just([1, 2, 3])) + //. > S.equals (S.Just ([1, 2, 3])) (S.Just ([1, 2, 3])) //. true //. - //. > S.equals(S.Just([1, 2, 3]), S.Just([3, 2, 1])) + //. > S.equals (S.Just ([1, 2, 3])) (S.Just ([3, 2, 1])) //. false //. - //. > S.equals(S.Just([1, 2, 3]), S.Nothing) + //. > S.equals (S.Just ([1, 2, 3])) (S.Nothing) //. false //. ``` function Maybe$prototype$equals(other) { return this.isNothing ? other.isNothing - : other.isJust && Z.equals(this.value, other.value); + : other.isJust && Z.equals (this.value, other.value); } //# Maybe#fantasy-land/lte :: Ord a => Maybe a ~> Maybe a -> Boolean @@ -1801,20 +1870,20 @@ //. directly. //. //. ```javascript - //. > S.lte(S.Just(1))(S.Nothing) + //. > S.lte (S.Just (1)) (S.Nothing) //. true //. - //. > S.lte(S.Just(1))(S.Just(0)) + //. > S.lte (S.Just (1)) (S.Just (0)) //. true //. - //. > S.lte(S.Just(1))(S.Just(1)) + //. > S.lte (S.Just (1)) (S.Just (1)) //. true //. - //. > S.lte(S.Just(1))(S.Just(2)) + //. > S.lte (S.Just (1)) (S.Just (2)) //. false //. ``` function Maybe$prototype$lte(other) { - return this.isNothing || other.isJust && Z.lte(this.value, other.value); + return this.isNothing || other.isJust && Z.lte (this.value, other.value); } //# Maybe#fantasy-land/concat :: Semigroup a => Maybe a ~> Maybe a -> Maybe a @@ -1835,22 +1904,22 @@ //. directly. //. //. ```javascript - //. > S.concat(S.Nothing, S.Nothing) + //. > S.concat (S.Nothing) (S.Nothing) //. Nothing //. - //. > S.concat(S.Just([1, 2, 3]), S.Just([4, 5, 6])) - //. Just([1, 2, 3, 4, 5, 6]) + //. > S.concat (S.Just ([1, 2, 3])) (S.Just ([4, 5, 6])) + //. Just ([1, 2, 3, 4, 5, 6]) //. - //. > S.concat(S.Nothing, S.Just([1, 2, 3])) - //. Just([1, 2, 3]) + //. > S.concat (S.Nothing) (S.Just ([1, 2, 3])) + //. Just ([1, 2, 3]) //. - //. > S.concat(S.Just([1, 2, 3]), S.Nothing) - //. Just([1, 2, 3]) + //. > S.concat (S.Just ([1, 2, 3])) (S.Nothing) + //. Just ([1, 2, 3]) //. ``` function Maybe$prototype$concat(other) { return this.isNothing ? other : - other.isNothing ? this : Just(Z.concat(this.value, other.value)); + other.isNothing ? this : Just (Z.concat (this.value, other.value)); } //# Maybe#fantasy-land/filter :: Maybe a ~> (a -> Boolean) -> Maybe a @@ -1862,17 +1931,17 @@ //. directly. //. //. ```javascript - //. > S.filter(S.odd, S.Nothing) + //. > S.filter (S.odd) (S.Nothing) //. Nothing //. - //. > S.filter(S.odd, S.Just(0)) + //. > S.filter (S.odd) (S.Just (0)) //. Nothing //. - //. > S.filter(S.odd, S.Just(1)) - //. Just(1) + //. > S.filter (S.odd) (S.Just (1)) + //. Just (1) //. ``` Maybe.prototype['fantasy-land/filter'] = function(pred) { - return this.isJust && pred(this.value) ? this : Nothing; + return this.isJust && pred (this.value) ? this : Nothing; }; //# Maybe#fantasy-land/map :: Maybe a ~> (a -> b) -> Maybe b @@ -1885,14 +1954,14 @@ //. directly. //. //. ```javascript - //. > S.map(Math.sqrt, S.Nothing) + //. > S.map (Math.sqrt) (S.Nothing) //. Nothing //. - //. > S.map(Math.sqrt, S.Just(9)) - //. Just(3) + //. > S.map (Math.sqrt) (S.Just (9)) + //. Just (3) //. ``` Maybe.prototype['fantasy-land/map'] = function(f) { - return this.isJust ? Just(f(this.value)) : this; + return this.isJust ? Just (f (this.value)) : this; }; //# Maybe#fantasy-land/ap :: Maybe a ~> Maybe (a -> b) -> Maybe b @@ -1904,20 +1973,20 @@ //. It is idiomatic to use [`ap`](#ap) rather than use this method directly. //. //. ```javascript - //. > S.ap(S.Nothing, S.Nothing) + //. > S.ap (S.Nothing) (S.Nothing) //. Nothing //. - //. > S.ap(S.Nothing, S.Just(9)) + //. > S.ap (S.Nothing) (S.Just (9)) //. Nothing //. - //. > S.ap(S.Just(Math.sqrt), S.Nothing) + //. > S.ap (S.Just (Math.sqrt)) (S.Nothing) //. Nothing //. - //. > S.ap(S.Just(Math.sqrt), S.Just(9)) - //. Just(3) + //. > S.ap (S.Just (Math.sqrt)) (S.Just (9)) + //. Just (3) //. ``` Maybe.prototype['fantasy-land/ap'] = function(other) { - return other.isJust ? Z.map(other.value, this) : other; + return other.isJust ? Z.map (other.value, this) : other; }; //# Maybe#fantasy-land/chain :: Maybe a ~> (a -> Maybe b) -> Maybe b @@ -1929,17 +1998,17 @@ //. directly. //. //. ```javascript - //. > S.chain(S.parseFloat, S.Nothing) + //. > S.chain (S.parseFloat) (S.Nothing) //. Nothing //. - //. > S.chain(S.parseFloat, S.Just('xxx')) + //. > S.chain (S.parseFloat) (S.Just ('xxx')) //. Nothing //. - //. > S.chain(S.parseFloat, S.Just('12.34')) - //. Just(12.34) + //. > S.chain (S.parseFloat) (S.Just ('12.34')) + //. Just (12.34) //. ``` Maybe.prototype['fantasy-land/chain'] = function(f) { - return this.isJust ? f(this.value) : this; + return this.isJust ? f (this.value) : this; }; //# Maybe#fantasy-land/alt :: Maybe a ~> Maybe a -> Maybe a @@ -1951,17 +2020,17 @@ //. directly. //. //. ```javascript - //. > S.alt(S.Nothing, S.Nothing) + //. > S.alt (S.Nothing) (S.Nothing) //. Nothing //. - //. > S.alt(S.Nothing, S.Just(1)) - //. Just(1) + //. > S.alt (S.Nothing) (S.Just (1)) + //. Just (1) //. - //. > S.alt(S.Just(2), S.Nothing) - //. Just(2) + //. > S.alt (S.Just (2)) (S.Nothing) + //. Just (2) //. - //. > S.alt(S.Just(3), S.Just(4)) - //. Just(3) + //. > S.alt (S.Just (3)) (S.Just (4)) + //. Just (3) //. ``` Maybe.prototype['fantasy-land/alt'] = function(other) { return this.isJust ? this : other; @@ -1980,14 +2049,14 @@ //. directly. //. //. ```javascript - //. > S.reduce(S.curry2(Math.pow), 10, S.Nothing) + //. > S.reduce (S.curry2 (Math.pow)) (10) (S.Nothing) //. 10 //. - //. > S.reduce(S.curry2(Math.pow), 10, S.Just(3)) + //. > S.reduce (S.curry2 (Math.pow)) (10) (S.Just (3)) //. 1000 //. ``` Maybe.prototype['fantasy-land/reduce'] = function(f, x) { - return this.isJust ? f(x, this.value) : x; + return this.isJust ? f (x, this.value) : x; }; //# Maybe#fantasy-land/traverse :: Applicative f => Maybe a ~> (TypeRep f, a -> f b) -> f (Maybe b) @@ -2005,14 +2074,14 @@ //. method directly. //. //. ```javascript - //. > S.traverse(Array, S.words, S.Nothing) + //. > S.traverse (Array) (S.words) (S.Nothing) //. [Nothing] //. - //. > S.traverse(Array, S.words, S.Just('foo bar baz')) - //. [Just('foo'), Just('bar'), Just('baz')] + //. > S.traverse (Array) (S.words) (S.Just ('foo bar baz')) + //. [Just ('foo'), Just ('bar'), Just ('baz')] //. ``` Maybe.prototype['fantasy-land/traverse'] = function(typeRep, f) { - return this.isJust ? Z.map(Just, f(this.value)) : Z.of(typeRep, this); + return this.isJust ? Z.map (Just, f (this.value)) : Z.of (typeRep, this); }; //# Maybe#fantasy-land/extend :: Maybe a ~> (Maybe a -> b) -> Maybe b @@ -2025,14 +2094,14 @@ //. directly. //. //. ```javascript - //. > S.extend(x => x.value + 1, S.Nothing) + //. > S.extend (x => x.value + 1) (S.Nothing) //. Nothing //. - //. > S.extend(x => x.value + 1, S.Just(42)) - //. Just(43) + //. > S.extend (x => x.value + 1) (S.Just (42)) + //. Just (43) //. ``` Maybe.prototype['fantasy-land/extend'] = function(f) { - return this.isJust ? Just(f(this)) : this; + return this.isJust ? Just (f (this)) : this; }; //# isNothing :: Maybe a -> Boolean @@ -2040,10 +2109,10 @@ //. Returns `true` if the given Maybe is Nothing; `false` if it is a Just. //. //. ```javascript - //. > S.isNothing(S.Nothing) + //. > S.isNothing (S.Nothing) //. true //. - //. > S.isNothing(S.Just(42)) + //. > S.isNothing (S.Just (42)) //. false //. ``` function isNothing(maybe) { @@ -2051,7 +2120,7 @@ } _.isNothing = { consts: {}, - types: [$Maybe(a), $.Boolean], + types: [$Maybe (a), $.Boolean], impl: isNothing }; @@ -2060,10 +2129,10 @@ //. Returns `true` if the given Maybe is a Just; `false` if it is Nothing. //. //. ```javascript - //. > S.isJust(S.Just(42)) + //. > S.isJust (S.Just (42)) //. true //. - //. > S.isJust(S.Nothing) + //. > S.isJust (S.Nothing) //. false //. ``` function isJust(maybe) { @@ -2071,7 +2140,7 @@ } _.isJust = { consts: {}, - types: [$Maybe(a), $.Boolean], + types: [$Maybe (a), $.Boolean], impl: isJust }; @@ -2084,18 +2153,18 @@ //. [`maybeToNullable`](#maybeToNullable). //. //. ```javascript - //. > S.fromMaybe(0, S.Just(42)) + //. > S.fromMaybe (0) (S.Just (42)) //. 42 //. - //. > S.fromMaybe(0, S.Nothing) + //. > S.fromMaybe (0) (S.Nothing) //. 0 //. ``` - function fromMaybe(x, maybe) { - return maybe.isJust ? maybe.value : x; + function fromMaybe(x) { + return maybe (x) (I); } _.fromMaybe = { consts: {}, - types: [a, $Maybe(a), a], + types: [a, $Maybe (a), a], impl: fromMaybe }; @@ -2105,21 +2174,18 @@ //. value is only computed if required. //. //. ```javascript - //. > function fib(n) { return n <= 1 ? n : fib(n - 2) + fib(n - 1); } + //. > function fib(n) { return n <= 1 ? n : fib (n - 2) + fib (n - 1); } //. - //. > S.fromMaybe_(() => fib(30), S.Just(1000000)) + //. > S.fromMaybe_ (() => fib (30)) (S.Just (1000000)) //. 1000000 //. - //. > S.fromMaybe_(() => fib(30), S.Nothing) + //. > S.fromMaybe_ (() => fib (30)) (S.Nothing) //. 832040 //. ``` - function fromMaybe_(thunk, maybe) { - return maybe.isJust ? maybe.value : thunk(); - } _.fromMaybe_ = { consts: {}, - types: [$.Thunk(a), $Maybe(a), a], - impl: fromMaybe_ + types: [$.Thunk (a), $Maybe (a), a], + impl: flip (maybe_) (I) }; //# maybeToNullable :: Maybe a -> Nullable a @@ -2130,10 +2196,10 @@ //. See also [`fromMaybe`](#fromMaybe). //. //. ```javascript - //. > S.maybeToNullable(S.Just(42)) + //. > S.maybeToNullable (S.Just (42)) //. 42 //. - //. > S.maybeToNullable(S.Nothing) + //. > S.maybeToNullable (S.Nothing) //. null //. ``` function maybeToNullable(maybe) { @@ -2141,7 +2207,7 @@ } _.maybeToNullable = { consts: {}, - types: [$Maybe(a), $.Nullable(a)], + types: [$Maybe (a), $.Nullable (a)], impl: maybeToNullable }; @@ -2151,18 +2217,18 @@ //. Just the value otherwise. //. //. ```javascript - //. > S.toMaybe(null) + //. > S.toMaybe (null) //. Nothing //. - //. > S.toMaybe(42) - //. Just(42) + //. > S.toMaybe (42) + //. Just (42) //. ``` function toMaybe(x) { - return x == null ? Nothing : Just(x); + return x == null ? Nothing : Just (x); } _.toMaybe = { consts: {}, - types: [a, $Maybe(a)], + types: [a, $Maybe (a)], impl: toMaybe }; @@ -2175,18 +2241,22 @@ //. See also [`maybe_`](#maybe_). //. //. ```javascript - //. > S.maybe(0, S.prop('length'), S.Just('refuge')) + //. > S.maybe (0) (S.prop ('length')) (S.Just ('refuge')) //. 6 //. - //. > S.maybe(0, S.prop('length'), S.Nothing) + //. > S.maybe (0) (S.prop ('length')) (S.Nothing) //. 0 //. ``` - function maybe(x, f, maybe) { - return fromMaybe(x, Z.map(f, maybe)); + function maybe(x) { + return function(f) { + return function(maybe) { + return maybe.isJust ? f (maybe.value) : x; + }; + }; } _.maybe = { consts: {}, - types: [b, Fn(a, b), $Maybe(a), b], + types: [b, Fn (a) (b), $Maybe (a), b], impl: maybe }; @@ -2196,20 +2266,24 @@ //. is only computed if required. //. //. ```javascript - //. > function fib(n) { return n <= 1 ? n : fib(n - 2) + fib(n - 1); } + //. > function fib(n) { return n <= 1 ? n : fib (n - 2) + fib (n - 1); } //. - //. > S.maybe_(() => fib(30), Math.sqrt, S.Just(1000000)) + //. > S.maybe_ (() => fib (30)) (Math.sqrt) (S.Just (1000000)) //. 1000 //. - //. > S.maybe_(() => fib(30), Math.sqrt, S.Nothing) + //. > S.maybe_ (() => fib (30)) (Math.sqrt) (S.Nothing) //. 832040 //. ``` - function maybe_(thunk, f, maybe) { - return maybe.isJust ? f(maybe.value) : thunk(); + function maybe_(thunk) { + return function(f) { + return function(maybe) { + return maybe.isJust ? f (maybe.value) : thunk (); + }; + }; } _.maybe_ = { consts: {}, - types: [$.Thunk(b), Fn(a, b), $Maybe(a), b], + types: [$.Thunk (b), Fn (a) (b), $Maybe (a), b], impl: maybe_ }; @@ -2221,15 +2295,15 @@ //. See also [`lefts`](#lefts) and [`rights`](#rights). //. //. ```javascript - //. > S.justs([S.Just('foo'), S.Nothing, S.Just('baz')]) + //. > S.justs ([S.Just ('foo'), S.Nothing, S.Just ('baz')]) //. ['foo', 'baz'] //. ``` function justs(maybes) { - return Z.map(value, Z.filter(isJust, maybes)); + return map (value) (filter (isJust) (maybes)); } _.justs = { consts: {f: [Z.Filterable, Z.Functor]}, - types: [f($Maybe(a)), f(a)], + types: [f ($Maybe (a)), f (a)], impl: justs }; @@ -2241,19 +2315,16 @@ //. if the result is a Just, the Just's value is included. //. //. ```javascript - //. > S.mapMaybe(S.head, [[], [1, 2, 3], [], [4, 5, 6], []]) + //. > S.mapMaybe (S.head) ([[], [1, 2, 3], [], [4, 5, 6], []]) //. [1, 4] //. - //. > S.mapMaybe(S.head, {x: [1, 2, 3], y: [], z: [4, 5, 6]}) + //. > S.mapMaybe (S.head) ({x: [1, 2, 3], y: [], z: [4, 5, 6]}) //. {x: 1, z: 4} //. ``` - function mapMaybe(f, filterable) { - return justs(Z.map(f, filterable)); - } _.mapMaybe = { consts: {f: [Z.Filterable, Z.Functor]}, - types: [Fn(a, $Maybe(b)), f(a), f(b)], - impl: mapMaybe + types: [Fn (a) ($Maybe (b)), f (a), f (b)], + impl: B (B (justs)) (map) }; //# encase :: (a -> b) -> a -> Maybe b @@ -2266,55 +2337,37 @@ //. See also [`encaseEither`](#encaseEither). //. //. ```javascript - //. > S.encase(eval, '1 + 1') - //. Just(2) + //. > S.encase (eval) ('1 + 1') + //. Just (2) //. - //. > S.encase(eval, '1 +') + //. > S.encase (eval) ('1 +') //. Nothing //. ``` - function encase(f, x) { - try { - return Just(f(x)); - } catch (err) { - return Nothing; - } + function encase(f) { + return B (eitherToMaybe) (encaseEither (I) (f)); } _.encase = { consts: {}, - types: [Fn(a, b), a, $Maybe(b)], + types: [Fn (a) (b), a, $Maybe (b)], impl: encase }; //# encase2 :: (a -> b -> c) -> a -> b -> Maybe c //. //. Binary version of [`encase`](#encase). - function encase2(f, x, y) { - try { - return Just(f(x)(y)); - } catch (err) { - return Nothing; - } - } _.encase2 = { consts: {}, - types: [Fn(a, Fn(b, c)), a, b, $Maybe(c)], - impl: encase2 + types: [Fn (a) (Fn (b) (c)), a, b, $Maybe (c)], + impl: B (B (B (eitherToMaybe))) (encaseEither2 (I)) }; //# encase3 :: (a -> b -> c -> d) -> a -> b -> c -> Maybe d //. //. Ternary version of [`encase`](#encase). - function encase3(f, x, y, z) { - try { - return Just(f(x)(y)(z)); - } catch (err) { - return Nothing; - } - } _.encase3 = { consts: {}, - types: [Fn(a, Fn(b, Fn(c, d))), a, b, c, $Maybe(d)], - impl: encase3 + types: [Fn (a) (Fn (b) (Fn (c) (d))), a, b, c, $Maybe (d)], + impl: B (B (B (B (eitherToMaybe)))) (encaseEither3 (I)) }; //# maybeToEither :: a -> Maybe b -> Either a b @@ -2325,18 +2378,18 @@ //. See also [`eitherToMaybe`](#eitherToMaybe). //. //. ```javascript - //. > S.maybeToEither('Expecting an integer', S.parseInt(10, 'xyz')) - //. Left('Expecting an integer') + //. > S.maybeToEither ('Expecting an integer') (S.parseInt (10) ('xyz')) + //. Left ('Expecting an integer') //. - //. > S.maybeToEither('Expecting an integer', S.parseInt(10, '42')) - //. Right(42) + //. > S.maybeToEither ('Expecting an integer') (S.parseInt (10) ('42')) + //. Right (42) //. ``` - function maybeToEither(x, maybe) { - return maybe.isNothing ? Left(x) : Right(maybe.value); + function maybeToEither(x) { + return maybe (Left (x)) (Right); } _.maybeToEither = { consts: {}, - types: [a, $Maybe(b), $Either(a, b)], + types: [a, $Maybe (b), $Either (a) (b)], impl: maybeToEither }; @@ -2368,15 +2421,15 @@ // Add "fantasy-land/concat" method conditionally so that Left('abc') // and Right('abc') satisfy the requirements of Semigroup but Left(123) // and Right(123) do not. - if (Z.Semigroup.test(this.value)) { + if (Z.Semigroup.test (this.value)) { this['fantasy-land/concat'] = Either$prototype$concat; } - if (Z.Setoid.test(this.value)) { + if (Z.Setoid.test (this.value)) { this['fantasy-land/equals'] = Either$prototype$equals; } - if (Z.Ord.test(this.value)) { + if (Z.Ord.test (this.value)) { this['fantasy-land/lte'] = Either$prototype$lte; } } @@ -2386,15 +2439,15 @@ //. Takes a value of any type and returns a Left with the given value. //. //. ```javascript - //. > S.Left('Cannot divide by zero') - //. Left('Cannot divide by zero') + //. > S.Left ('Cannot divide by zero') + //. Left ('Cannot divide by zero') //. ``` function Left(x) { - return new _Either('Left', x); + return new _Either ('Left', x); } _.Left = { consts: {}, - types: [a, $Either(a, b)], + types: [a, $Either (a) (b)], impl: Left }; @@ -2403,15 +2456,15 @@ //. Takes a value of any type and returns a Right with the given value. //. //. ```javascript - //. > S.Right(42) - //. Right(42) + //. > S.Right (42) + //. Right (42) //. ``` function Right(x) { - return new _Either('Right', x); + return new _Either ('Right', x); } _.Right = { consts: {}, - types: [b, $Either(a, b)], + types: [b, $Either (a) (b)], impl: Right }; @@ -2428,8 +2481,8 @@ //. directly. //. //. ```javascript - //. > S.of(S.Either, 42) - //. Right(42) + //. > S.of (S.Either) (42) + //. Right (42) //. ``` Either['fantasy-land/of'] = Right; @@ -2438,10 +2491,10 @@ //. `true` if `this` is a Left; `false` if `this` is a Right. //. //. ```javascript - //. > S.Left('Cannot divide by zero').isLeft + //. > (S.Left ('Cannot divide by zero')).isLeft //. true //. - //. > S.Right(42).isLeft + //. > (S.Right (42)).isLeft //. false //. ``` @@ -2450,10 +2503,10 @@ //. `true` if `this` is a Right; `false` if `this` is a Left. //. //. ```javascript - //. > S.Right(42).isRight + //. > (S.Right (42)).isRight //. true //. - //. > S.Left('Cannot divide by zero').isRight + //. > (S.Left ('Cannot divide by zero')).isRight //. false //. ``` @@ -2462,15 +2515,15 @@ //. Returns the string representation of the Either. //. //. ```javascript - //. > S.toString(S.Left('Cannot divide by zero')) + //. > S.toString (S.Left ('Cannot divide by zero')) //. 'Left("Cannot divide by zero")' //. - //. > S.toString(S.Right([1, 2, 3])) + //. > S.toString (S.Right ([1, 2, 3])) //. 'Right([1, 2, 3])' //. ``` Either.prototype.toString = function() { return (this.isLeft ? 'Left' : 'Right') + - '(' + Z.toString(this.value) + ')'; + '(' + Z.toString (this.value) + ')'; }; //# Either#inspect :: Either a b ~> () -> String @@ -2481,13 +2534,13 @@ //. See also [`Either#toString`][]. //. //. ```javascript - //. > S.Left('Cannot divide by zero').inspect() + //. > (S.Left ('Cannot divide by zero')).inspect () //. 'Left("Cannot divide by zero")' //. - //. > S.Right([1, 2, 3]).inspect() + //. > (S.Right ([1, 2, 3])).inspect () //. 'Right([1, 2, 3])' //. ``` - Either.prototype.inspect = function() { return this.toString(); }; + Either.prototype.inspect = function() { return this.toString (); }; //# Either#fantasy-land/equals :: (Setoid a, Setoid b) => Either a b ~> Either a b -> Boolean //. @@ -2500,14 +2553,14 @@ //. directly. //. //. ```javascript - //. > S.equals(S.Right([1, 2, 3]), S.Right([1, 2, 3])) + //. > S.equals (S.Right ([1, 2, 3])) (S.Right ([1, 2, 3])) //. true //. - //. > S.equals(S.Right([1, 2, 3]), S.Left([1, 2, 3])) + //. > S.equals (S.Right ([1, 2, 3])) (S.Left ([1, 2, 3])) //. false //. ``` function Either$prototype$equals(other) { - return this.isLeft === other.isLeft && Z.equals(this.value, other.value); + return this.isLeft === other.isLeft && Z.equals (this.value, other.value); } //# Either#fantasy-land/lte :: (Ord a, Ord b) => Either a b ~> Either a b -> Boolean @@ -2523,27 +2576,27 @@ //. directly. //. //. ```javascript - //. > S.lte(S.Left(0))(S.Left(0)) + //. > S.lte (S.Left (0)) (S.Left (0)) //. true //. - //. > S.lte(S.Left(0))(S.Left(1)) + //. > S.lte (S.Left (0)) (S.Left (1)) //. false //. - //. > S.lte(S.Left(0))(S.Right(0)) + //. > S.lte (S.Left (0)) (S.Right (0)) //. false //. - //. > S.lte(S.Right(0))(S.Left(0)) + //. > S.lte (S.Right (0)) (S.Left (0)) //. true //. - //. > S.lte(S.Right(0))(S.Right(0)) + //. > S.lte (S.Right (0)) (S.Right (0)) //. true //. - //. > S.lte(S.Right(0))(S.Right(1)) + //. > S.lte (S.Right (0)) (S.Right (1)) //. false //. ``` function Either$prototype$lte(other) { return this.isLeft === other.isLeft ? - Z.lte(this.value, other.value) : + Z.lte (this.value, other.value) : this.isLeft; } @@ -2566,22 +2619,22 @@ //. directly. //. //. ```javascript - //. > S.concat(S.Left('abc'), S.Left('def')) - //. Left('abcdef') + //. > S.concat (S.Left ('abc')) (S.Left ('def')) + //. Left ('abcdef') //. - //. > S.concat(S.Right([1, 2, 3]), S.Right([4, 5, 6])) - //. Right([1, 2, 3, 4, 5, 6]) + //. > S.concat (S.Right ([1, 2, 3])) (S.Right ([4, 5, 6])) + //. Right ([1, 2, 3, 4, 5, 6]) //. - //. > S.concat(S.Left('abc'), S.Right([1, 2, 3])) - //. Right([1, 2, 3]) + //. > S.concat (S.Left ('abc')) (S.Right ([1, 2, 3])) + //. Right ([1, 2, 3]) //. - //. > S.concat(S.Right([1, 2, 3]), S.Left('abc')) - //. Right([1, 2, 3]) + //. > S.concat (S.Right ([1, 2, 3])) (S.Left ('abc')) + //. Right ([1, 2, 3]) //. ``` function Either$prototype$concat(other) { return this.isLeft ? - other.isLeft ? Left(Z.concat(this.value, other.value)) : other : - other.isLeft ? this : Right(Z.concat(this.value, other.value)); + other.isLeft ? Left (Z.concat (this.value, other.value)) : other : + other.isLeft ? this : Right (Z.concat (this.value, other.value)); } //# Either#fantasy-land/map :: Either a b ~> (b -> c) -> Either a c @@ -2596,14 +2649,14 @@ //. See also [`Either#fantasy-land/bimap`][]. //. //. ```javascript - //. > S.map(Math.sqrt, S.Left('Cannot divide by zero')) - //. Left('Cannot divide by zero') + //. > S.map (Math.sqrt) (S.Left ('Cannot divide by zero')) + //. Left ('Cannot divide by zero') //. - //. > S.map(Math.sqrt, S.Right(9)) - //. Right(3) + //. > S.map (Math.sqrt) (S.Right (9)) + //. Right (3) //. ``` Either.prototype['fantasy-land/map'] = function(f) { - return this.isRight ? Right(f(this.value)) : this; + return this.isRight ? Right (f (this.value)) : this; }; //# Either#fantasy-land/bimap :: Either a b ~> (a -> c, b -> d) -> Either c d @@ -2623,14 +2676,14 @@ //. directly. //. //. ```javascript - //. > S.bimap(S.toUpper, S.add(1), S.Left('abc')) - //. Left('ABC') + //. > S.bimap (S.toUpper) (S.add (1)) (S.Left ('abc')) + //. Left ('ABC') //. - //. > S.bimap(S.toUpper, S.add(1), S.Right(42)) - //. Right(43) + //. > S.bimap (S.toUpper) (S.add (1)) (S.Right (42)) + //. Right (43) //. ``` Either.prototype['fantasy-land/bimap'] = function(f, g) { - return this.isLeft ? Left(f(this.value)) : Right(g(this.value)); + return this.isLeft ? Left (f (this.value)) : Right (g (this.value)); }; //# Either#fantasy-land/ap :: Either a b ~> Either a (b -> c) -> Either a c @@ -2642,20 +2695,20 @@ //. It is idiomatic to use [`ap`](#ap) rather than use this method directly. //. //. ```javascript - //. > S.ap(S.Left('No such function'), S.Left('Cannot divide by zero')) - //. Left('No such function') + //. > S.ap (S.Left ('No such function')) (S.Left ('Cannot divide by zero')) + //. Left ('No such function') //. - //. > S.ap(S.Left('No such function'), S.Right(9)) - //. Left('No such function') + //. > S.ap (S.Left ('No such function')) (S.Right (9)) + //. Left ('No such function') //. - //. > S.ap(S.Right(Math.sqrt), S.Left('Cannot divide by zero')) - //. Left('Cannot divide by zero') + //. > S.ap (S.Right (Math.sqrt)) (S.Left ('Cannot divide by zero')) + //. Left ('Cannot divide by zero') //. - //. > S.ap(S.Right(Math.sqrt), S.Right(9)) - //. Right(3) + //. > S.ap (S.Right (Math.sqrt)) (S.Right (9)) + //. Right (3) //. ``` Either.prototype['fantasy-land/ap'] = function(other) { - return other.isRight ? Z.map(other.value, this) : other; + return other.isRight ? Z.map (other.value, this) : other; }; //# Either#fantasy-land/chain :: Either a b ~> (b -> Either a c) -> Either a c @@ -2668,20 +2721,20 @@ //. //. ```javascript //. > const sqrt = n => - //. . n < 0 ? S.Left('Cannot represent square root of negative number') - //. . : S.Right(Math.sqrt(n)) + //. . n < 0 ? S.Left ('Cannot represent square root of negative number') + //. . : S.Right (Math.sqrt (n)) //. - //. > S.chain(sqrt, S.Left('Cannot divide by zero')) - //. Left('Cannot divide by zero') + //. > S.chain (sqrt) (S.Left ('Cannot divide by zero')) + //. Left ('Cannot divide by zero') //. - //. > S.chain(sqrt, S.Right(-1)) - //. Left('Cannot represent square root of negative number') + //. > S.chain (sqrt) (S.Right (-1)) + //. Left ('Cannot represent square root of negative number') //. - //. > S.chain(sqrt, S.Right(25)) - //. Right(5) + //. > S.chain (sqrt) (S.Right (25)) + //. Right (5) //. ``` Either.prototype['fantasy-land/chain'] = function(f) { - return this.isRight ? f(this.value) : this; + return this.isRight ? f (this.value) : this; }; //# Either#fantasy-land/alt :: Either a b ~> Either a b -> Either a b @@ -2693,17 +2746,17 @@ //. directly. //. //. ```javascript - //. > S.alt(S.Left('A'), S.Left('B')) - //. Left('B') + //. > S.alt (S.Left ('A')) (S.Left ('B')) + //. Left ('B') //. - //. > S.alt(S.Left('C'), S.Right(1)) - //. Right(1) + //. > S.alt (S.Left ('C')) (S.Right (1)) + //. Right (1) //. - //. > S.alt(S.Right(2), S.Left('D')) - //. Right(2) + //. > S.alt (S.Right (2)) (S.Left ('D')) + //. Right (2) //. - //. > S.alt(S.Right(3), S.Right(4)) - //. Right(3) + //. > S.alt (S.Right (3)) (S.Right (4)) + //. Right (3) //. ``` Either.prototype['fantasy-land/alt'] = function(other) { return this.isRight ? this : other; @@ -2722,14 +2775,14 @@ //. directly. //. //. ```javascript - //. > S.reduce(S.curry2(Math.pow), 10, S.Left('Cannot divide by zero')) + //. > S.reduce (S.curry2 (Math.pow)) (10) (S.Left ('Cannot divide by zero')) //. 10 //. - //. > S.reduce(S.curry2(Math.pow), 10, S.Right(3)) + //. > S.reduce (S.curry2 (Math.pow)) (10) (S.Right (3)) //. 1000 //. ``` Either.prototype['fantasy-land/reduce'] = function(f, x) { - return this.isRight ? f(x, this.value) : x; + return this.isRight ? f (x, this.value) : x; }; //# Either#fantasy-land/traverse :: Applicative f => Either a b ~> (TypeRep f, b -> f c) -> f (Either a c) @@ -2747,14 +2800,14 @@ //. method directly. //. //. ```javascript - //. > S.traverse(Array, S.words, S.Left('Request failed')) - //. [Left('Request failed')] + //. > S.traverse (Array) (S.words) (S.Left ('Request failed')) + //. [Left ('Request failed')] //. - //. > S.traverse(Array, S.words, S.Right('foo bar baz')) - //. [Right('foo'), Right('bar'), Right('baz')] + //. > S.traverse (Array) (S.words) (S.Right ('foo bar baz')) + //. [Right ('foo'), Right ('bar'), Right ('baz')] //. ``` Either.prototype['fantasy-land/traverse'] = function(typeRep, f) { - return this.isRight ? Z.map(Right, f(this.value)) : Z.of(typeRep, this); + return this.isRight ? Z.map (Right, f (this.value)) : Z.of (typeRep, this); }; //# Either#fantasy-land/extend :: Either a b ~> (Either a b -> c) -> Either a c @@ -2767,14 +2820,14 @@ //. directly. //. //. ```javascript - //. > S.extend(x => x.value + 1, S.Left('Cannot divide by zero')) - //. Left('Cannot divide by zero') + //. > S.extend (x => x.value + 1) (S.Left ('Cannot divide by zero')) + //. Left ('Cannot divide by zero') //. - //. > S.extend(x => x.value + 1, S.Right(42)) - //. Right(43) + //. > S.extend (x => x.value + 1) (S.Right (42)) + //. Right (43) //. ``` Either.prototype['fantasy-land/extend'] = function(f) { - return this.isLeft ? this : Right(f(this)); + return this.isLeft ? this : Right (f (this)); }; //# isLeft :: Either a b -> Boolean @@ -2782,10 +2835,10 @@ //. Returns `true` if the given Either is a Left; `false` if it is a Right. //. //. ```javascript - //. > S.isLeft(S.Left('Cannot divide by zero')) + //. > S.isLeft (S.Left ('Cannot divide by zero')) //. true //. - //. > S.isLeft(S.Right(42)) + //. > S.isLeft (S.Right (42)) //. false //. ``` function isLeft(either) { @@ -2793,7 +2846,7 @@ } _.isLeft = { consts: {}, - types: [$Either(a, b), $.Boolean], + types: [$Either (a) (b), $.Boolean], impl: isLeft }; @@ -2802,10 +2855,10 @@ //. Returns `true` if the given Either is a Right; `false` if it is a Left. //. //. ```javascript - //. > S.isRight(S.Right(42)) + //. > S.isRight (S.Right (42)) //. true //. - //. > S.isRight(S.Left('Cannot divide by zero')) + //. > S.isRight (S.Left ('Cannot divide by zero')) //. false //. ``` function isRight(either) { @@ -2813,7 +2866,7 @@ } _.isRight = { consts: {}, - types: [$Either(a, b), $.Boolean], + types: [$Either (a) (b), $.Boolean], impl: isRight }; @@ -2823,18 +2876,18 @@ //. if the Either is a Right; the default value otherwise. //. //. ```javascript - //. > S.fromEither(0, S.Right(42)) + //. > S.fromEither (0) (S.Right (42)) //. 42 //. - //. > S.fromEither(0, S.Left(42)) + //. > S.fromEither (0) (S.Left (42)) //. 0 //. ``` - function fromEither(x, either) { - return either.isRight ? either.value : x; + function fromEither(x) { + return either (K (x)) (I); } _.fromEither = { consts: {}, - types: [b, $Either(a, b), b], + types: [b, $Either (a) (b), b], impl: fromEither }; @@ -2845,24 +2898,30 @@ //. value of the Left in the "failure" case. //. //. ```javascript - //. > S.toEither('XYZ', null) - //. Left('XYZ') + //. > S.toEither ('XYZ') (null) + //. Left ('XYZ') //. - //. > S.toEither('XYZ', 'ABC') - //. Right('ABC') + //. > S.toEither ('XYZ') ('ABC') + //. Right ('ABC') //. - //. > S.map(S.prop('0'), S.toEither('Invalid protocol', 'ftp://example.com/'.match(/^https?:/))) - //. Left('Invalid protocol') + //. > S.map (S.prop ('0')) + //. . (S.toEither ('Invalid protocol') + //. . ('ftp://example.com/'.match (/^https?:/))) + //. Left ('Invalid protocol') //. - //. > S.map(S.prop('0'), S.toEither('Invalid protocol', 'https://example.com/'.match(/^https?:/))) - //. Right('https:') + //. > S.map (S.prop ('0')) + //. . (S.toEither ('Invalid protocol') + //. . ('https://example.com/'.match (/^https?:/))) + //. Right ('https:') //. ``` - function toEither(x, y) { - return y == null ? Left(x) : Right(y); + function toEither(x) { + return function(y) { + return y == null ? Left (x) : Right (y); + }; } _.toEither = { consts: {}, - types: [a, b, $Either(a, b)], + types: [a, b, $Either (a) (b)], impl: toEither }; @@ -2874,18 +2933,22 @@ //. Right's value, if the Either is a Right. //. //. ```javascript - //. > S.either(S.toUpper, S.toString, S.Left('Cannot divide by zero')) + //. > S.either (S.toUpper) (S.toString) (S.Left ('Cannot divide by zero')) //. 'CANNOT DIVIDE BY ZERO' //. - //. > S.either(S.toUpper, S.toString, S.Right(42)) + //. > S.either (S.toUpper) (S.toString) (S.Right (42)) //. '42' //. ``` - function either(l, r, either) { - return either.isLeft ? l(either.value) : r(either.value); + function either(l) { + return function(r) { + return function(either) { + return (either.isLeft ? l : r) (either.value); + }; + }; } _.either = { consts: {}, - types: [Fn(a, c), Fn(b, c), $Either(a, b), c], + types: [Fn (a) (c), Fn (b) (c), $Either (a) (b), c], impl: either }; @@ -2897,16 +2960,13 @@ //. See also [`rights`](#rights). //. //. ```javascript - //. > S.lefts([S.Right(20), S.Left('foo'), S.Right(10), S.Left('bar')]) + //. > S.lefts ([S.Right (20), S.Left ('foo'), S.Right (10), S.Left ('bar')]) //. ['foo', 'bar'] //. ``` - function lefts(eithers) { - return Z.map(value, Z.filter(isLeft, eithers)); - } _.lefts = { consts: {f: [Z.Filterable, Z.Functor]}, - types: [f($Either(a, b)), f(a)], - impl: lefts + types: [f ($Either (a) (b)), f (a)], + impl: B (map (value)) (filter (isLeft)) }; //# rights :: (Filterable f, Functor f) => f (Either a b) -> f b @@ -2917,16 +2977,13 @@ //. See also [`lefts`](#lefts). //. //. ```javascript - //. > S.rights([S.Right(20), S.Left('foo'), S.Right(10), S.Left('bar')]) + //. > S.rights ([S.Right (20), S.Left ('foo'), S.Right (10), S.Left ('bar')]) //. [20, 10] //. ``` - function rights(eithers) { - return Z.map(value, Z.filter(isRight, eithers)); - } _.rights = { consts: {f: [Z.Filterable, Z.Functor]}, - types: [f($Either(a, b)), f(b)], - impl: rights + types: [f ($Either (a) (b)), f (b)], + impl: B (map (value)) (filter (isRight)) }; //# tagBy :: (a -> Boolean) -> a -> Either a a @@ -2935,18 +2992,18 @@ //. satisfies the predicate; a Left of the value otherwise. //. //. ```javascript - //. > S.tagBy(S.odd, 0) - //. Left(0) + //. > S.tagBy (S.odd) (0) + //. Left (0) // - //. > S.tagBy(S.odd, 1) - //. Right(1) + //. > S.tagBy (S.odd) (1) + //. Right (1) //. ``` - function tagBy(pred, a) { - return pred(a) ? Right(a) : Left(a); + function tagBy(pred) { + return ifElse (pred) (Right) (Left); } _.tagBy = { consts: {}, - types: [$.Predicate(a), a, $Either(a, a)], + types: [$.Predicate (a), a, $Either (a) (a)], impl: tagBy }; @@ -2961,57 +3018,80 @@ //. See also [`encase`](#encase). //. //. ```javascript - //. > S.encaseEither(S.I, JSON.parse, '["foo","bar","baz"]') - //. Right(['foo', 'bar', 'baz']) + //. > S.encaseEither (S.I) (JSON.parse) ('["foo","bar","baz"]') + //. Right (['foo', 'bar', 'baz']) //. - //. > S.encaseEither(S.I, JSON.parse, '[') - //. Left(new SyntaxError('Unexpected end of JSON input')) + //. > S.encaseEither (S.I) (JSON.parse) ('[') + //. Left (new SyntaxError ('Unexpected end of JSON input')) //. - //. > S.encaseEither(S.prop('message'), JSON.parse, '[') - //. Left('Unexpected end of JSON input') + //. > S.encaseEither (S.prop ('message')) (JSON.parse) ('[') + //. Left ('Unexpected end of JSON input') //. ``` - function encaseEither(f, g, x) { - try { - return Right(g(x)); - } catch (err) { - return Left(f(err)); - } + function encaseEither(f) { + return function(g) { + return function(x) { + try { + return Right (g (x)); + } catch (err) { + return Left (f (err)); + } + }; + }; } _.encaseEither = { consts: {}, - types: [Fn($.Error, l), Fn(a, r), a, $Either(l, r)], + types: [Fn ($.Error) (l), Fn (a) (r), a, $Either (l) (r)], impl: encaseEither }; //# encaseEither2 :: (Error -> l) -> (a -> b -> r) -> a -> b -> Either l r //. //. Binary version of [`encaseEither`](#encaseEither). - function encaseEither2(f, g, x, y) { - try { - return Right(g(x)(y)); - } catch (err) { - return Left(f(err)); - } + function encaseEither2(f) { + return function(g) { + return function(x) { + return function(y) { + try { + return Right (g (x) (y)); + } catch (err) { + return Left (f (err)); + } + }; + }; + }; } _.encaseEither2 = { consts: {}, - types: [Fn($.Error, l), Fn(a, Fn(b, r)), a, b, $Either(l, r)], + types: [Fn ($.Error) (l), Fn (a) (Fn (b) (r)), a, b, $Either (l) (r)], impl: encaseEither2 }; //# encaseEither3 :: (Error -> l) -> (a -> b -> c -> r) -> a -> b -> c -> Either l r //. //. Ternary version of [`encaseEither`](#encaseEither). - function encaseEither3(f, g, x, y, z) { - try { - return Right(g(x)(y)(z)); - } catch (err) { - return Left(f(err)); - } + function encaseEither3(f) { + return function(g) { + return function(x) { + return function(y) { + return function(z) { + try { + return Right (g (x) (y) (z)); + } catch (err) { + return Left (f (err)); + } + }; + }; + }; + }; } _.encaseEither3 = { consts: {}, - types: [Fn($.Error, l), Fn(a, Fn(b, Fn(c, r))), a, b, c, $Either(l, r)], + types: [Fn ($.Error) (l), + Fn (a) (Fn (b) (Fn (c) (r))), + a, + b, + c, + $Either (l) (r)], impl: encaseEither3 }; @@ -3023,18 +3103,18 @@ //. See also [`maybeToEither`](#maybeToEither). //. //. ```javascript - //. > S.eitherToMaybe(S.Left('Cannot divide by zero')) + //. > S.eitherToMaybe (S.Left ('Cannot divide by zero')) //. Nothing //. - //. > S.eitherToMaybe(S.Right(42)) - //. Just(42) + //. > S.eitherToMaybe (S.Right (42)) + //. Just (42) //. ``` function eitherToMaybe(either) { - return either.isLeft ? Nothing : Just(either.value); + return either.isLeft ? Nothing : Just (either.value); } _.eitherToMaybe = { consts: {}, - types: [$Either(a, b), $Maybe(b)], + types: [$Either (a) (b), $Maybe (b)], impl: eitherToMaybe }; @@ -3045,20 +3125,22 @@ //. Boolean "and". //. //. ```javascript - //. > S.and(false, false) + //. > S.and (false) (false) //. false //. - //. > S.and(false, true) + //. > S.and (false) (true) //. false //. - //. > S.and(true, false) + //. > S.and (true) (false) //. false //. - //. > S.and(true, true) + //. > S.and (true) (true) //. true //. ``` - function and(x, y) { - return x && y; + function and(x) { + return function(y) { + return x && y; + }; } _.and = { consts: {}, @@ -3071,20 +3153,22 @@ //. Boolean "or". //. //. ```javascript - //. > S.or(false, false) + //. > S.or (false) (false) //. false //. - //. > S.or(false, true) + //. > S.or (false) (true) //. true //. - //. > S.or(true, false) + //. > S.or (true) (false) //. true //. - //. > S.or(true, true) + //. > S.or (true) (true) //. true //. ``` - function or(x, y) { - return x || y; + function or(x) { + return function(y) { + return x || y; + }; } _.or = { consts: {}, @@ -3099,10 +3183,10 @@ //. See also [`complement`](#complement). //. //. ```javascript - //. > S.not(false) + //. > S.not (false) //. true //. - //. > S.not(true) + //. > S.not (true) //. false //. ``` function not(x) { @@ -3122,19 +3206,16 @@ //. See also [`not`](#not). //. //. ```javascript - //. > Number.isInteger(42) + //. > Number.isInteger (42) //. true //. - //. > S.complement(Number.isInteger, 42) + //. > S.complement (Number.isInteger) (42) //. false //. ``` - function complement(pred, x) { - return !pred(x); - } _.complement = { consts: {}, - types: [$.Predicate(a), a, $.Boolean], - impl: complement + types: [$.Predicate (a), a, $.Boolean], + impl: B (not) }; //# ifElse :: (a -> Boolean) -> (a -> b) -> (a -> b) -> a -> b @@ -3148,18 +3229,24 @@ //. See also [`when`](#when) and [`unless`](#unless). //. //. ```javascript - //. > S.ifElse(x => x < 0, Math.abs, Math.sqrt, -1) + //. > S.ifElse (x => x < 0) (Math.abs) (Math.sqrt) (-1) //. 1 //. - //. > S.ifElse(x => x < 0, Math.abs, Math.sqrt, 16) + //. > S.ifElse (x => x < 0) (Math.abs) (Math.sqrt) (16) //. 4 //. ``` - function ifElse(pred, f, g, x) { - return pred(x) ? f(x) : g(x); + function ifElse(pred) { + return function(f) { + return function(g) { + return function(x) { + return (pred (x) ? f : g) (x); + }; + }; + }; } _.ifElse = { consts: {}, - types: [$.Predicate(a), Fn(a, b), Fn(a, b), a, b], + types: [$.Predicate (a), Fn (a) (b), Fn (a) (b), a, b], impl: ifElse }; @@ -3172,18 +3259,18 @@ //. See also [`unless`](#unless) and [`ifElse`](#ifElse). //. //. ```javascript - //. > S.when(x => x >= 0, Math.sqrt, 16) + //. > S.when (x => x >= 0) (Math.sqrt) (16) //. 4 //. - //. > S.when(x => x >= 0, Math.sqrt, -1) + //. > S.when (x => x >= 0) (Math.sqrt) (-1) //. -1 //. ``` - function when(pred, f, x) { - return ifElse(pred, f, I, x); + function when(pred) { + return flip (ifElse (pred)) (I); } _.when = { consts: {}, - types: [$.Predicate(a), Fn(a, a), a, a], + types: [$.Predicate (a), Fn (a) (a), a, a], impl: when }; @@ -3196,18 +3283,18 @@ //. See also [`when`](#when) and [`ifElse`](#ifElse). //. //. ```javascript - //. > S.unless(x => x < 0, Math.sqrt, 16) + //. > S.unless (x => x < 0) (Math.sqrt) (16) //. 4 //. - //. > S.unless(x => x < 0, Math.sqrt, -1) + //. > S.unless (x => x < 0) (Math.sqrt) (-1) //. -1 //. ``` - function unless(pred, f, x) { - return ifElse(pred, I, f, x); + function unless(pred) { + return ifElse (pred) (I); } _.unless = { consts: {}, - types: [$.Predicate(a), Fn(a, a), a, a], + types: [$.Predicate (a), Fn (a) (a), a, a], impl: unless }; @@ -3219,18 +3306,20 @@ //. the first predicate not satisfied. //. //. ```javascript - //. > S.allPass([S.test(/q/), S.test(/u/), S.test(/i/)], 'quiessence') + //. > S.allPass ([S.test (/q/), S.test (/u/), S.test (/i/)]) ('quiessence') //. true //. - //. > S.allPass([S.test(/q/), S.test(/u/), S.test(/i/)], 'fissiparous') + //. > S.allPass ([S.test (/q/), S.test (/u/), S.test (/i/)]) ('fissiparous') //. false //. ``` - function allPass(preds, x) { - return Z.reduce(function(b, p) { return b && p(x); }, true, preds); + function allPass(preds) { + return function(x) { + return Z.reduce (function(b, p) { return b && p (x); }, true, preds); + }; } _.allPass = { consts: {f: [Z.Foldable]}, - types: [f($.Predicate(a)), a, $.Boolean], + types: [f ($.Predicate (a)), a, $.Boolean], impl: allPass }; @@ -3242,18 +3331,20 @@ //. the first predicate satisfied. //. //. ```javascript - //. > S.anyPass([S.test(/q/), S.test(/u/), S.test(/i/)], 'incandescent') + //. > S.anyPass ([S.test (/q/), S.test (/u/), S.test (/i/)]) ('incandescent') //. true //. - //. > S.anyPass([S.test(/q/), S.test(/u/), S.test(/i/)], 'empathy') + //. > S.anyPass ([S.test (/q/), S.test (/u/), S.test (/i/)]) ('empathy') //. false //. ``` - function anyPass(preds, x) { - return Z.reduce(function(b, p) { return b || p(x); }, false, preds); + function anyPass(preds) { + return function(x) { + return Z.reduce (function(b, p) { return b || p (x); }, false, preds); + }; } _.anyPass = { consts: {f: [Z.Foldable]}, - types: [f($.Predicate(a)), a, $.Boolean], + types: [f ($.Predicate (a)), a, $.Boolean], impl: anyPass }; @@ -3269,27 +3360,32 @@ //. and [`dropLast`](#dropLast). //. //. ```javascript - //. > S.slice(1, 3, ['a', 'b', 'c', 'd', 'e']) - //. Just(['b', 'c']) + //. > S.slice (1) (3) (['a', 'b', 'c', 'd', 'e']) + //. Just (['b', 'c']) //. - //. > S.slice(-3, -1, ['a', 'b', 'c', 'd', 'e']) - //. Just(['c', 'd']) + //. > S.slice (-3) (-1) (['a', 'b', 'c', 'd', 'e']) + //. Just (['c', 'd']) //. - //. > S.slice(1, 6, ['a', 'b', 'c', 'd', 'e']) + //. > S.slice (1) (6) (['a', 'b', 'c', 'd', 'e']) //. Nothing //. ``` - function slice(start, end, xs) { - var len = xs.length; - var fromIdx = start < 0 ? start + len : start; - var toIdx = end < 0 ? end + len : end; - - return Math.abs(start) <= len && Math.abs(end) <= len && fromIdx <= toIdx ? - Just(xs.slice(fromIdx, toIdx)) : - Nothing; + function slice(start) { + return function(end) { + return function(xs) { + var fromIdx = start < 0 ? start + xs.length : start; + var toIdx = end < 0 ? end + xs.length : end; + + return Math.abs (start) <= xs.length && + Math.abs (end) <= xs.length && + fromIdx <= toIdx ? + Just (xs.slice (fromIdx, toIdx)) : + Nothing; + }; + }; } _.slice = { consts: {}, - types: [$.Integer, $.Integer, $.Array(a), $Maybe($.Array(a))], + types: [$.Integer, $.Integer, $.Array (a), $Maybe ($.Array (a))], impl: slice }; @@ -3300,22 +3396,24 @@ //. index represents an offset from the length of the array. //. //. ```javascript - //. > S.at(2, ['a', 'b', 'c', 'd', 'e']) - //. Just('c') + //. > S.at (2) (['a', 'b', 'c', 'd', 'e']) + //. Just ('c') //. - //. > S.at(5, ['a', 'b', 'c', 'd', 'e']) + //. > S.at (5) (['a', 'b', 'c', 'd', 'e']) //. Nothing //. - //. > S.at(-2, ['a', 'b', 'c', 'd', 'e']) - //. Just('d') + //. > S.at (-2) (['a', 'b', 'c', 'd', 'e']) + //. Just ('d') //. ``` - function at(n, xs) { - var idx = n < 0 ? xs.length + n : n; - return idx < 0 || idx >= xs.length ? Nothing : Just(xs[idx]); + function at(n) { + return function(xs) { + var idx = n < 0 ? xs.length + n : n; + return idx < 0 || idx >= xs.length ? Nothing : Just (xs[idx]); + }; } _.at = { consts: {}, - types: [$.Integer, $.Array(a), $Maybe(a)], + types: [$.Integer, $.Array (a), $Maybe (a)], impl: at }; @@ -3325,18 +3423,18 @@ //. at least one element; Nothing otherwise. //. //. ```javascript - //. > S.head([1, 2, 3]) - //. Just(1) + //. > S.head ([1, 2, 3]) + //. Just (1) //. - //. > S.head([]) + //. > S.head ([]) //. Nothing //. ``` function head(xs) { - return xs.length > 0 ? Just(xs[0]) : Nothing; + return xs.length > 0 ? Just (xs[0]) : Nothing; } _.head = { consts: {}, - types: [$.Array(a), $Maybe(a)], + types: [$.Array (a), $Maybe (a)], impl: head }; @@ -3346,18 +3444,18 @@ //. at least one element; Nothing otherwise. //. //. ```javascript - //. > S.last([1, 2, 3]) - //. Just(3) + //. > S.last ([1, 2, 3]) + //. Just (3) //. - //. > S.last([]) + //. > S.last ([]) //. Nothing //. ``` function last(xs) { - return xs.length > 0 ? Just(xs[xs.length - 1]) : Nothing; + return xs.length > 0 ? Just (xs[xs.length - 1]) : Nothing; } _.last = { consts: {}, - types: [$.Array(a), $Maybe(a)], + types: [$.Array (a), $Maybe (a)], impl: last }; @@ -3367,18 +3465,18 @@ //. array contains at least one element; Nothing otherwise. //. //. ```javascript - //. > S.tail([1, 2, 3]) - //. Just([2, 3]) + //. > S.tail ([1, 2, 3]) + //. Just ([2, 3]) //. - //. > S.tail([]) + //. > S.tail ([]) //. Nothing //. ``` function tail(xs) { - return xs.length > 0 ? Just(xs.slice(1)) : Nothing; + return xs.length > 0 ? Just (xs.slice (1)) : Nothing; } _.tail = { consts: {}, - types: [$.Array(a), $Maybe($.Array(a))], + types: [$.Array (a), $Maybe ($.Array (a))], impl: tail }; @@ -3388,18 +3486,18 @@ //. array contains at least one element; Nothing otherwise. //. //. ```javascript - //. > S.init([1, 2, 3]) - //. Just([1, 2]) + //. > S.init ([1, 2, 3]) + //. Just ([1, 2]) //. - //. > S.init([]) + //. > S.init ([]) //. Nothing //. ``` function init(xs) { - return xs.length > 0 ? Just(xs.slice(0, -1)) : Nothing; + return xs.length > 0 ? Just (xs.slice (0, -1)) : Nothing; } _.init = { consts: {}, - types: [$.Array(a), $Maybe($.Array(a))], + types: [$.Array (a), $Maybe ($.Array (a))], impl: init }; @@ -3410,21 +3508,23 @@ //. Nothing otherwise. //. //. ```javascript - //. > S.take(2, ['a', 'b', 'c', 'd', 'e']) - //. Just(['a', 'b']) + //. > S.take (2) (['a', 'b', 'c', 'd', 'e']) + //. Just (['a', 'b']) //. - //. > S.take(5, ['a', 'b', 'c', 'd', 'e']) - //. Just(['a', 'b', 'c', 'd', 'e']) + //. > S.take (5) (['a', 'b', 'c', 'd', 'e']) + //. Just (['a', 'b', 'c', 'd', 'e']) //. - //. > S.take(6, ['a', 'b', 'c', 'd', 'e']) + //. > S.take (6) (['a', 'b', 'c', 'd', 'e']) //. Nothing //. ``` - function take(n, xs) { - return n >= 0 && n <= xs.length ? Just(xs.slice(0, n)) : Nothing; + function take(n) { + return function(xs) { + return n >= 0 && n <= xs.length ? Just (xs.slice (0, n)) : Nothing; + }; } _.take = { consts: {}, - types: [$.Integer, $.Array(a), $Maybe($.Array(a))], + types: [$.Integer, $.Array (a), $Maybe ($.Array (a))], impl: take }; @@ -3435,21 +3535,24 @@ //. Nothing otherwise. //. //. ```javascript - //. > S.takeLast(2, ['a', 'b', 'c', 'd', 'e']) - //. Just(['d', 'e']) + //. > S.takeLast (2) (['a', 'b', 'c', 'd', 'e']) + //. Just (['d', 'e']) //. - //. > S.takeLast(5, ['a', 'b', 'c', 'd', 'e']) - //. Just(['a', 'b', 'c', 'd', 'e']) + //. > S.takeLast (5) (['a', 'b', 'c', 'd', 'e']) + //. Just (['a', 'b', 'c', 'd', 'e']) //. - //. > S.takeLast(6, ['a', 'b', 'c', 'd', 'e']) + //. > S.takeLast (6) (['a', 'b', 'c', 'd', 'e']) //. Nothing //. ``` - function takeLast(n, xs) { - return n >= 0 && n <= xs.length ? Just(xs.slice(xs.length - n)) : Nothing; + function takeLast(n) { + return function(xs) { + return n >= 0 && n <= xs.length ? Just (xs.slice (xs.length - n)) + : Nothing; + }; } _.takeLast = { consts: {}, - types: [$.Integer, $.Array(a), $Maybe($.Array(a))], + types: [$.Integer, $.Array (a), $Maybe ($.Array (a))], impl: takeLast }; @@ -3460,21 +3563,23 @@ //. the array; Nothing otherwise. //. //. ```javascript - //. > S.drop(2, ['a', 'b', 'c', 'd', 'e']) - //. Just(['c', 'd', 'e']) + //. > S.drop (2) (['a', 'b', 'c', 'd', 'e']) + //. Just (['c', 'd', 'e']) //. - //. > S.drop(5, ['a', 'b', 'c', 'd', 'e']) - //. Just([]) + //. > S.drop (5) (['a', 'b', 'c', 'd', 'e']) + //. Just ([]) //. - //. > S.drop(6, ['a', 'b', 'c', 'd', 'e']) + //. > S.drop (6) (['a', 'b', 'c', 'd', 'e']) //. Nothing //. ``` - function drop(n, xs) { - return n >= 0 && n <= xs.length ? Just(xs.slice(n)) : Nothing; + function drop(n) { + return function(xs) { + return n >= 0 && n <= xs.length ? Just (xs.slice (n)) : Nothing; + }; } _.drop = { consts: {}, - types: [$.Integer, $.Array(a), $Maybe($.Array(a))], + types: [$.Integer, $.Array (a), $Maybe ($.Array (a))], impl: drop }; @@ -3485,22 +3590,24 @@ //. the array; Nothing otherwise. //. //. ```javascript - //. > S.dropLast(2, ['a', 'b', 'c', 'd', 'e']) - //. Just(['a', 'b', 'c']) + //. > S.dropLast (2) (['a', 'b', 'c', 'd', 'e']) + //. Just (['a', 'b', 'c']) //. - //. > S.dropLast(5, ['a', 'b', 'c', 'd', 'e']) - //. Just([]) + //. > S.dropLast (5) (['a', 'b', 'c', 'd', 'e']) + //. Just ([]) //. - //. > S.dropLast(6, ['a', 'b', 'c', 'd', 'e']) + //. > S.dropLast (6) (['a', 'b', 'c', 'd', 'e']) //. Nothing //. ``` - function dropLast(n, xs) { - return n >= 0 && n <= xs.length ? Just(xs.slice(0, xs.length - n)) - : Nothing; + function dropLast(n) { + return function(xs) { + return n >= 0 && n <= xs.length ? Just (xs.slice (0, xs.length - n)) + : Nothing; + }; } _.dropLast = { consts: {}, - types: [$.Integer, $.Array(a), $Maybe($.Array(a))], + types: [$.Integer, $.Array (a), $Maybe ($.Array (a))], impl: dropLast }; @@ -3509,27 +3616,27 @@ //. Returns the number of elements of the given structure. //. //. ```javascript - //. > S.size([]) + //. > S.size ([]) //. 0 //. - //. > S.size(['foo', 'bar', 'baz']) + //. > S.size (['foo', 'bar', 'baz']) //. 3 //. - //. > S.size(Nil) + //. > S.size (Nil) //. 0 //. - //. > S.size(Cons('foo', Cons('bar', Cons('baz', Nil)))) + //. > S.size (Cons ('foo') (Cons ('bar') (Cons ('baz') (Nil)))) //. 3 //. - //. > S.size(S.Nothing) + //. > S.size (S.Nothing) //. 0 //. - //. > S.size(S.Just('quux')) + //. > S.size (S.Just ('quux')) //. 1 //. ``` _.size = { consts: {f: [Z.Foldable]}, - types: [f(a), $.Integer], + types: [f (a), $.Integer], impl: Z.size }; @@ -3540,22 +3647,22 @@ //. See also [`prepend`](#prepend). //. //. ```javascript - //. > S.append(3, [1, 2]) + //. > S.append (3) ([1, 2]) //. [1, 2, 3] //. - //. > S.append(3, Cons(1, Cons(2, Nil))) - //. Cons(1, Cons(2, Cons(3, Nil))) + //. > S.append (3) (Cons (1) (Cons (2) (Nil))) + //. Cons (1) (Cons (2) (Cons (3) (Nil))) //. - //. > S.append([1], S.Nothing) - //. Just([1]) + //. > S.append ([1]) (S.Nothing) + //. Just ([1]) //. - //. > S.append([3], S.Just([1, 2])) - //. Just([1, 2, 3]) + //. > S.append ([3]) (S.Just ([1, 2])) + //. Just ([1, 2, 3]) //. ``` _.append = { consts: {f: [Z.Applicative, Z.Semigroup]}, - types: [a, f(a), f(a)], - impl: Z.append + types: [a, f (a), f (a)], + impl: curry2 (Z.append) }; //# prepend :: (Applicative f, Semigroup (f a)) => a -> f a -> f a @@ -3565,22 +3672,22 @@ //. See also [`append`](#append). //. //. ```javascript - //. > S.prepend(1, [2, 3]) + //. > S.prepend (1) ([2, 3]) //. [1, 2, 3] //. - //. > S.prepend(1, Cons(2, Cons(3, Nil))) - //. Cons(1, Cons(2, Cons(3, Nil))) + //. > S.prepend (1) (Cons (2) (Cons (3) (Nil))) + //. Cons (1) (Cons (2) (Cons (3) (Nil))) //. - //. > S.prepend([1], S.Nothing) - //. Just([1]) + //. > S.prepend ([1]) (S.Nothing) + //. Just ([1]) //. - //. > S.prepend([1], S.Just([2, 3])) - //. Just([1, 2, 3]) + //. > S.prepend ([1]) (S.Just ([2, 3])) + //. Just ([1, 2, 3]) //. ``` _.prepend = { consts: {f: [Z.Applicative, Z.Semigroup]}, - types: [a, f(a), f(a)], - impl: Z.prepend + types: [a, f (a), f (a)], + impl: curry2 (Z.prepend) }; //# joinWith :: String -> Array String -> String @@ -3594,15 +3701,17 @@ //. See also [`splitOn`](#splitOn). //. //. ```javascript - //. > S.joinWith(':', ['foo', 'bar', 'baz']) + //. > S.joinWith (':') (['foo', 'bar', 'baz']) //. 'foo:bar:baz' //. ``` - function joinWith(separator, ss) { - return ss.join(separator); + function joinWith(separator) { + return function(ss) { + return ss.join (separator); + }; } _.joinWith = { consts: {}, - types: [$.String, $.Array($.String), $.String], + types: [$.String, $.Array ($.String), $.String], impl: joinWith }; @@ -3614,31 +3723,31 @@ //. See also [`find`](#find). //. //. ```javascript - //. > S.elem('c', ['a', 'b', 'c']) + //. > S.elem ('c') (['a', 'b', 'c']) //. true //. - //. > S.elem('x', ['a', 'b', 'c']) + //. > S.elem ('x') (['a', 'b', 'c']) //. false //. - //. > S.elem(3, {x: 1, y: 2, z: 3}) + //. > S.elem (3) ({x: 1, y: 2, z: 3}) //. true //. - //. > S.elem(8, {x: 1, y: 2, z: 3}) + //. > S.elem (8) ({x: 1, y: 2, z: 3}) //. false //. - //. > S.elem(0, S.Just(0)) + //. > S.elem (0) (S.Just (0)) //. true //. - //. > S.elem(0, S.Just(1)) + //. > S.elem (0) (S.Just (1)) //. false //. - //. > S.elem(0, S.Nothing) + //. > S.elem (0) (S.Nothing) //. false //. ``` _.elem = { consts: {a: [Z.Setoid], f: [Z.Foldable]}, - types: [a, f(a), $.Boolean], - impl: Z.elem + types: [a, f (a), $.Boolean], + impl: curry2 (Z.elem) }; //# find :: Foldable f => (a -> Boolean) -> f a -> Maybe a @@ -3650,26 +3759,30 @@ //. See also [`elem`](#elem). //. //. ```javascript - //. > S.find(n => n < 0, [1, -2, 3, -4, 5]) - //. Just(-2) + //. > S.find (S.lt (0)) ([1, -2, 3, -4, 5]) + //. Just (-2) //. - //. > S.find(n => n < 0, [1, 2, 3, 4, 5]) + //. > S.find (S.lt (0)) ([1, 2, 3, 4, 5]) //. Nothing //. ``` - function find(pred, xs) { - return Z.reduce( - function(m, x) { return m.isJust ? m : pred(x) ? Just(x) : Nothing; }, - Nothing, - xs - ); + function find(pred) { + return function(xs) { + return Z.reduce ( + function(m, x) { + return m.isJust ? m : pred (x) ? Just (x) : Nothing; + }, + Nothing, + xs + ); + }; } _.find = { consts: {f: [Z.Foldable]}, - types: [$.Predicate(a), f(a), $Maybe(a)], + types: [$.Predicate (a), f (a), $Maybe (a)], impl: find }; - //# unfoldr :: (b -> Maybe (Pair a b)) -> b -> Array a + //# unfoldr :: (b -> Maybe (Array2 a b)) -> b -> Array a //. //. Takes a function and a seed value, and returns an array generated by //. applying the function repeatedly. The array is initially empty. The @@ -3682,17 +3795,21 @@ //. the array and the function is applied to the second element. //. //. ```javascript - //. > S.unfoldr(n => n < 5 ? S.Just([n, n + 1]) : S.Nothing, 1) + //. > S.unfoldr (n => n < 5 ? S.Just ([n, n + 1]) : S.Nothing) (1) //. [1, 2, 3, 4] //. ``` - function unfoldr(f, x) { - var result = []; - for (var m = f(x); m.isJust; m = f(m.value[1])) result.push(m.value[0]); - return result; + function unfoldr(f) { + return function(x) { + var result = []; + for (var m = f (x); m.isJust; m = f (m.value[1])) { + result.push (m.value[0]); + } + return result; + }; } _.unfoldr = { consts: {}, - types: [Fn(b, $Maybe($.Pair(a, b))), b, $.Array(a)], + types: [Fn (b) ($Maybe ($.Array2 (a) (b))), b, $.Array (a)], impl: unfoldr }; @@ -3703,23 +3820,25 @@ //. argument is less than or equal to the first argument. //. //. ```javascript - //. > S.range(0, 10) + //. > S.range (0) (10) //. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] //. - //. > S.range(-5, 0) + //. > S.range (-5) (0) //. [-5, -4, -3, -2, -1] //. - //. > S.range(0, -5) + //. > S.range (0) (-5) //. [] //. ``` - function range(from, to) { - var result = []; - for (var n = from; n < to; n += 1) result.push(n); - return result; + function range(from) { + return function(to) { + var result = []; + for (var n = from; n < to; n += 1) result.push (n); + return result; + }; } _.range = { consts: {}, - types: [$.Integer, $.Integer, $.Array($.Integer)], + types: [$.Integer, $.Integer, $.Array ($.Integer)], impl: range }; @@ -3737,26 +3856,28 @@ //. S.join(S.groupBy(f, xs)) = xs` //. //. ```javascript - //. > S.groupBy(S.equals, [1, 1, 2, 1, 1]) + //. > S.groupBy (S.equals) ([1, 1, 2, 1, 1]) //. [[1, 1], [2], [1, 1]] //. - //. > S.groupBy(x => y => x + y === 0, [2, -3, 3, 3, 3, 4, -4, 4]) + //. > S.groupBy (x => y => x + y === 0) ([2, -3, 3, 3, 3, 4, -4, 4]) //. [[2], [-3, 3, 3, 3], [4, -4], [4]] //. ``` - function groupBy(f, xs) { - if (xs.length === 0) return []; - var x0 = xs[0]; // :: a - var active = [x0]; // :: Array a - var result = [active]; // :: Array (Array a) - for (var idx = 1; idx < xs.length; idx += 1) { - var x = xs[idx]; - if (f(x0)(x)) active.push(x); else result.push(active = [x0 = x]); - } - return result; + function groupBy(f) { + return function(xs) { + if (xs.length === 0) return []; + var x0 = xs[0]; // :: a + var active = [x0]; // :: Array a + var result = [active]; // :: Array (Array a) + for (var idx = 1; idx < xs.length; idx += 1) { + var x = xs[idx]; + if (f (x0) (x)) active.push (x); else result.push (active = [x0 = x]); + } + return result; + }; } _.groupBy = { consts: {}, - types: [Fn(a, $.Predicate(a)), $.Array(a), $.Array($.Array(a))], + types: [Fn (a) ($.Predicate (a)), $.Array (a), $.Array ($.Array (a))], impl: groupBy }; @@ -3765,18 +3886,18 @@ //. Reverses the elements of the given structure. //. //. ```javascript - //. > S.reverse([1, 2, 3]) + //. > S.reverse ([1, 2, 3]) //. [3, 2, 1] //. - //. > S.reverse(Cons(1, Cons(2, Cons(3, Nil)))) - //. Cons(3, Cons(2, Cons(1, Nil))) + //. > S.reverse (Cons (1) (Cons (2) (Cons (3) (Nil)))) + //. Cons (3) (Cons (2) (Cons (1) (Nil))) //. - //. > S.pipe([S.splitOn(''), S.reverse, S.joinWith('')], 'abc') + //. > S.pipe ([S.splitOn (''), S.reverse, S.joinWith ('')]) ('abc') //. 'cba' //. ``` _.reverse = { consts: {f: [Z.Applicative, Z.Foldable, Z.Monoid]}, - types: [f(a), f(a)], + types: [f (a), f (a)], impl: Z.reverse }; @@ -3792,15 +3913,15 @@ //. See also [`sortBy`](#sortBy). //. //. ```javascript - //. > S.sort(['foo', 'bar', 'baz']) + //. > S.sort (['foo', 'bar', 'baz']) //. ['bar', 'baz', 'foo'] //. - //. > S.sort([S.Left(4), S.Right(3), S.Left(2), S.Right(1)]) - //. [Left(2), Left(4), Right(1), Right(3)] + //. > S.sort ([S.Left (4), S.Right (3), S.Left (2), S.Right (1)]) + //. [Left (2), Left (4), Right (1), Right (3)] //. ``` _.sort = { consts: {a: [Z.Ord], m: [Z.Applicative, Z.Foldable, Z.Monoid]}, - types: [m(a), m(a)], + types: [m (a), m (a)], impl: Z.sort }; @@ -3817,7 +3938,7 @@ //. See also [`sort`](#sort). //. //. ```javascript - //. > S.sortBy(S.prop('rank'), [ + //. > S.sortBy (S.prop ('rank')) ([ //. . {rank: 7, suit: 'spades'}, //. . {rank: 5, suit: 'hearts'}, //. . {rank: 2, suit: 'hearts'}, @@ -3828,7 +3949,7 @@ //. . {rank: 5, suit: 'spades'}, //. . {rank: 7, suit: 'spades'} ] //. - //. > S.sortBy(S.prop('suit'), [ + //. > S.sortBy (S.prop ('suit')) ([ //. . {rank: 7, suit: 'spades'}, //. . {rank: 5, suit: 'hearts'}, //. . {rank: 2, suit: 'hearts'}, @@ -3841,11 +3962,11 @@ //. ``` _.sortBy = { consts: {b: [Z.Ord], m: [Z.Applicative, Z.Foldable, Z.Monoid]}, - types: [Fn(a, b), m(a), m(a)], - impl: Z.sortBy + types: [Fn (a) (b), m (a), m (a)], + impl: curry2 (Z.sortBy) }; - //# zip :: Array a -> Array b -> Array (Pair a b) + //# zip :: Array a -> Array b -> Array (Array2 a b) //. //. Returns an array of pairs of corresponding elements from the given //. arrays. The length of the resulting array is equal to the length of @@ -3854,19 +3975,16 @@ //. See also [`zipWith`](#zipWith). //. //. ```javascript - //. > S.zip(['a', 'b'], ['x', 'y', 'z']) + //. > S.zip (['a', 'b']) (['x', 'y', 'z']) //. [['a', 'x'], ['b', 'y']] //. - //. > S.zip([1, 3, 5], [2, 4]) + //. > S.zip ([1, 3, 5]) ([2, 4]) //. [[1, 2], [3, 4]] //. ``` - function zip(xs, ys) { - return zipWith(pair, xs, ys); - } _.zip = { consts: {}, - types: [$.Array(a), $.Array(b), $.Array($.Pair(a, b))], - impl: zip + types: [$.Array (a), $.Array (b), $.Array ($.Array2 (a) (b))], + impl: zipWith (pair) }; //# zipWith :: (a -> b -> c) -> Array a -> Array b -> Array c @@ -3878,21 +3996,27 @@ //. See also [`zip`](#zip). //. //. ```javascript - //. > S.zipWith(a => b => a + b, ['a', 'b'], ['x', 'y', 'z']) + //. > S.zipWith (a => b => a + b) (['a', 'b']) (['x', 'y', 'z']) //. ['ax', 'by'] //. - //. > S.zipWith(a => b => [a, b], [1, 3, 5], [2, 4]) + //. > S.zipWith (a => b => [a, b]) ([1, 3, 5]) ([2, 4]) //. [[1, 2], [3, 4]] //. ``` - function zipWith(f, xs, ys) { - var result = []; - var len = Math.min(xs.length, ys.length); - for (var idx = 0; idx < len; idx += 1) result.push(f(xs[idx])(ys[idx])); - return result; + function zipWith(f) { + return function(xs) { + return function(ys) { + var result = []; + var len = Math.min (xs.length, ys.length); + for (var idx = 0; idx < len; idx += 1) { + result.push (f (xs[idx]) (ys[idx])); + } + return result; + }; + }; } _.zipWith = { consts: {}, - types: [Fn(a, Fn(b, c)), $.Array(a), $.Array(b), $.Array(c)], + types: [Fn (a) (Fn (b) (c)), $.Array (a), $.Array (b), $.Array (c)], impl: zipWith }; @@ -3907,14 +4031,16 @@ //. For accessing properties of uncertain objects, use [`get`](#get) instead. //. //. ```javascript - //. > S.prop('a', {a: 1, b: 2}) + //. > S.prop ('a') ({a: 1, b: 2}) //. 1 //. ``` - function prop(key, x) { - var obj = toObject(x); - if (key in obj) return obj[key]; - throw new TypeError('‘prop’ expected object to have a property named ‘' + - key + '’; ' + Z.toString(x) + ' does not'); + function prop(key) { + return function(x) { + var obj = toObject (x); + if (key in obj) return obj[key]; + throw new TypeError ('‘prop’ expected object to have a property named ' + + '‘' + key + '’; ' + Z.toString (x) + ' does not'); + }; } _.prop = { consts: {}, @@ -3932,21 +4058,23 @@ //. instead. //. //. ```javascript - //. > S.props(['a', 'b', 'c'], {a: {b: {c: 1}}}) + //. > S.props (['a', 'b', 'c']) ({a: {b: {c: 1}}}) //. 1 //. ``` - function props(path, x) { - return path.reduce(function(x, key) { - var obj = toObject(x); - if (key in obj) return obj[key]; - throw new TypeError('‘props’ expected object to have a property at ' + - Z.toString(path) + '; ' + - Z.toString(x) + ' does not'); - }, x); + function props(path) { + return function(x) { + return path.reduce (function(x, key) { + var obj = toObject (x); + if (key in obj) return obj[key]; + throw new TypeError ('‘props’ expected object to have a property at ' + + Z.toString (path) + '; ' + + Z.toString (x) + ' does not'); + }, x); + }; } _.props = { consts: {}, - types: [$.Array($.String), a, b], + types: [$.Array ($.String), a, b], impl: props }; @@ -3959,32 +4087,27 @@ //. See also [`gets`](#gets) and [`prop`](#prop). //. //. ```javascript - //. > S.get(S.is($.Number), 'x', {x: 1, y: 2}) - //. Just(1) + //. > S.get (S.is ($.Number)) ('x') ({x: 1, y: 2}) + //. Just (1) //. - //. > S.get(S.is($.Number), 'x', {x: '1', y: '2'}) + //. > S.get (S.is ($.Number)) ('x') ({x: '1', y: '2'}) //. Nothing //. - //. > S.get(S.is($.Number), 'x', {}) + //. > S.get (S.is ($.Number)) ('x') ({}) //. Nothing //. - //. > S.get(S.is($.Array($.Number)), 'x', {x: [1, 2, 3]}) - //. Just([1, 2, 3]) + //. > S.get (S.is ($.Array ($.Number))) ('x') ({x: [1, 2, 3]}) + //. Just ([1, 2, 3]) //. - //. > S.get(S.is($.Array($.Number)), 'x', {x: [1, 2, 3, null]}) + //. > S.get (S.is ($.Array ($.Number))) ('x') ({x: [1, 2, 3, null]}) //. Nothing //. ``` - function get(pred, key, x) { - var obj = toObject(x); - if (key in obj) { - var val = obj[key]; - if (pred(val)) return Just(val); - } - return Nothing; + function get(pred) { + return B (B (filter (pred))) (get_); } _.get = { consts: {}, - types: [$.Predicate($.Any), $.String, a, $Maybe(b)], + types: [$.Predicate ($.Any), $.String, a, $Maybe (b)], impl: get }; @@ -3997,26 +4120,27 @@ //. See also [`get`](#get). //. //. ```javascript - //. > S.gets(S.is($.Number), ['a', 'b', 'c'], {a: {b: {c: 42}}}) - //. Just(42) + //. > S.gets (S.is ($.Number)) (['a', 'b', 'c']) ({a: {b: {c: 42}}}) + //. Just (42) //. - //. > S.gets(S.is($.Number), ['a', 'b', 'c'], {a: {b: {c: '42'}}}) + //. > S.gets (S.is ($.Number)) (['a', 'b', 'c']) ({a: {b: {c: '42'}}}) //. Nothing //. - //. > S.gets(S.is($.Number), ['a', 'b', 'c'], {}) + //. > S.gets (S.is ($.Number)) (['a', 'b', 'c']) ({}) //. Nothing //. ``` - function gets(pred, keys, x) { - return Z.filter(pred, Z.reduce(function(m, key) { - return Z.chain(function(x) { - var obj = toObject(x); - return key in obj ? Just(obj[key]) : Nothing; - }, m); - }, Just(x), keys)); + function gets(pred) { + return function(keys) { + return function(x) { + return Z.filter (pred, keys.reduce (function(maybe, key) { + return Z.chain (get_ (key), maybe); + }, Just (x))); + }; + }; } _.gets = { consts: {}, - types: [$.Predicate($.Any), $.Array($.String), a, $Maybe(b)], + types: [$.Predicate ($.Any), $.Array ($.String), a, $Maybe (b)], impl: gets }; @@ -4034,17 +4158,19 @@ //. a single entry (mapping the key to the value). //. //. ```javascript - //. > S.singleton('foo', 42) + //. > S.singleton ('foo') (42) //. {foo: 42} //. ``` - function singleton(key, val) { - var strMap = {}; - strMap[key] = val; - return strMap; + function singleton(key) { + return function(val) { + var strMap = {}; + strMap[key] = val; + return strMap; + }; } _.singleton = { consts: {}, - types: [$.String, a, $.StrMap(a)], + types: [$.String, a, $.StrMap (a)], impl: singleton }; @@ -4058,18 +4184,22 @@ //. function. //. //. ```javascript - //. > S.insert('c', 3, {a: 1, b: 2}) + //. > S.insert ('c') (3) ({a: 1, b: 2}) //. {a: 1, b: 2, c: 3} //. - //. > S.insert('a', 4, {a: 1, b: 2}) + //. > S.insert ('a') (4) ({a: 1, b: 2}) //. {a: 4, b: 2} //. ``` - function insert(key, val, strMap) { - return Z.concat(strMap, singleton(key, val)); + function insert(key) { + return function(val) { + return function(strMap) { + return Z.concat (strMap, singleton (key) (val)); + }; + }; } _.insert = { consts: {}, - types: [$.String, a, $.StrMap(a), $.StrMap(a)], + types: [$.String, a, $.StrMap (a), $.StrMap (a)], impl: insert }; @@ -4083,20 +4213,22 @@ //. function. //. //. ```javascript - //. > S.remove('c', {a: 1, b: 2, c: 3}) + //. > S.remove ('c') ({a: 1, b: 2, c: 3}) //. {a: 1, b: 2} //. - //. > S.remove('c', {}) + //. > S.remove ('c') ({}) //. {} //. ``` - function remove(key, strMap) { - var result = Z.concat(strMap, {}); - delete result[key]; - return result; + function remove(key) { + return function(strMap) { + var result = Z.concat (strMap, {}); + delete result[key]; + return result; + }; } _.remove = { consts: {}, - types: [$.String, $.StrMap(a), $.StrMap(a)], + types: [$.String, $.StrMap (a), $.StrMap (a)], impl: remove }; @@ -4105,12 +4237,12 @@ //. Returns the keys of the given string map, in arbitrary order. //. //. ```javascript - //. > S.sort(S.keys({b: 2, c: 3, a: 1})) + //. > S.sort (S.keys ({b: 2, c: 3, a: 1})) //. ['a', 'b', 'c'] //. ``` _.keys = { consts: {}, - types: [$.StrMap(a), $.Array($.String)], + types: [$.StrMap (a), $.Array ($.String)], impl: Object.keys }; @@ -4119,57 +4251,58 @@ //. Returns the values of the given string map, in arbitrary order. //. //. ```javascript - //. > S.sort(S.values({a: 1, c: 3, b: 2})) + //. > S.sort (S.values ({a: 1, c: 3, b: 2})) //. [1, 2, 3] //. ``` function values(strMap) { - return Z.map(function(k) { return strMap[k]; }, Object.keys(strMap)); + return Z.map (function(k) { return strMap[k]; }, Object.keys (strMap)); } _.values = { consts: {}, - types: [$.StrMap(a), $.Array(a)], + types: [$.StrMap (a), $.Array (a)], impl: values }; - //# pairs :: StrMap a -> Array (Pair String a) + //# pairs :: StrMap a -> Array (Array2 String a) //. //. Returns the key–value pairs of the given string map, in arbitrary order. //. //. ```javascript - //. > S.sort(S.pairs({b: 2, a: 1, c: 3})) + //. > S.sort (S.pairs ({b: 2, a: 1, c: 3})) //. [['a', 1], ['b', 2], ['c', 3]] //. ``` function pairs(strMap) { - return Z.map(function(k) { return [k, strMap[k]]; }, Object.keys(strMap)); + return Z.map (function(k) { return [k, strMap[k]]; }, + Object.keys (strMap)); } _.pairs = { consts: {}, - types: [$.StrMap(a), $.Array($.Pair($.String, a))], + types: [$.StrMap (a), $.Array ($.Array2 ($.String) (a))], impl: pairs }; - //# fromPairs :: Foldable f => f (Pair String a) -> StrMap a + //# fromPairs :: Foldable f => f (Array2 String a) -> StrMap a //. //. Returns a string map containing the key–value pairs specified by the //. given [Foldable][]. If a key appears in multiple pairs, the rightmost //. pair takes precedence. //. //. ```javascript - //. > S.fromPairs([['a', 1], ['b', 2], ['c', 3]]) + //. > S.fromPairs ([['a', 1], ['b', 2], ['c', 3]]) //. {a: 1, b: 2, c: 3} //. - //. > S.fromPairs([['x', 1], ['x', 2]]) + //. > S.fromPairs ([['x', 1], ['x', 2]]) //. {x: 2} //. ``` function fromPairs(pairs) { - return Z.reduce(function(strMap, pair) { + return Z.reduce (function(strMap, pair) { strMap[pair[0]] = pair[1]; return strMap; }, {}, pairs); } _.fromPairs = { consts: {f: [Z.Foldable]}, - types: [f($.Pair($.String, a)), $.StrMap(a)], + types: [f ($.Array2 ($.String) (a)), $.StrMap (a)], impl: fromPairs }; @@ -4180,10 +4313,10 @@ //. Negates its argument. //. //. ```javascript - //. > S.negate(12.5) + //. > S.negate (12.5) //. -12.5 //. - //. > S.negate(-42) + //. > S.negate (-42) //. 42 //. ``` function negate(n) { @@ -4200,11 +4333,13 @@ //. Returns the sum of two (finite) numbers. //. //. ```javascript - //. > S.add(1, 1) + //. > S.add (1) (1) //. 2 //. ``` - function add(x, y) { - return x + y; + function add(x) { + return function(y) { + return x + y; + }; } _.add = { consts: {}, @@ -4217,33 +4352,30 @@ //. Returns the sum of the given array of (finite) numbers. //. //. ```javascript - //. > S.sum([1, 2, 3, 4, 5]) + //. > S.sum ([1, 2, 3, 4, 5]) //. 15 //. - //. > S.sum([]) + //. > S.sum ([]) //. 0 //. - //. > S.sum(S.Just(42)) + //. > S.sum (S.Just (42)) //. 42 //. - //. > S.sum(S.Nothing) + //. > S.sum (S.Nothing) //. 0 //. ``` - function sum(foldable) { - return Z.reduce(add, 0, foldable); - } _.sum = { consts: {f: [Z.Foldable]}, - types: [f($.FiniteNumber), $.FiniteNumber], - impl: sum + types: [f ($.FiniteNumber), $.FiniteNumber], + impl: reduce (add) (0) }; - //# sub :: FiniteNumber -> (FiniteNumber -> FiniteNumber) + //# sub :: FiniteNumber -> FiniteNumber -> FiniteNumber //. //. Takes a finite number `n` and returns the _subtract `n`_ function. //. //. ```javascript - //. > S.map(S.sub(1), [1, 2, 3]) + //. > S.map (S.sub (1)) ([1, 2, 3]) //. [0, 1, 2] //. ``` function sub(y) { @@ -4253,7 +4385,7 @@ } _.sub = { consts: {}, - types: [$.FiniteNumber, Fn($.FiniteNumber, $.FiniteNumber)], + types: [$.FiniteNumber, $.FiniteNumber, $.FiniteNumber], impl: sub }; @@ -4262,11 +4394,13 @@ //. Returns the product of two (finite) numbers. //. //. ```javascript - //. > S.mult(4, 2) + //. > S.mult (4) (2) //. 8 //. ``` - function mult(x, y) { - return x * y; + function mult(x) { + return function(y) { + return x * y; + }; } _.mult = { consts: {}, @@ -4279,34 +4413,31 @@ //. Returns the product of the given array of (finite) numbers. //. //. ```javascript - //. > S.product([1, 2, 3, 4, 5]) + //. > S.product ([1, 2, 3, 4, 5]) //. 120 //. - //. > S.product([]) + //. > S.product ([]) //. 1 //. - //. > S.product(S.Just(42)) + //. > S.product (S.Just (42)) //. 42 //. - //. > S.product(S.Nothing) + //. > S.product (S.Nothing) //. 1 //. ``` - function product(foldable) { - return Z.reduce(mult, 1, foldable); - } _.product = { consts: {f: [Z.Foldable]}, - types: [f($.FiniteNumber), $.FiniteNumber], - impl: product + types: [f ($.FiniteNumber), $.FiniteNumber], + impl: reduce (mult) (1) }; - //# div :: NonZeroFiniteNumber -> (FiniteNumber -> FiniteNumber) + //# div :: NonZeroFiniteNumber -> FiniteNumber -> FiniteNumber //. //. Takes a non-zero finite number `n` and returns the _divide by `n`_ //. function. //. //. ```javascript - //. > S.map(S.div(2), [0, 1, 2, 3]) + //. > S.map (S.div (2)) ([0, 1, 2, 3]) //. [0, 0.5, 1, 1.5] //. ``` function div(y) { @@ -4316,29 +4447,29 @@ } _.div = { consts: {}, - types: [$.NonZeroFiniteNumber, Fn($.FiniteNumber, $.FiniteNumber)], + types: [$.NonZeroFiniteNumber, $.FiniteNumber, $.FiniteNumber], impl: div }; - //# pow :: FiniteNumber -> (FiniteNumber -> FiniteNumber) + //# pow :: FiniteNumber -> FiniteNumber -> FiniteNumber //. //. Takes a finite number `n` and returns the _power of `n`_ function. //. //. ```javascript - //. > S.map(S.pow(2), [-3, -2, -1, 0, 1, 2, 3]) + //. > S.map (S.pow (2)) ([-3, -2, -1, 0, 1, 2, 3]) //. [9, 4, 1, 0, 1, 4, 9] //. - //. > S.map(S.pow(0.5), [1, 4, 9, 16, 25]) + //. > S.map (S.pow (0.5)) ([1, 4, 9, 16, 25]) //. [1, 2, 3, 4, 5] //. ``` function pow(exp) { return function(base) { - return Math.pow(base, exp); + return Math.pow (base, exp); }; } _.pow = { consts: {}, - types: [$.FiniteNumber, Fn($.FiniteNumber, $.FiniteNumber)], + types: [$.FiniteNumber, $.FiniteNumber, $.FiniteNumber], impl: pow }; @@ -4347,20 +4478,20 @@ //. Returns the mean of the given array of (finite) numbers. //. //. ```javascript - //. > S.mean([1, 2, 3, 4, 5]) - //. Just(3) + //. > S.mean ([1, 2, 3, 4, 5]) + //. Just (3) //. - //. > S.mean([]) + //. > S.mean ([]) //. Nothing //. - //. > S.mean(S.Just(42)) - //. Just(42) + //. > S.mean (S.Just (42)) + //. Just (42) //. - //. > S.mean(S.Nothing) + //. > S.mean (S.Nothing) //. Nothing //. ``` function mean(foldable) { - var result = Z.reduce( + var result = Z.reduce ( function(acc, n) { acc.total += n; acc.count += 1; @@ -4369,11 +4500,11 @@ {total: 0, count: 0}, foldable ); - return result.count > 0 ? Just(result.total / result.count) : Nothing; + return result.count > 0 ? Just (result.total / result.count) : Nothing; } _.mean = { consts: {f: [Z.Foldable]}, - types: [f($.FiniteNumber), $Maybe($.FiniteNumber)], + types: [f ($.FiniteNumber), $Maybe ($.FiniteNumber)], impl: mean }; @@ -4384,10 +4515,10 @@ //. Returns `true` if the given integer is even; `false` if it is odd. //. //. ```javascript - //. > S.even(42) + //. > S.even (42) //. true //. - //. > S.even(99) + //. > S.even (99) //. false //. ``` function even(n) { @@ -4404,10 +4535,10 @@ //. Returns `true` if the given integer is odd; `false` if it is even. //. //. ```javascript - //. > S.odd(99) + //. > S.odd (99) //. true //. - //. > S.odd(42) + //. > S.odd (42) //. false //. ``` function odd(n) { @@ -4427,47 +4558,47 @@ //. if it does in fact represent a date; Nothing otherwise. //. //. ```javascript - //. > S.parseDate('2011-01-19T17:40:00Z') - //. Just(new Date('2011-01-19T17:40:00.000Z')) + //. > S.parseDate ('2011-01-19T17:40:00Z') + //. Just (new Date ('2011-01-19T17:40:00.000Z')) //. - //. > S.parseDate('today') + //. > S.parseDate ('today') //. Nothing //. ``` function parseDate(s) { - var date = new Date(s); - return isNaN(date.valueOf()) ? Nothing : Just(date); + var date = new Date (s); + return isNaN (date.valueOf ()) ? Nothing : Just (date); } _.parseDate = { consts: {}, - types: [$.String, $Maybe($.ValidDate)], + types: [$.String, $Maybe ($.ValidDate)], impl: parseDate }; // requiredNonCapturingGroup :: Array String -> String function requiredNonCapturingGroup(xs) { - return '(?:' + xs.join('|') + ')'; + return '(?:' + xs.join ('|') + ')'; } // optionalNonCapturingGroup :: Array String -> String function optionalNonCapturingGroup(xs) { - return requiredNonCapturingGroup(xs) + '?'; + return requiredNonCapturingGroup (xs) + '?'; } // validFloatRepr :: RegExp - var validFloatRepr = new RegExp( + var validFloatRepr = new RegExp ( '^' + // start-of-string anchor '\\s*' + // any number of leading whitespace characters '[+-]?' + // optional sign - requiredNonCapturingGroup([ + requiredNonCapturingGroup ([ 'Infinity', // "Infinity" 'NaN', // "NaN" - requiredNonCapturingGroup([ + requiredNonCapturingGroup ([ '[0-9]+', // number '[0-9]+[.][0-9]+', // number with interior decimal point '[0-9]+[.]', // number with trailing decimal point '[.][0-9]+' // number with leading decimal point ]) + - optionalNonCapturingGroup([ + optionalNonCapturingGroup ([ '[Ee]' + // "E" or "e" '[+-]?' + // optional sign '[0-9]+' // exponent @@ -4483,27 +4614,26 @@ //. if it does in fact represent a number; Nothing otherwise. //. //. ```javascript - //. > S.parseFloat('-123.45') - //. Just(-123.45) + //. > S.parseFloat ('-123.45') + //. Just (-123.45) //. - //. > S.parseFloat('foo.bar') + //. > S.parseFloat ('foo.bar') //. Nothing //. ``` function parseFloat_(s) { - return validFloatRepr.test(s) ? Just(parseFloat(s)) : Nothing; + return validFloatRepr.test (s) ? Just (parseFloat (s)) : Nothing; } _.parseFloat = { consts: {}, - types: [$.String, $Maybe($.Number)], + types: [$.String, $Maybe ($.Number)], impl: parseFloat_ }; // Radix :: Type - var Radix = $.NullaryType( - 'sanctuary/Radix', - '', - function(x) { return $.Integer._test(x) && x >= 2 && x <= 36; } - ); + var Radix = $.NullaryType + ('sanctuary/Radix') + ('') + (function(x) { return $.Integer._test (x) && x >= 2 && x <= 36; }); //# parseInt :: Radix -> String -> Maybe Integer //. @@ -4517,29 +4647,31 @@ //. characters are members of the character set specified by the radix. //. //. ```javascript - //. > S.parseInt(10, '-42') - //. Just(-42) + //. > S.parseInt (10) ('-42') + //. Just (-42) //. - //. > S.parseInt(16, '0xFF') - //. Just(255) + //. > S.parseInt (16) ('0xFF') + //. Just (255) //. - //. > S.parseInt(16, '0xGG') + //. > S.parseInt (16) ('0xGG') //. Nothing //. ``` - function parseInt_(radix, s) { - var charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.slice(0, radix); - var pattern = new RegExp('^[' + charset + ']+$', 'i'); + function parseInt_(radix) { + return function(s) { + var charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.slice (0, radix); + var pattern = new RegExp ('^[' + charset + ']+$', 'i'); - var t = s.replace(/^[+-]/, ''); - if (pattern.test(radix === 16 ? t.replace(/^0x/i, '') : t)) { - var n = parseInt(s, radix); - if ($.Integer._test(n)) return Just(n); - } - return Nothing; + var t = s.replace (/^[+-]/, ''); + if (pattern.test (radix === 16 ? t.replace (/^0x/i, '') : t)) { + var n = parseInt (s, radix); + if ($.Integer._test (n)) return Just (n); + } + return Nothing; + }; } _.parseInt = { consts: {}, - types: [Radix, $.String, $Maybe($.Integer)], + types: [Radix, $.String, $Maybe ($.Integer)], impl: parseInt_ }; @@ -4550,44 +4682,44 @@ //. result satisfies the predicate; Nothing otherwise. //. //. ```javascript - //. > S.parseJson(S.is($.Array($.Integer)), '[') + //. > S.parseJson (S.is ($.Array ($.Integer))) ('[') //. Nothing //. - //. > S.parseJson(S.is($.Array($.Integer)), '["1","2","3"]') + //. > S.parseJson (S.is ($.Array ($.Integer))) ('["1","2","3"]') //. Nothing //. - //. > S.parseJson(S.is($.Array($.Integer)), '[0,1.5,3,4.5]') + //. > S.parseJson (S.is ($.Array ($.Integer))) ('[0,1.5,3,4.5]') //. Nothing //. - //. > S.parseJson(S.is($.Array($.Integer)), '[1,2,3]') - //. Just([1, 2, 3]) + //. > S.parseJson (S.is ($.Array ($.Integer))) ('[1,2,3]') + //. Just ([1, 2, 3]) //. ``` - function parseJson(pred, s) { - return Z.filter(pred, encase(JSON.parse, s)); + function parseJson(pred) { + return B (filter (pred)) (encase (JSON.parse)); } _.parseJson = { consts: {}, - types: [$.Predicate($.Any), $.String, $Maybe(a)], + types: [$.Predicate ($.Any), $.String, $Maybe (a)], impl: parseJson }; //. ### RegExp // Match :: Type - var Match = $.RecordType({ + var Match = $.RecordType ({ match: $.String, - groups: $.Array($Maybe($.String)) + groups: $.Array ($Maybe ($.String)) }); // toMatch :: Array String? -> Match function toMatch(ss) { - return {match: ss[0], groups: ss.slice(1).map(toMaybe)}; + return {match: ss[0], groups: Z.map (toMaybe, ss.slice (1))}; } // withRegex :: (RegExp, () -> a) -> a function withRegex(pattern, thunk) { var lastIndex = pattern.lastIndex; - var result = thunk(); + var result = thunk (); pattern.lastIndex = lastIndex; return result; } @@ -4597,11 +4729,13 @@ //. Takes a [RegexFlags][] and a pattern, and returns a RegExp. //. //. ```javascript - //. > S.regex('g', ':\\d+:') + //. > S.regex ('g') (':\\d+:') //. /:\d+:/g //. ``` - function regex(flags, source) { - return new RegExp(source, flags); + function regex(flags) { + return function(source) { + return new RegExp (source, flags); + }; } _.regex = { consts: {}, @@ -4619,11 +4753,11 @@ //. - `forall s :: String. S.test(S.regex('', S.regexEscape(s)), s) = true` //. //. ```javascript - //. > S.regexEscape('-=*{XYZ}*=-') + //. > S.regexEscape ('-=*{XYZ}*=-') //. '\\-=\\*\\{XYZ\\}\\*=\\-' //. ``` function regexEscape(s) { - return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); + return s.replace (/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); } _.regexEscape = { consts: {}, @@ -4637,14 +4771,16 @@ //. matches the string. //. //. ```javascript - //. > S.test(/^a/, 'abacus') + //. > S.test (/^a/) ('abacus') //. true //. - //. > S.test(/^a/, 'banana') + //. > S.test (/^a/) ('banana') //. false //. ``` - function test(pattern, s) { - return withRegex(pattern, function() { return pattern.test(s); }); + function test(pattern) { + return function(s) { + return withRegex (pattern, function() { return pattern.test (s); }); + }; } _.test = { consts: {}, @@ -4668,18 +4804,20 @@ //. See also [`matchAll`](#matchAll). //. //. ```javascript - //. > S.match(/(good)?bye/, 'goodbye') - //. Just({match: 'goodbye', groups: [Just('good')]}) + //. > S.match (/(good)?bye/) ('goodbye') + //. Just ({match: 'goodbye', groups: [Just ('good')]}) //. - //. > S.match(/(good)?bye/, 'bye') - //. Just({match: 'bye', groups: [Nothing]}) + //. > S.match (/(good)?bye/) ('bye') + //. Just ({match: 'bye', groups: [Nothing]}) //. ``` - function match(pattern, s) { - return Z.map(toMatch, toMaybe(s.match(pattern))); + function match(pattern) { + return function(s) { + return Z.map (toMatch, toMaybe (s.match (pattern))); + }; } _.match = { consts: {}, - types: [$.NonGlobalRegExp, $.String, $Maybe(Match)], + types: [$.NonGlobalRegExp, $.String, $Maybe (Match)], impl: match }; @@ -4693,26 +4831,28 @@ //. See also [`match`](#match). //. //. ```javascript - //. > S.matchAll(/@([a-z]+)/g, 'Hello, world!') + //. > S.matchAll (/@([a-z]+)/g) ('Hello, world!') //. [] //. - //. > S.matchAll(/@([a-z]+)/g, 'Hello, @foo! Hello, @bar! Hello, @baz!') - //. [ {match: '@foo', groups: [Just('foo')]}, - //. . {match: '@bar', groups: [Just('bar')]}, - //. . {match: '@baz', groups: [Just('baz')]} ] - //. ``` - function matchAll(pattern, s) { - return withRegex(pattern, function() { - return unfoldr(function(_) { - return Z.map(function(ss) { - return [toMatch(ss), null]; - }, toMaybe(pattern.exec(s))); - }, []); - }); + //. > S.matchAll (/@([a-z]+)/g) ('Hello, @foo! Hello, @bar! Hello, @baz!') + //. [ {match: '@foo', groups: [Just ('foo')]}, + //. . {match: '@bar', groups: [Just ('bar')]}, + //. . {match: '@baz', groups: [Just ('baz')]} ] + //. ``` + function matchAll(pattern) { + return function(s) { + return withRegex (pattern, function() { + return unfoldr (function(_) { + return Z.map (function(ss) { + return [toMatch (ss), null]; + }, toMaybe (pattern.exec (s))); + }) ([]); + }); + }; } _.matchAll = { consts: {}, - types: [$.GlobalRegExp, $.String, $.Array(Match)], + types: [$.GlobalRegExp, $.String, $.Array (Match)], impl: matchAll }; @@ -4725,11 +4865,11 @@ //. See also [`toLower`](#toLower). //. //. ```javascript - //. > S.toUpper('ABC def 123') + //. > S.toUpper ('ABC def 123') //. 'ABC DEF 123' //. ``` function toUpper(s) { - return s.toUpperCase(); + return s.toUpperCase (); } _.toUpper = { consts: {}, @@ -4744,11 +4884,11 @@ //. See also [`toUpper`](#toUpper). //. //. ```javascript - //. > S.toLower('ABC def 123') + //. > S.toLower ('ABC def 123') //. 'abc def 123' //. ``` function toLower(s) { - return s.toLowerCase(); + return s.toLowerCase (); } _.toLower = { consts: {}, @@ -4761,11 +4901,11 @@ //. Strips leading and trailing whitespace characters. //. //. ```javascript - //. > S.trim('\t\t foo bar \n') + //. > S.trim ('\t\t foo bar \n') //. 'foo bar' //. ``` function trim(s) { - return s.trim(); + return s.trim (); } _.trim = { consts: {}, @@ -4782,19 +4922,21 @@ //. See also [`stripSuffix`](#stripSuffix). //. //. ```javascript - //. > S.stripPrefix('https://', 'https://sanctuary.js.org') - //. Just('sanctuary.js.org') + //. > S.stripPrefix ('https://') ('https://sanctuary.js.org') + //. Just ('sanctuary.js.org') //. - //. > S.stripPrefix('https://', 'http://sanctuary.js.org') + //. > S.stripPrefix ('https://') ('http://sanctuary.js.org') //. Nothing //. ``` - function stripPrefix(prefix, s) { - var idx = prefix.length; - return s.slice(0, idx) === prefix ? Just(s.slice(idx)) : Nothing; + function stripPrefix(prefix) { + return function(s) { + var idx = prefix.length; + return s.slice (0, idx) === prefix ? Just (s.slice (idx)) : Nothing; + }; } _.stripPrefix = { consts: {}, - types: [$.String, $.String, $Maybe($.String)], + types: [$.String, $.String, $Maybe ($.String)], impl: stripPrefix }; @@ -4807,19 +4949,21 @@ //. See also [`stripPrefix`](#stripPrefix). //. //. ```javascript - //. > S.stripSuffix('.md', 'README.md') - //. Just('README') + //. > S.stripSuffix ('.md') ('README.md') + //. Just ('README') //. - //. > S.stripSuffix('.md', 'README') + //. > S.stripSuffix ('.md') ('README') //. Nothing //. ``` - function stripSuffix(suffix, s) { - var idx = s.length - suffix.length; // value may be negative - return s.slice(idx) === suffix ? Just(s.slice(0, idx)) : Nothing; + function stripSuffix(suffix) { + return function(s) { + var idx = s.length - suffix.length; // value may be negative + return s.slice (idx) === suffix ? Just (s.slice (0, idx)) : Nothing; + }; } _.stripSuffix = { consts: {}, - types: [$.String, $.String, $Maybe($.String)], + types: [$.String, $.String, $Maybe ($.String)], impl: stripSuffix }; @@ -4831,17 +4975,18 @@ //. See also [`unwords`](#unwords). //. //. ```javascript - //. > S.words(' foo bar baz ') + //. > S.words (' foo bar baz ') //. ['foo', 'bar', 'baz'] //. ``` function words(s) { - var words = s.split(/\s+/); - return words.slice(words[0] === '' ? 1 : 0, - words[words.length - 1] === '' ? -1 : Infinity); + var words = s.split (/\s+/); + var len = words.length; + return words.slice (words[0] === '' ? 1 : 0, + words[len - 1] === '' ? len - 1 : len); } _.words = { consts: {}, - types: [$.String, $.Array($.String)], + types: [$.String, $.Array ($.String)], impl: words }; @@ -4853,16 +4998,13 @@ //. See also [`words`](#words). //. //. ```javascript - //. > S.unwords(['foo', 'bar', 'baz']) + //. > S.unwords (['foo', 'bar', 'baz']) //. 'foo bar baz' //. ``` - function unwords(xs) { - return xs.join(' '); - } _.unwords = { consts: {}, - types: [$.Array($.String), $.String], - impl: unwords + types: [$.Array ($.String), $.String], + impl: joinWith (' ') }; //# lines :: String -> Array String @@ -4874,16 +5016,16 @@ //. See also [`unlines`](#unlines). //. //. ```javascript - //. > S.lines('foo\nbar\nbaz\n') + //. > S.lines ('foo\nbar\nbaz\n') //. ['foo', 'bar', 'baz'] //. ``` function lines(s) { - var match = s.replace(/\r\n?/g, '\n').match(/^(?=[\s\S]).*/gm); - return match == null ? [] : match; + return s === '' ? [] + : (s.replace (/\r\n?/g, '\n')).match (/^(?=[\s\S]).*/gm); } _.lines = { consts: {}, - types: [$.String, $.Array($.String)], + types: [$.String, $.Array ($.String)], impl: lines }; @@ -4895,15 +5037,15 @@ //. See also [`lines`](#lines). //. //. ```javascript - //. > S.unlines(['foo', 'bar', 'baz']) + //. > S.unlines (['foo', 'bar', 'baz']) //. 'foo\nbar\nbaz\n' //. ``` function unlines(xs) { - return Z.reduce(function(s, x) { return s + x + '\n'; }, '', xs); + return xs.reduce (function(s, x) { return s + x + '\n'; }, ''); } _.unlines = { consts: {}, - types: [$.Array($.String), $.String], + types: [$.Array ($.String), $.String], impl: unlines }; @@ -4915,15 +5057,17 @@ //. See also [`joinWith`](#joinWith) and [`splitOnRegex`](#splitOnRegex). //. //. ```javascript - //. > S.splitOn('::', 'foo::bar::baz') + //. > S.splitOn ('::') ('foo::bar::baz') //. ['foo', 'bar', 'baz'] //. ``` - function splitOn(separator, s) { - return s.split(separator); + function splitOn(separator) { + return function(s) { + return s.split (separator); + }; } _.splitOn = { consts: {}, - types: [$.String, $.String, $.Array($.String)], + types: [$.String, $.String, $.Array ($.String)], impl: splitOn }; @@ -4941,37 +5085,39 @@ //. See also [`splitOn`](#splitOn). //. //. ```javascript - //. > S.splitOnRegex(/[,;][ ]*/g, 'foo, bar, baz') + //. > S.splitOnRegex (/[,;][ ]*/g) ('foo, bar, baz') //. ['foo', 'bar', 'baz'] //. - //. > S.splitOnRegex(/[,;][ ]*/g, 'foo;bar;baz') + //. > S.splitOnRegex (/[,;][ ]*/g) ('foo;bar;baz') //. ['foo', 'bar', 'baz'] //. ``` - function splitOnRegex(pattern, s) { - return withRegex(pattern, function() { - var result = []; - var lastIndex = 0; - var match; - while ((match = pattern.exec(s)) != null) { - if (pattern.lastIndex === lastIndex && match[0] === '') { - if (pattern.lastIndex === s.length) return result; - pattern.lastIndex += 1; - } else { - result.push(s.slice(lastIndex, match.index)); - lastIndex = match.index + match[0].length; + function splitOnRegex(pattern) { + return function(s) { + return withRegex (pattern, function() { + var result = []; + var lastIndex = 0; + var match; + while ((match = pattern.exec (s)) != null) { + if (pattern.lastIndex === lastIndex && match[0] === '') { + if (pattern.lastIndex === s.length) return result; + pattern.lastIndex += 1; + } else { + result.push (s.slice (lastIndex, match.index)); + lastIndex = match.index + match[0].length; + } } - } - result.push(s.slice(lastIndex)); - return result; - }); + result.push (s.slice (lastIndex)); + return result; + }); + }; } _.splitOnRegex = { consts: {}, - types: [$.GlobalRegExp, $.String, $.Array($.String)], + types: [$.GlobalRegExp, $.String, $.Array ($.String)], impl: splitOnRegex }; - return create({checkTypes: true, env: defaultEnv}); + return create ({checkTypes: true, env: defaultEnv}); })); diff --git a/karma.conf.js b/karma.conf.js index d13a40fa..8cb06cb2 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,11 +1,13 @@ 'use strict'; -var eq = require('./test/internal/eq'); +var S = require ('.'); + +var eq = require ('./test/internal/eq'); // depMain :: String -> String function depMain(name) { - var pkg = require(name + '/package.json'); + var pkg = require (name + '/package.json'); var main = 'main' in pkg ? pkg.main : 'index.js'; return './node_modules/' + name + '/' + main; } @@ -17,8 +19,8 @@ var dependencies = [ 'sanctuary-def' ]; -eq(dependencies.slice().sort(), - Object.keys(require('./package.json').dependencies).sort()); +eq (S.sort (dependencies)) + (S.sort (Object.keys ((require ('./package.json')).dependencies))); // https://saucelabs.com/platforms var customLaunchers = { @@ -75,9 +77,9 @@ var options = { }, plugins: [ - require('karma-browserify'), - require('karma-mocha'), - require('karma-sauce-launcher') + require ('karma-browserify'), + require ('karma-mocha'), + require ('karma-sauce-launcher') ], frameworks: [ @@ -85,7 +87,8 @@ var options = { 'mocha' ], - files: dependencies.map(depMain).concat(['index.js', 'test/**/*.js']), + files: S.concat (S.map (depMain) (dependencies)) + (['index.js', 'test/**/*.js']), preprocessors: { 'test/**/*.js': ['browserify'] @@ -100,9 +103,9 @@ var options = { browserify: { configure: function(bundle) { - bundle.on('prebundle', function() { - dependencies.forEach(function(name) { - bundle.require(depMain(name), {expose: name}); + bundle.on ('prebundle', function() { + dependencies.forEach (function(name) { + bundle.require (depMain (name), {expose: name}); }); }); } @@ -118,8 +121,8 @@ var options = { customLaunchers: customLaunchers, - browsers: Object.keys(customLaunchers) + browsers: S.keys (customLaunchers) }; -module.exports = function(config) { config.set(options); }; +module.exports = function(config) { config.set (options); }; diff --git a/package.json b/package.json index 41c360de..5af4c9b6 100644 --- a/package.json +++ b/package.json @@ -14,12 +14,13 @@ "test": "npm run lint && sanctuary-test && npm run doctest" }, "dependencies": { - "sanctuary-def": "0.14.0", + "sanctuary-def": "0.15.0", "sanctuary-type-classes": "8.1.1", "sanctuary-type-identifiers": "2.0.1" }, "devDependencies": { "browserify": "13.1.x", + "eslint-plugin-markdown": "1.0.0-beta.7", "fantasy-land": "3.5.0", "jsverify": "0.7.x", "karma": "1.3.x", diff --git a/scripts/lint b/scripts/lint new file mode 100755 index 00000000..4f465d25 --- /dev/null +++ b/scripts/lint @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +set -euf -o pipefail + +node_modules/.bin/sanctuary-lint "$@" + +function rewrite { + local state= + local line + while IFS='' read -r line ; do + local a="${line:0:1}" + local b="${line:1:1}" + local z="${line: -1}" + if [[ $a$b == '> ' ]] ; then + printf '\n%s' "${line:2}" + state=input + elif [[ -n $state && $a$b == '. ' ]] ; then + printf '\n%s' "${line:2}" + elif [[ $state == input && $a$z == '{}' ]] ; then + printf ';\n%s' "($line)" + state=output + elif [[ $state == input ]] ; then + printf ';\n%s' "$line" + state=output + elif [[ $state == output ]] ; then + printf ';\n%s' "$line" + state= + else + printf '\n%s' "$line" + fi + done +} + +trap 'mv README.md.orig README.md && rm -f README.md.temp' EXIT +cp README.md README.md.orig +VERSION=0.0.0 PREVIOUS_VERSION=0.0.0 node_modules/.bin/sanctuary-generate-readme +cp README.md README.md.temp +rewrite README.md + +node_modules/.bin/eslint --config eslint/es6.js -- README.md eslint diff --git a/test/Either/Either.js b/test/Either/Either.js index 2f0c6cec..153108c9 100644 --- a/test/Either/Either.js +++ b/test/Either/Either.js @@ -1,208 +1,208 @@ 'use strict'; -var jsc = require('jsverify'); +var jsc = require ('jsverify'); -var S = require('../internal/sanctuary'); +var S = require ('../internal/sanctuary'); -var EitherArb = require('../internal/EitherArb'); -var Identity = require('../internal/Identity'); -var IdentityArb = require('../internal/IdentityArb'); -var add_ = require('../internal/add_'); -var equals = require('../internal/equals'); -var laws = require('../internal/laws'); -var squareRoot = require('../internal/squareRoot'); +var EitherArb = require ('../internal/EitherArb'); +var Identity = require ('../internal/Identity'); +var IdentityArb = require ('../internal/IdentityArb'); +var add_ = require ('../internal/add_'); +var equals = require ('../internal/equals'); +var laws = require ('../internal/laws'); +var squareRoot = require ('../internal/squareRoot'); -suite('Either', function() { +suite ('Either', function() { - suite('Setoid laws', function() { + suite ('Setoid laws', function() { var setoidLaws = laws.Setoid; - setoidLaws.reflexivity( - EitherArb(jsc.string, jsc.falsy) + setoidLaws.reflexivity ( + EitherArb (jsc.string, jsc.falsy) ); - setoidLaws.symmetry( - EitherArb(jsc.bool, jsc.bool), - EitherArb(jsc.bool, jsc.bool) + setoidLaws.symmetry ( + EitherArb (jsc.bool, jsc.bool), + EitherArb (jsc.bool, jsc.bool) ); - setoidLaws.transitivity( - EitherArb(jsc.bool, jsc.bool), - EitherArb(jsc.bool, jsc.bool), - EitherArb(jsc.bool, jsc.bool) + setoidLaws.transitivity ( + EitherArb (jsc.bool, jsc.bool), + EitherArb (jsc.bool, jsc.bool), + EitherArb (jsc.bool, jsc.bool) ); }); - suite('Semigroup laws', function() { + suite ('Semigroup laws', function() { - var semigroupLaws = laws.Semigroup(equals); + var semigroupLaws = laws.Semigroup (equals); - semigroupLaws.associativity( - EitherArb(jsc.string, jsc.string), - EitherArb(jsc.string, jsc.string), - EitherArb(jsc.string, jsc.string) + semigroupLaws.associativity ( + EitherArb (jsc.string, jsc.string), + EitherArb (jsc.string, jsc.string), + EitherArb (jsc.string, jsc.string) ); }); - suite('Functor laws', function() { + suite ('Functor laws', function() { - var functorLaws = laws.Functor(equals); + var functorLaws = laws.Functor (equals); - functorLaws.identity( - EitherArb(jsc.string, jsc.number) + functorLaws.identity ( + EitherArb (jsc.string, jsc.number) ); - functorLaws.composition( - EitherArb(jsc.string, jsc.number), - jsc.constant(Math.sqrt), - jsc.constant(Math.abs) + functorLaws.composition ( + EitherArb (jsc.string, jsc.number), + jsc.constant (Math.sqrt), + jsc.constant (Math.abs) ); }); - suite('Bifunctor laws', function() { + suite ('Bifunctor laws', function() { - var bifunctorLaws = laws.Bifunctor(equals); + var bifunctorLaws = laws.Bifunctor (equals); - bifunctorLaws.identity( - EitherArb(jsc.string, jsc.number) + bifunctorLaws.identity ( + EitherArb (jsc.string, jsc.number) ); - bifunctorLaws.composition( - EitherArb(jsc.string, jsc.number), - jsc.constant(Math.sqrt), - jsc.constant(function(s) { return s.length; }), - jsc.constant(Math.sqrt), - jsc.constant(Math.abs) + bifunctorLaws.composition ( + EitherArb (jsc.string, jsc.number), + jsc.constant (Math.sqrt), + jsc.constant (function(s) { return s.length; }), + jsc.constant (Math.sqrt), + jsc.constant (Math.abs) ); }); - suite('Apply laws', function() { + suite ('Apply laws', function() { - var applyLaws = laws.Apply(equals); + var applyLaws = laws.Apply (equals); - applyLaws.composition( - EitherArb(jsc.string, jsc.constant(Math.sqrt)), - EitherArb(jsc.string, jsc.constant(Math.abs)), - EitherArb(jsc.string, jsc.number) + applyLaws.composition ( + EitherArb (jsc.string, jsc.constant (Math.sqrt)), + EitherArb (jsc.string, jsc.constant (Math.abs)), + EitherArb (jsc.string, jsc.number) ); }); - suite('Applicative laws', function() { + suite ('Applicative laws', function() { - var applicativeLaws = laws.Applicative(equals, S.Either); + var applicativeLaws = laws.Applicative (equals, S.Either); - applicativeLaws.identity( - EitherArb(jsc.string, jsc.number) + applicativeLaws.identity ( + EitherArb (jsc.string, jsc.number) ); - applicativeLaws.homomorphism( - jsc.constant(Math.abs), + applicativeLaws.homomorphism ( + jsc.constant (Math.abs), jsc.number ); - applicativeLaws.interchange( - EitherArb(jsc.string, jsc.constant(Math.abs)), + applicativeLaws.interchange ( + EitherArb (jsc.string, jsc.constant (Math.abs)), jsc.number ); }); - suite('Chain laws', function() { + suite ('Chain laws', function() { - var chainLaws = laws.Chain(equals); + var chainLaws = laws.Chain (equals); - chainLaws.associativity( - EitherArb(jsc.string, jsc.array(jsc.number)), - jsc.constant(function(xs) { return xs.length > 0 ? S.Right(xs[0]) : S.Left('Empty list'); }), - jsc.constant(squareRoot) + chainLaws.associativity ( + EitherArb (jsc.string, jsc.array (jsc.number)), + jsc.constant (function(xs) { return xs.length > 0 ? S.Right (xs[0]) : S.Left ('Empty list'); }), + jsc.constant (squareRoot) ); }); - suite('Monad laws', function() { + suite ('Monad laws', function() { - var monadLaws = laws.Monad(equals, S.Either); + var monadLaws = laws.Monad (equals, S.Either); - monadLaws.leftIdentity( - jsc.constant(squareRoot), + monadLaws.leftIdentity ( + jsc.constant (squareRoot), jsc.number ); - monadLaws.rightIdentity( - EitherArb(jsc.string, jsc.number) + monadLaws.rightIdentity ( + EitherArb (jsc.string, jsc.number) ); }); - suite('Alt laws', function() { + suite ('Alt laws', function() { - var altLaws = laws.Alt(equals); + var altLaws = laws.Alt (equals); - altLaws.associativity( - EitherArb(jsc.string, jsc.number), - EitherArb(jsc.string, jsc.number), - EitherArb(jsc.string, jsc.number) + altLaws.associativity ( + EitherArb (jsc.string, jsc.number), + EitherArb (jsc.string, jsc.number), + EitherArb (jsc.string, jsc.number) ); - altLaws.distributivity( - EitherArb(jsc.string, jsc.number), - EitherArb(jsc.string, jsc.number), - jsc.constant(Math.sqrt) + altLaws.distributivity ( + EitherArb (jsc.string, jsc.number), + EitherArb (jsc.string, jsc.number), + jsc.constant (Math.sqrt) ); }); - suite('Foldable laws', function() { + suite ('Foldable laws', function() { - var foldableLaws = laws.Foldable(equals); + var foldableLaws = laws.Foldable (equals); - foldableLaws.associativity( - jsc.constant(add_), + foldableLaws.associativity ( + jsc.constant (add_), jsc.number, - EitherArb(jsc.string, jsc.number) + EitherArb (jsc.string, jsc.number) ); }); - suite('Traversable laws', function() { + suite ('Traversable laws', function() { - var traversableLaws = laws.Traversable(equals); + var traversableLaws = laws.Traversable (equals); - traversableLaws.naturality( - jsc.constant(S.compose(S.Just, S.prop('value'))), - EitherArb(jsc.string, IdentityArb(jsc.number)), - jsc.constant(Identity), - jsc.constant(S.Maybe) + traversableLaws.naturality ( + jsc.constant (S.compose (S.Just) (S.prop ('value'))), + EitherArb (jsc.string, IdentityArb (jsc.number)), + jsc.constant (Identity), + jsc.constant (S.Maybe) ); - traversableLaws.identity( - EitherArb(jsc.string, jsc.number), - jsc.constant(Identity) + traversableLaws.identity ( + EitherArb (jsc.string, jsc.number), + jsc.constant (Identity) ); - traversableLaws.composition( - EitherArb(jsc.string, IdentityArb(EitherArb(jsc.string, jsc.number))), - jsc.constant(Identity), - jsc.constant(S.Either) + traversableLaws.composition ( + EitherArb (jsc.string, IdentityArb (EitherArb (jsc.string, jsc.number))), + jsc.constant (Identity), + jsc.constant (S.Either) ); }); - suite('Extend laws', function() { + suite ('Extend laws', function() { - var extendLaws = laws.Extend(equals); + var extendLaws = laws.Extend (equals); - extendLaws.associativity( - EitherArb(jsc.string, jsc.integer), - jsc.constant(function(either) { return either.value + 1; }), - jsc.constant(function(either) { return either.value * either.value; }) + extendLaws.associativity ( + EitherArb (jsc.string, jsc.integer), + jsc.constant (function(either) { return either.value + 1; }), + jsc.constant (function(either) { return either.value * either.value; }) ); }); diff --git a/test/Either/EitherType.js b/test/Either/EitherType.js index f06aef28..8c9458cb 100644 --- a/test/Either/EitherType.js +++ b/test/Either/EitherType.js @@ -1,18 +1,18 @@ 'use strict'; -var $ = require('sanctuary-def'); +var $ = require ('sanctuary-def'); -var S = require('../..'); +var S = require ('../..'); -var eq = require('../internal/eq'); +var eq = require ('../internal/eq'); -test('EitherType', function() { +test ('EitherType', function() { - eq($.test($.env, S.EitherType($.String, $.Number), S.Left('Error')), true); - eq($.test($.env, S.EitherType($.String, $.Number), S.Right(42)), true); - eq($.test($.env, S.EitherType($.String, $.Number), S.Right('42')), false); - eq($.test($.env, S.EitherType($.String, $.Number), S.Just(42)), false); - eq($.test($.env, S.EitherType($.String, $.Number), null), false); + eq ($.test ($.env) (S.EitherType ($.String) ($.Number)) (S.Left ('Error'))) (true); + eq ($.test ($.env) (S.EitherType ($.String) ($.Number)) (S.Right (42))) (true); + eq ($.test ($.env) (S.EitherType ($.String) ($.Number)) (S.Right ('42'))) (false); + eq ($.test ($.env) (S.EitherType ($.String) ($.Number)) (S.Just (42))) (false); + eq ($.test ($.env) (S.EitherType ($.String) ($.Number)) (null)) (false); }); diff --git a/test/Either/Left.js b/test/Either/Left.js index fdb781db..e5066a25 100644 --- a/test/Either/Left.js +++ b/test/Either/Left.js @@ -1,106 +1,106 @@ 'use strict'; -var FL = require('fantasy-land'); -var Z = require('sanctuary-type-classes'); +var FL = require ('fantasy-land'); +var Z = require ('sanctuary-type-classes'); -var S = require('../internal/sanctuary'); +var S = require ('../internal/sanctuary'); -var Useless = require('../internal/Useless'); -var eq = require('../internal/eq'); -var squareRoot = require('../internal/squareRoot'); +var Useless = require ('../internal/Useless'); +var eq = require ('../internal/eq'); +var squareRoot = require ('../internal/squareRoot'); -suite('Left', function() { +suite ('Left', function() { - test('data constructor', function() { - eq(typeof S.Left, 'function'); - eq(S.Left.length, 1); - eq(S.Left(42).constructor, S.Either); - eq(S.Left(42).isLeft, true); - eq(S.Left(42).isRight, false); + test ('data constructor', function() { + eq (typeof S.Left) ('function'); + eq (S.Left.length) (1); + eq ((S.Left (42)).constructor) (S.Either); + eq ((S.Left (42)).isLeft) (true); + eq ((S.Left (42)).isRight) (false); }); - test('"fantasy-land/alt" method', function() { - eq(S.Left(1)[FL.alt].length, 1); - eq(S.Left(1)[FL.alt](S.Left(2)), S.Left(2)); - eq(S.Left(1)[FL.alt](S.Right(2)), S.Right(2)); + test ('"fantasy-land/alt" method', function() { + eq ((S.Left (1))[FL.alt].length) (1); + eq ((S.Left (1))[FL.alt] (S.Left (2))) (S.Left (2)); + eq ((S.Left (1))[FL.alt] (S.Right (2))) (S.Right (2)); }); - test('"fantasy-land/ap" method', function() { - eq(S.Left('abc')[FL.ap].length, 1); - eq(S.Left('abc')[FL.ap](S.Left('xyz')), S.Left('xyz')); - eq(S.Left('abc')[FL.ap](S.Right(S.add(1))), S.Left('abc')); + test ('"fantasy-land/ap" method', function() { + eq ((S.Left ('abc'))[FL.ap].length) (1); + eq ((S.Left ('abc'))[FL.ap] (S.Left ('xyz'))) (S.Left ('xyz')); + eq ((S.Left ('abc'))[FL.ap] (S.Right (S.add (1)))) (S.Left ('abc')); }); - test('"fantasy-land/bimap" method', function() { - eq(S.Left('abc')[FL.bimap].length, 2); - eq(S.Left('abc')[FL.bimap](S.toUpper, S.add(1)), S.Left('ABC')); + test ('"fantasy-land/bimap" method', function() { + eq ((S.Left ('abc'))[FL.bimap].length) (2); + eq ((S.Left ('abc'))[FL.bimap] (S.toUpper, S.add (1))) (S.Left ('ABC')); }); - test('"fantasy-land/chain" method', function() { - eq(S.Left('abc')[FL.chain].length, 1); - eq(S.Left('abc')[FL.chain](squareRoot), S.Left('abc')); + test ('"fantasy-land/chain" method', function() { + eq ((S.Left ('abc'))[FL.chain].length) (1); + eq ((S.Left ('abc'))[FL.chain] (squareRoot)) (S.Left ('abc')); }); - test('"fantasy-land/concat" method', function() { - eq(S.Left('abc')[FL.concat].length, 1); - eq(S.Left('abc')[FL.concat](S.Left('def')), S.Left('abcdef')); - eq(S.Left('abc')[FL.concat](S.Right('xyz')), S.Right('xyz')); + test ('"fantasy-land/concat" method', function() { + eq ((S.Left ('abc'))[FL.concat].length) (1); + eq ((S.Left ('abc'))[FL.concat] (S.Left ('def'))) (S.Left ('abcdef')); + eq ((S.Left ('abc'))[FL.concat] (S.Right ('xyz'))) (S.Right ('xyz')); - eq(Z.Semigroup.test(S.Left('abc')), true); - eq(Z.Semigroup.test(S.Left(123)), false); + eq (Z.Semigroup.test (S.Left ('abc'))) (true); + eq (Z.Semigroup.test (S.Left (123))) (false); }); - test('"fantasy-land/equals" method', function() { - eq(S.Left(42)[FL.equals].length, 1); - eq(S.Left(42)[FL.equals](S.Left(42)), true); - eq(S.Left(42)[FL.equals](S.Left('42')), false); - eq(S.Left(42)[FL.equals](S.Right(42)), false); + test ('"fantasy-land/equals" method', function() { + eq ((S.Left (42))[FL.equals].length) (1); + eq ((S.Left (42))[FL.equals] (S.Left (42))) (true); + eq ((S.Left (42))[FL.equals] (S.Left ('42'))) (false); + eq ((S.Left (42))[FL.equals] (S.Right (42))) (false); // Value-based equality: - eq(S.Left(NaN)[FL.equals](S.Left(NaN)), true); - eq(S.Left([1, 2, 3])[FL.equals](S.Left([1, 2, 3])), true); + eq ((S.Left (NaN))[FL.equals] (S.Left (NaN))) (true); + eq ((S.Left ([1, 2, 3]))[FL.equals] (S.Left ([1, 2, 3]))) (true); - eq(Z.Setoid.test(S.Left(1)), true); - eq(Z.Setoid.test(S.Left(Useless)), false); + eq (Z.Setoid.test (S.Left (1))) (true); + eq (Z.Setoid.test (S.Left (Useless))) (false); }); - test('"fantasy-land/extend" method', function() { - eq(S.Left('abc')[FL.extend].length, 1); - eq(S.Left('abc')[FL.extend](function(x) { return x / 2; }), S.Left('abc')); + test ('"fantasy-land/extend" method', function() { + eq ((S.Left ('abc'))[FL.extend].length) (1); + eq ((S.Left ('abc'))[FL.extend] (function(x) { return x / 2; })) (S.Left ('abc')); }); - test('"fantasy-land/lte" method', function() { - eq(S.Left(1)[FL.lte].length, 1); - eq(S.Left(1)[FL.lte](S.Right(0)), true); - eq(S.Left(1)[FL.lte](S.Right(1)), true); - eq(S.Left(1)[FL.lte](S.Right(2)), true); - eq(S.Left(1)[FL.lte](S.Left(0)), false); - eq(S.Left(1)[FL.lte](S.Left(1)), true); - eq(S.Left(1)[FL.lte](S.Left(2)), true); - - eq(Z.Ord.test(S.Left(1)), true); - eq(Z.Ord.test(S.Left(Math.sqrt)), false); + test ('"fantasy-land/lte" method', function() { + eq ((S.Left (1))[FL.lte].length) (1); + eq ((S.Left (1))[FL.lte] (S.Right (0))) (true); + eq ((S.Left (1))[FL.lte] (S.Right (1))) (true); + eq ((S.Left (1))[FL.lte] (S.Right (2))) (true); + eq ((S.Left (1))[FL.lte] (S.Left (0))) (false); + eq ((S.Left (1))[FL.lte] (S.Left (1))) (true); + eq ((S.Left (1))[FL.lte] (S.Left (2))) (true); + + eq (Z.Ord.test (S.Left (1))) (true); + eq (Z.Ord.test (S.Left (Math.sqrt))) (false); }); - test('"fantasy-land/map" method', function() { - eq(S.Left('abc')[FL.map].length, 1); - eq(S.Left('abc')[FL.map](Math.sqrt), S.Left('abc')); + test ('"fantasy-land/map" method', function() { + eq ((S.Left ('abc'))[FL.map].length) (1); + eq ((S.Left ('abc'))[FL.map] (Math.sqrt)) (S.Left ('abc')); }); - test('"fantasy-land/reduce" method', function() { - eq(S.Left('abc')[FL.reduce].length, 2); - eq(S.Left('abc')[FL.reduce](function(x, y) { return x - y; }, 42), 42); + test ('"fantasy-land/reduce" method', function() { + eq ((S.Left ('abc'))[FL.reduce].length) (2); + eq ((S.Left ('abc'))[FL.reduce] (function(x, y) { return x - y; }, 42)) (42); }); - test('"toString" method', function() { - eq(S.Left('abc').toString.length, 0); - eq(S.Left('abc').toString(), 'Left("abc")'); + test ('"toString" method', function() { + eq ((S.Left ('abc')).toString.length) (0); + eq ((S.Left ('abc')).toString ()) ('Left("abc")'); }); - test('"inspect" method', function() { - eq(S.Left('abc').inspect.length, 0); - eq(S.Left('abc').inspect(), 'Left("abc")'); + test ('"inspect" method', function() { + eq ((S.Left ('abc')).inspect.length) (0); + eq ((S.Left ('abc')).inspect ()) ('Left("abc")'); }); }); diff --git a/test/Either/Right.js b/test/Either/Right.js index 94a30278..564c9244 100644 --- a/test/Either/Right.js +++ b/test/Either/Right.js @@ -1,106 +1,106 @@ 'use strict'; -var FL = require('fantasy-land'); -var Z = require('sanctuary-type-classes'); +var FL = require ('fantasy-land'); +var Z = require ('sanctuary-type-classes'); -var S = require('../internal/sanctuary'); +var S = require ('../internal/sanctuary'); -var Useless = require('../internal/Useless'); -var eq = require('../internal/eq'); -var squareRoot = require('../internal/squareRoot'); +var Useless = require ('../internal/Useless'); +var eq = require ('../internal/eq'); +var squareRoot = require ('../internal/squareRoot'); -suite('Right', function() { +suite ('Right', function() { - test('data constructor', function() { - eq(typeof S.Right, 'function'); - eq(S.Right.length, 1); - eq(S.Right(42).constructor, S.Either); - eq(S.Right(42).isLeft, false); - eq(S.Right(42).isRight, true); + test ('data constructor', function() { + eq (typeof S.Right) ('function'); + eq (S.Right.length) (1); + eq ((S.Right (42)).constructor) (S.Either); + eq ((S.Right (42)).isLeft) (false); + eq ((S.Right (42)).isRight) (true); }); - test('"fantasy-land/alt" method', function() { - eq(S.Right(1)[FL.alt].length, 1); - eq(S.Right(1)[FL.alt](S.Left(2)), S.Right(1)); - eq(S.Right(1)[FL.alt](S.Right(2)), S.Right(1)); + test ('"fantasy-land/alt" method', function() { + eq ((S.Right (1))[FL.alt].length) (1); + eq ((S.Right (1))[FL.alt] (S.Left (2))) (S.Right (1)); + eq ((S.Right (1))[FL.alt] (S.Right (2))) (S.Right (1)); }); - test('"fantasy-land/ap" method', function() { - eq(S.Right(42)[FL.ap].length, 1); - eq(S.Right(42)[FL.ap](S.Left('abc')), S.Left('abc')); - eq(S.Right(42)[FL.ap](S.Right(S.add(1))), S.Right(43)); + test ('"fantasy-land/ap" method', function() { + eq ((S.Right (42))[FL.ap].length) (1); + eq ((S.Right (42))[FL.ap] (S.Left ('abc'))) (S.Left ('abc')); + eq ((S.Right (42))[FL.ap] (S.Right (S.add (1)))) (S.Right (43)); }); - test('"fantasy-land/bimap" method', function() { - eq(S.Right(42)[FL.bimap].length, 2); - eq(S.Right(42)[FL.bimap](S.toUpper, S.add(1)), S.Right(43)); + test ('"fantasy-land/bimap" method', function() { + eq ((S.Right (42))[FL.bimap].length) (2); + eq ((S.Right (42))[FL.bimap] (S.toUpper, S.add (1))) (S.Right (43)); }); - test('"fantasy-land/chain" method', function() { - eq(S.Right(25)[FL.chain].length, 1); - eq(S.Right(25)[FL.chain](squareRoot), S.Right(5)); + test ('"fantasy-land/chain" method', function() { + eq ((S.Right (25))[FL.chain].length) (1); + eq ((S.Right (25))[FL.chain] (squareRoot)) (S.Right (5)); }); - test('"fantasy-land/concat" method', function() { - eq(S.Right('abc')[FL.concat].length, 1); - eq(S.Right('abc')[FL.concat](S.Left('xyz')), S.Right('abc')); - eq(S.Right('abc')[FL.concat](S.Right('def')), S.Right('abcdef')); + test ('"fantasy-land/concat" method', function() { + eq ((S.Right ('abc'))[FL.concat].length) (1); + eq ((S.Right ('abc'))[FL.concat] (S.Left ('xyz'))) (S.Right ('abc')); + eq ((S.Right ('abc'))[FL.concat] (S.Right ('def'))) (S.Right ('abcdef')); - eq(Z.Semigroup.test(S.Right('abc')), true); - eq(Z.Semigroup.test(S.Right(123)), false); + eq (Z.Semigroup.test (S.Right ('abc'))) (true); + eq (Z.Semigroup.test (S.Right (123))) (false); }); - test('"fantasy-land/equals" method', function() { - eq(S.Right(42)[FL.equals].length, 1); - eq(S.Right(42)[FL.equals](S.Right(42)), true); - eq(S.Right(42)[FL.equals](S.Right('42')), false); - eq(S.Right(42)[FL.equals](S.Left(42)), false); + test ('"fantasy-land/equals" method', function() { + eq ((S.Right (42))[FL.equals].length) (1); + eq ((S.Right (42))[FL.equals] (S.Right (42))) (true); + eq ((S.Right (42))[FL.equals] (S.Right ('42'))) (false); + eq ((S.Right (42))[FL.equals] (S.Left (42))) (false); // Value-based equality: - eq(S.Right(NaN)[FL.equals](S.Right(NaN)), true); - eq(S.Right([1, 2, 3])[FL.equals](S.Right([1, 2, 3])), true); + eq ((S.Right (NaN))[FL.equals] (S.Right (NaN))) (true); + eq ((S.Right ([1, 2, 3]))[FL.equals] (S.Right ([1, 2, 3]))) (true); - eq(Z.Setoid.test(S.Right(1)), true); - eq(Z.Setoid.test(S.Right(Useless)), false); + eq (Z.Setoid.test (S.Right (1))) (true); + eq (Z.Setoid.test (S.Right (Useless))) (false); }); - test('"fantasy-land/extend" method', function() { - eq(S.Right(42)[FL.extend].length, 1); - eq(S.Right(42)[FL.extend](function(x) { return x.value / 2; }), S.Right(21)); + test ('"fantasy-land/extend" method', function() { + eq ((S.Right (42))[FL.extend].length) (1); + eq ((S.Right (42))[FL.extend] (function(x) { return x.value / 2; })) (S.Right (21)); }); - test('"fantasy-land/lte" method', function() { - eq(S.Right(1)[FL.lte].length, 1); - eq(S.Right(1)[FL.lte](S.Left(0)), false); - eq(S.Right(1)[FL.lte](S.Left(1)), false); - eq(S.Right(1)[FL.lte](S.Left(2)), false); - eq(S.Right(1)[FL.lte](S.Right(0)), false); - eq(S.Right(1)[FL.lte](S.Right(1)), true); - eq(S.Right(1)[FL.lte](S.Right(2)), true); - - eq(Z.Ord.test(S.Right(1)), true); - eq(Z.Ord.test(S.Right(Math.sqrt)), false); + test ('"fantasy-land/lte" method', function() { + eq ((S.Right (1))[FL.lte].length) (1); + eq ((S.Right (1))[FL.lte] (S.Left (0))) (false); + eq ((S.Right (1))[FL.lte] (S.Left (1))) (false); + eq ((S.Right (1))[FL.lte] (S.Left (2))) (false); + eq ((S.Right (1))[FL.lte] (S.Right (0))) (false); + eq ((S.Right (1))[FL.lte] (S.Right (1))) (true); + eq ((S.Right (1))[FL.lte] (S.Right (2))) (true); + + eq (Z.Ord.test (S.Right (1))) (true); + eq (Z.Ord.test (S.Right (Math.sqrt))) (false); }); - test('"fantasy-land/map" method', function() { - eq(S.Right(9)[FL.map].length, 1); - eq(S.Right(9)[FL.map](Math.sqrt), S.Right(3)); + test ('"fantasy-land/map" method', function() { + eq ((S.Right (9))[FL.map].length) (1); + eq ((S.Right (9))[FL.map] (Math.sqrt)) (S.Right (3)); }); - test('"fantasy-land/reduce" method', function() { - eq(S.Right(5)[FL.reduce].length, 2); - eq(S.Right(5)[FL.reduce](function(x, y) { return x - y; }, 42), 37); + test ('"fantasy-land/reduce" method', function() { + eq ((S.Right (5))[FL.reduce].length) (2); + eq ((S.Right (5))[FL.reduce] (function(x, y) { return x - y; }, 42)) (37); }); - test('"toString" method', function() { - eq(S.Right([1, 2, 3]).toString.length, 0); - eq(S.Right([1, 2, 3]).toString(), 'Right([1, 2, 3])'); + test ('"toString" method', function() { + eq ((S.Right ([1, 2, 3])).toString.length) (0); + eq ((S.Right ([1, 2, 3])).toString ()) ('Right([1, 2, 3])'); }); - test('"inspect" method', function() { - eq(S.Right([1, 2, 3]).inspect.length, 0); - eq(S.Right([1, 2, 3]).inspect(), 'Right([1, 2, 3])'); + test ('"inspect" method', function() { + eq ((S.Right ([1, 2, 3])).inspect.length) (0); + eq ((S.Right ([1, 2, 3])).inspect ()) ('Right([1, 2, 3])'); }); }); diff --git a/test/I.js b/test/I.js index 982981d9..5d05fc91 100644 --- a/test/I.js +++ b/test/I.js @@ -1,21 +1,21 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var properties = require('./properties'); +var eq = require ('./internal/eq'); +var properties = require ('./properties'); -test('I', function() { +test ('I', function() { - eq(typeof S.I, 'function'); - eq(S.I.length, 1); - eq(S.I.toString(), 'I :: a -> a'); + eq (typeof S.I) ('function'); + eq (S.I.length) (1); + eq (String (S.I)) ('I :: a -> a'); - eq(S.I([1, 2, 3]), [1, 2, 3]); - eq(S.I(['foo', 42]), ['foo', 42]); + eq (S.I ([1, 2, 3])) ([1, 2, 3]); + eq (S.I (['foo', 42])) (['foo', 42]); - eq(properties.idempotent(S.I), true); - eq(properties.involution(S.I), true); + eq (properties.idempotent (S.I)) (true); + eq (properties.involution (S.I)) (true); }); diff --git a/test/K.js b/test/K.js index eeb6a669..7133e3ee 100644 --- a/test/K.js +++ b/test/K.js @@ -1,18 +1,18 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('K', function() { +test ('K', function() { - eq(typeof S.K, 'function'); - eq(S.K.length, 2); - eq(S.K.toString(), 'K :: a -> b -> a'); + eq (typeof S.K) ('function'); + eq (S.K.length) (1); + eq (String (S.K)) ('K :: a -> b -> a'); - eq(S.K(21, []), 21); - eq(S.K(42, null), 42); - eq(S.K(84, undefined), 84); + eq (S.K (21) ([])) (21); + eq (S.K (42) (null)) (42); + eq (S.K (84) (undefined)) (84); }); diff --git a/test/Maybe/Just.js b/test/Maybe/Just.js index dcfe6d24..6d8d76a1 100644 --- a/test/Maybe/Just.js +++ b/test/Maybe/Just.js @@ -1,98 +1,98 @@ 'use strict'; -var FL = require('fantasy-land'); -var Z = require('sanctuary-type-classes'); +var FL = require ('fantasy-land'); +var Z = require ('sanctuary-type-classes'); -var S = require('../internal/sanctuary'); +var S = require ('../internal/sanctuary'); -var Useless = require('../internal/Useless'); -var eq = require('../internal/eq'); +var Useless = require ('../internal/Useless'); +var eq = require ('../internal/eq'); -suite('Just', function() { +suite ('Just', function() { - test('data constructor', function() { - eq(typeof S.Just, 'function'); - eq(S.Just.length, 1); - eq(S.Just(42).constructor, S.Maybe); - eq(S.Just(42).isNothing, false); - eq(S.Just(42).isJust, true); + test ('data constructor', function() { + eq (typeof S.Just) ('function'); + eq (S.Just.length) (1); + eq ((S.Just (42)).constructor) (S.Maybe); + eq ((S.Just (42)).isNothing) (false); + eq ((S.Just (42)).isJust) (true); }); - test('"fantasy-land/alt" method', function() { - eq(S.Just(1)[FL.alt].length, 1); - eq(S.Just(1)[FL.alt](S.Nothing), S.Just(1)); - eq(S.Just(1)[FL.alt](S.Just(2)), S.Just(1)); + test ('"fantasy-land/alt" method', function() { + eq ((S.Just (1))[FL.alt].length) (1); + eq ((S.Just (1))[FL.alt] (S.Nothing)) (S.Just (1)); + eq ((S.Just (1))[FL.alt] (S.Just (2))) (S.Just (1)); }); - test('"fantasy-land/ap" method', function() { - eq(S.Just(42)[FL.ap].length, 1); - eq(S.Just(42)[FL.ap](S.Nothing), S.Nothing); - eq(S.Just(42)[FL.ap](S.Just(S.add(1))), S.Just(43)); + test ('"fantasy-land/ap" method', function() { + eq ((S.Just (42))[FL.ap].length) (1); + eq ((S.Just (42))[FL.ap] (S.Nothing)) (S.Nothing); + eq ((S.Just (42))[FL.ap] (S.Just (S.add (1)))) (S.Just (43)); }); - test('"fantasy-land/chain" method', function() { - eq(S.Just([1, 2, 3])[FL.chain].length, 1); - eq(S.Just([1, 2, 3])[FL.chain](S.head), S.Just(1)); + test ('"fantasy-land/chain" method', function() { + eq ((S.Just ([1, 2, 3]))[FL.chain].length) (1); + eq ((S.Just ([1, 2, 3]))[FL.chain] (S.head)) (S.Just (1)); }); - test('"fantasy-land/concat" method', function() { - eq(S.Just('foo')[FL.concat].length, 1); - eq(S.Just('foo')[FL.concat](S.Nothing), S.Just('foo')); - eq(S.Just('foo')[FL.concat](S.Just('bar')), S.Just('foobar')); + test ('"fantasy-land/concat" method', function() { + eq ((S.Just ('foo'))[FL.concat].length) (1); + eq ((S.Just ('foo'))[FL.concat] (S.Nothing)) (S.Just ('foo')); + eq ((S.Just ('foo'))[FL.concat] (S.Just ('bar'))) (S.Just ('foobar')); - eq(Z.Semigroup.test(S.Just('abc')), true); - eq(Z.Semigroup.test(S.Just(123)), false); + eq (Z.Semigroup.test (S.Just ('abc'))) (true); + eq (Z.Semigroup.test (S.Just (123))) (false); }); - test('"fantasy-land/equals" method', function() { - eq(S.Just(42)[FL.equals].length, 1); - eq(S.Just(42)[FL.equals](S.Just(42)), true); - eq(S.Just(42)[FL.equals](S.Just(43)), false); - eq(S.Just(42)[FL.equals](S.Nothing), false); + test ('"fantasy-land/equals" method', function() { + eq ((S.Just (42))[FL.equals].length) (1); + eq ((S.Just (42))[FL.equals] (S.Just (42))) (true); + eq ((S.Just (42))[FL.equals] (S.Just (43))) (false); + eq ((S.Just (42))[FL.equals] (S.Nothing)) (false); // Value-based equality: - eq(S.Just(NaN)[FL.equals](S.Just(NaN)), true); - eq(S.Just([1, 2, 3])[FL.equals](S.Just([1, 2, 3])), true); + eq ((S.Just (NaN))[FL.equals] (S.Just (NaN))) (true); + eq ((S.Just ([1, 2, 3]))[FL.equals] (S.Just ([1, 2, 3]))) (true); - eq(Z.Setoid.test(S.Just(1)), true); - eq(Z.Setoid.test(S.Just(Useless)), false); + eq (Z.Setoid.test (S.Just (1))) (true); + eq (Z.Setoid.test (S.Just (Useless))) (false); }); - test('"fantasy-land/extend" method', function() { - eq(S.Just(42)[FL.extend].length, 1); - eq(S.Just(42)[FL.extend](function(x) { return x.value / 2; }), S.Just(21)); + test ('"fantasy-land/extend" method', function() { + eq ((S.Just (42))[FL.extend].length) (1); + eq ((S.Just (42))[FL.extend] (function(x) { return x.value / 2; })) (S.Just (21)); }); - test('"fantasy-land/lte" method', function() { - eq(S.Just(1)[FL.lte].length, 1); - eq(S.Just(1)[FL.lte](S.Nothing), false); - eq(S.Just(1)[FL.lte](S.Just(0)), false); - eq(S.Just(1)[FL.lte](S.Just(1)), true); - eq(S.Just(1)[FL.lte](S.Just(2)), true); + test ('"fantasy-land/lte" method', function() { + eq ((S.Just (1))[FL.lte].length) (1); + eq ((S.Just (1))[FL.lte] (S.Nothing)) (false); + eq ((S.Just (1))[FL.lte] (S.Just (0))) (false); + eq ((S.Just (1))[FL.lte] (S.Just (1))) (true); + eq ((S.Just (1))[FL.lte] (S.Just (2))) (true); - eq(Z.Ord.test(S.Just(1)), true); - eq(Z.Ord.test(S.Just(Math.sqrt)), false); + eq (Z.Ord.test (S.Just (1))) (true); + eq (Z.Ord.test (S.Just (Math.sqrt))) (false); }); - test('"fantasy-land/map" method', function() { - eq(S.Just(42)[FL.map].length, 1); - eq(S.Just(42)[FL.map](function(x) { return x / 2; }), S.Just(21)); + test ('"fantasy-land/map" method', function() { + eq ((S.Just (42))[FL.map].length) (1); + eq ((S.Just (42))[FL.map] (function(x) { return x / 2; })) (S.Just (21)); }); - test('"fantasy-land/reduce" method', function() { - eq(S.Just(5)[FL.reduce].length, 2); - eq(S.Just(5)[FL.reduce](function(x, y) { return x - y; }, 42), 37); + test ('"fantasy-land/reduce" method', function() { + eq ((S.Just (5))[FL.reduce].length) (2); + eq ((S.Just (5))[FL.reduce] (function(x, y) { return x - y; }, 42)) (37); }); - test('"toString" method', function() { - eq(S.Just([1, 2, 3]).toString.length, 0); - eq(S.Just([1, 2, 3]).toString(), 'Just([1, 2, 3])'); + test ('"toString" method', function() { + eq ((S.Just ([1, 2, 3])).toString.length) (0); + eq ((S.Just ([1, 2, 3])).toString ()) ('Just([1, 2, 3])'); }); - test('"inspect" method', function() { - eq(S.Just([1, 2, 3]).inspect.length, 0); - eq(S.Just([1, 2, 3]).inspect(), 'Just([1, 2, 3])'); + test ('"inspect" method', function() { + eq ((S.Just ([1, 2, 3])).inspect.length) (0); + eq ((S.Just ([1, 2, 3])).inspect ()) ('Just([1, 2, 3])'); }); }); diff --git a/test/Maybe/Maybe.js b/test/Maybe/Maybe.js index 0b18d01e..2f22f36f 100644 --- a/test/Maybe/Maybe.js +++ b/test/Maybe/Maybe.js @@ -1,238 +1,238 @@ 'use strict'; -var jsc = require('jsverify'); +var jsc = require ('jsverify'); -var S = require('../internal/sanctuary'); +var S = require ('../internal/sanctuary'); -var EitherArb = require('../internal/EitherArb'); -var Identity = require('../internal/Identity'); -var IdentityArb = require('../internal/IdentityArb'); -var MaybeArb = require('../internal/MaybeArb'); -var add_ = require('../internal/add_'); -var equals = require('../internal/equals'); -var laws = require('../internal/laws'); +var EitherArb = require ('../internal/EitherArb'); +var Identity = require ('../internal/Identity'); +var IdentityArb = require ('../internal/IdentityArb'); +var MaybeArb = require ('../internal/MaybeArb'); +var add_ = require ('../internal/add_'); +var equals = require ('../internal/equals'); +var laws = require ('../internal/laws'); -suite('Maybe', function() { +suite ('Maybe', function() { - suite('Setoid laws', function() { + suite ('Setoid laws', function() { var setoidLaws = laws.Setoid; - setoidLaws.reflexivity( - MaybeArb(jsc.falsy) + setoidLaws.reflexivity ( + MaybeArb (jsc.falsy) ); - setoidLaws.symmetry( - MaybeArb(jsc.bool), - MaybeArb(jsc.bool) + setoidLaws.symmetry ( + MaybeArb (jsc.bool), + MaybeArb (jsc.bool) ); - setoidLaws.transitivity( - MaybeArb(jsc.bool), - MaybeArb(jsc.bool), - MaybeArb(jsc.bool) + setoidLaws.transitivity ( + MaybeArb (jsc.bool), + MaybeArb (jsc.bool), + MaybeArb (jsc.bool) ); }); - suite('Semigroup laws', function() { + suite ('Semigroup laws', function() { - var semigroupLaws = laws.Semigroup(equals); + var semigroupLaws = laws.Semigroup (equals); - semigroupLaws.associativity( - MaybeArb(jsc.string), - MaybeArb(jsc.string), - MaybeArb(jsc.string) + semigroupLaws.associativity ( + MaybeArb (jsc.string), + MaybeArb (jsc.string), + MaybeArb (jsc.string) ); }); - suite('Monoid laws', function() { + suite ('Monoid laws', function() { - var monoidLaws = laws.Monoid(equals, S.Maybe); + var monoidLaws = laws.Monoid (equals, S.Maybe); - monoidLaws.leftIdentity( - MaybeArb(jsc.string) + monoidLaws.leftIdentity ( + MaybeArb (jsc.string) ); - monoidLaws.rightIdentity( - MaybeArb(jsc.string) + monoidLaws.rightIdentity ( + MaybeArb (jsc.string) ); }); - suite('Functor laws', function() { + suite ('Functor laws', function() { - var functorLaws = laws.Functor(equals); + var functorLaws = laws.Functor (equals); - functorLaws.identity( - MaybeArb(jsc.number) + functorLaws.identity ( + MaybeArb (jsc.number) ); - functorLaws.composition( - MaybeArb(jsc.number), - jsc.constant(Math.sqrt), - jsc.constant(Math.abs) + functorLaws.composition ( + MaybeArb (jsc.number), + jsc.constant (Math.sqrt), + jsc.constant (Math.abs) ); }); - suite('Apply laws', function() { + suite ('Apply laws', function() { - var applyLaws = laws.Apply(equals); + var applyLaws = laws.Apply (equals); - applyLaws.composition( - MaybeArb(jsc.constant(Math.sqrt)), - MaybeArb(jsc.constant(Math.abs)), - MaybeArb(jsc.number) + applyLaws.composition ( + MaybeArb (jsc.constant (Math.sqrt)), + MaybeArb (jsc.constant (Math.abs)), + MaybeArb (jsc.number) ); }); - suite('Applicative laws', function() { + suite ('Applicative laws', function() { - var applicativeLaws = laws.Applicative(equals, S.Maybe); + var applicativeLaws = laws.Applicative (equals, S.Maybe); - applicativeLaws.identity( - MaybeArb(jsc.number) + applicativeLaws.identity ( + MaybeArb (jsc.number) ); - applicativeLaws.homomorphism( - jsc.constant(Math.abs), + applicativeLaws.homomorphism ( + jsc.constant (Math.abs), jsc.number ); - applicativeLaws.interchange( - MaybeArb(jsc.constant(Math.abs)), + applicativeLaws.interchange ( + MaybeArb (jsc.constant (Math.abs)), jsc.number ); }); - suite('Chain laws', function() { + suite ('Chain laws', function() { - var chainLaws = laws.Chain(equals); + var chainLaws = laws.Chain (equals); - chainLaws.associativity( - MaybeArb(jsc.array(jsc.asciistring)), - jsc.constant(S.head), - jsc.constant(S.parseInt(36)) + chainLaws.associativity ( + MaybeArb (jsc.array (jsc.asciistring)), + jsc.constant (S.head), + jsc.constant (S.parseInt (36)) ); }); - suite('Monad laws', function() { + suite ('Monad laws', function() { - var monadLaws = laws.Monad(equals, S.Maybe); + var monadLaws = laws.Monad (equals, S.Maybe); - monadLaws.leftIdentity( - jsc.constant(S.head), - jsc.array(jsc.number) + monadLaws.leftIdentity ( + jsc.constant (S.head), + jsc.array (jsc.number) ); - monadLaws.rightIdentity( - MaybeArb(jsc.number) + monadLaws.rightIdentity ( + MaybeArb (jsc.number) ); }); - suite('Alt laws', function() { + suite ('Alt laws', function() { - var altLaws = laws.Alt(equals); + var altLaws = laws.Alt (equals); - altLaws.associativity( - MaybeArb(jsc.number), - MaybeArb(jsc.number), - MaybeArb(jsc.number) + altLaws.associativity ( + MaybeArb (jsc.number), + MaybeArb (jsc.number), + MaybeArb (jsc.number) ); - altLaws.distributivity( - MaybeArb(jsc.number), - MaybeArb(jsc.number), - jsc.constant(Math.sqrt) + altLaws.distributivity ( + MaybeArb (jsc.number), + MaybeArb (jsc.number), + jsc.constant (Math.sqrt) ); }); - suite('Plus laws', function() { + suite ('Plus laws', function() { - var plusLaws = laws.Plus(equals, S.Maybe); + var plusLaws = laws.Plus (equals, S.Maybe); - plusLaws.leftIdentity( - MaybeArb(jsc.number) + plusLaws.leftIdentity ( + MaybeArb (jsc.number) ); - plusLaws.rightIdentity( - MaybeArb(jsc.number) + plusLaws.rightIdentity ( + MaybeArb (jsc.number) ); - plusLaws.annihilation( - jsc.constant(Math.sqrt) + plusLaws.annihilation ( + jsc.constant (Math.sqrt) ); }); - suite('Alternative laws', function() { + suite ('Alternative laws', function() { - var alternativeLaws = laws.Alternative(equals, S.Maybe); + var alternativeLaws = laws.Alternative (equals, S.Maybe); - alternativeLaws.distributivity( - MaybeArb(jsc.number), - MaybeArb(jsc.constant(Math.sqrt)), - MaybeArb(jsc.constant(Math.abs)) + alternativeLaws.distributivity ( + MaybeArb (jsc.number), + MaybeArb (jsc.constant (Math.sqrt)), + MaybeArb (jsc.constant (Math.abs)) ); - alternativeLaws.annihilation( - MaybeArb(jsc.number) + alternativeLaws.annihilation ( + MaybeArb (jsc.number) ); }); - suite('Foldable laws', function() { + suite ('Foldable laws', function() { - var foldableLaws = laws.Foldable(equals); + var foldableLaws = laws.Foldable (equals); - foldableLaws.associativity( - jsc.constant(add_), + foldableLaws.associativity ( + jsc.constant (add_), jsc.number, - MaybeArb(jsc.number) + MaybeArb (jsc.number) ); }); - suite('Traversable laws', function() { + suite ('Traversable laws', function() { - var traversableLaws = laws.Traversable(equals); + var traversableLaws = laws.Traversable (equals); - traversableLaws.naturality( - jsc.constant(S.eitherToMaybe), - MaybeArb(EitherArb(jsc.string, jsc.number)), - jsc.constant(S.Either), - jsc.constant(S.Maybe) + traversableLaws.naturality ( + jsc.constant (S.eitherToMaybe), + MaybeArb (EitherArb (jsc.string, jsc.number)), + jsc.constant (S.Either), + jsc.constant (S.Maybe) ); - traversableLaws.identity( - MaybeArb(jsc.number), - jsc.constant(Identity) + traversableLaws.identity ( + MaybeArb (jsc.number), + jsc.constant (Identity) ); - traversableLaws.composition( - MaybeArb(IdentityArb(MaybeArb(jsc.number))), - jsc.constant(Identity), - jsc.constant(S.Maybe) + traversableLaws.composition ( + MaybeArb (IdentityArb (MaybeArb (jsc.number))), + jsc.constant (Identity), + jsc.constant (S.Maybe) ); }); - suite('Extend laws', function() { + suite ('Extend laws', function() { - var extendLaws = laws.Extend(equals); + var extendLaws = laws.Extend (equals); - extendLaws.associativity( - MaybeArb(jsc.integer), - jsc.constant(function(maybe) { return maybe.value + 1; }), - jsc.constant(function(maybe) { return maybe.value * maybe.value; }) + extendLaws.associativity ( + MaybeArb (jsc.integer), + jsc.constant (function(maybe) { return maybe.value + 1; }), + jsc.constant (function(maybe) { return maybe.value * maybe.value; }) ); }); diff --git a/test/Maybe/MaybeType.js b/test/Maybe/MaybeType.js index 52bc649e..5f27fd81 100644 --- a/test/Maybe/MaybeType.js +++ b/test/Maybe/MaybeType.js @@ -1,18 +1,18 @@ 'use strict'; -var $ = require('sanctuary-def'); +var $ = require ('sanctuary-def'); -var S = require('../..'); +var S = require ('../..'); -var eq = require('../internal/eq'); +var eq = require ('../internal/eq'); -test('MaybeType', function() { +test ('MaybeType', function() { - eq($.test($.env, S.MaybeType($.Number), S.Nothing), true); - eq($.test($.env, S.MaybeType($.Number), S.Just(42)), true); - eq($.test($.env, S.MaybeType($.Number), S.Just('42')), false); - eq($.test($.env, S.MaybeType($.Number), S.Right(42)), false); - eq($.test($.env, S.MaybeType($.Number), null), false); + eq ($.test ($.env) (S.MaybeType ($.Number)) (S.Nothing)) (true); + eq ($.test ($.env) (S.MaybeType ($.Number)) (S.Just (42))) (true); + eq ($.test ($.env) (S.MaybeType ($.Number)) (S.Just ('42'))) (false); + eq ($.test ($.env) (S.MaybeType ($.Number)) (S.Right (42))) (false); + eq ($.test ($.env) (S.MaybeType ($.Number)) (null)) (false); }); diff --git a/test/Maybe/Nothing.js b/test/Maybe/Nothing.js index bc8b2ab1..adef5024 100644 --- a/test/Maybe/Nothing.js +++ b/test/Maybe/Nothing.js @@ -1,85 +1,85 @@ 'use strict'; -var FL = require('fantasy-land'); -var Z = require('sanctuary-type-classes'); +var FL = require ('fantasy-land'); +var Z = require ('sanctuary-type-classes'); -var S = require('../internal/sanctuary'); +var S = require ('../internal/sanctuary'); -var eq = require('../internal/eq'); +var eq = require ('../internal/eq'); -suite('Nothing', function() { +suite ('Nothing', function() { - test('member of the "Maybe a" type', function() { - eq(S.Nothing.constructor, S.Maybe); - eq(S.Nothing.isNothing, true); - eq(S.Nothing.isJust, false); + test ('member of the "Maybe a" type', function() { + eq (S.Nothing.constructor) (S.Maybe); + eq (S.Nothing.isNothing) (true); + eq (S.Nothing.isJust) (false); }); - test('"fantasy-land/alt" method', function() { - eq(S.Nothing[FL.alt].length, 1); - eq(S.Nothing[FL.alt](S.Nothing), S.Nothing); - eq(S.Nothing[FL.alt](S.Just(1)), S.Just(1)); + test ('"fantasy-land/alt" method', function() { + eq (S.Nothing[FL.alt].length) (1); + eq (S.Nothing[FL.alt] (S.Nothing)) (S.Nothing); + eq (S.Nothing[FL.alt] (S.Just (1))) (S.Just (1)); }); - test('"fantasy-land/ap" method', function() { - eq(S.Nothing[FL.ap].length, 1); - eq(S.Nothing[FL.ap](S.Nothing), S.Nothing); - eq(S.Nothing[FL.ap](S.Just(S.add(1))), S.Nothing); + test ('"fantasy-land/ap" method', function() { + eq (S.Nothing[FL.ap].length) (1); + eq (S.Nothing[FL.ap] (S.Nothing)) (S.Nothing); + eq (S.Nothing[FL.ap] (S.Just (S.add (1)))) (S.Nothing); }); - test('"fantasy-land/chain" method', function() { - eq(S.Nothing[FL.chain].length, 1); - eq(S.Nothing[FL.chain](S.head), S.Nothing); + test ('"fantasy-land/chain" method', function() { + eq (S.Nothing[FL.chain].length) (1); + eq (S.Nothing[FL.chain] (S.head)) (S.Nothing); }); - test('"fantasy-land/concat" method', function() { - eq(S.Nothing[FL.concat].length, 1); - eq(S.Nothing[FL.concat](S.Nothing), S.Nothing); - eq(S.Nothing[FL.concat](S.Just('foo')), S.Just('foo')); + test ('"fantasy-land/concat" method', function() { + eq (S.Nothing[FL.concat].length) (1); + eq (S.Nothing[FL.concat] (S.Nothing)) (S.Nothing); + eq (S.Nothing[FL.concat] (S.Just ('foo'))) (S.Just ('foo')); - eq(Z.Semigroup.test(S.Nothing), true); + eq (Z.Semigroup.test (S.Nothing)) (true); }); - test('"fantasy-land/equals" method', function() { - eq(S.Nothing[FL.equals].length, 1); - eq(S.Nothing[FL.equals](S.Nothing), true); - eq(S.Nothing[FL.equals](S.Just(42)), false); + test ('"fantasy-land/equals" method', function() { + eq (S.Nothing[FL.equals].length) (1); + eq (S.Nothing[FL.equals] (S.Nothing)) (true); + eq (S.Nothing[FL.equals] (S.Just (42))) (false); - eq(Z.Setoid.test(S.Nothing), true); + eq (Z.Setoid.test (S.Nothing)) (true); }); - test('"fantasy-land/extend" method', function() { - eq(S.Nothing[FL.extend].length, 1); - eq(S.Nothing[FL.extend](function(x) { return x.value / 2; }), S.Nothing); + test ('"fantasy-land/extend" method', function() { + eq (S.Nothing[FL.extend].length) (1); + eq (S.Nothing[FL.extend] (function(x) { return x.value / 2; })) (S.Nothing); }); - test('"fantasy-land/lte" method', function() { - eq(S.Nothing[FL.lte].length, 1); - eq(S.Nothing[FL.lte](S.Nothing), true); - eq(S.Nothing[FL.lte](S.Just(0)), true); + test ('"fantasy-land/lte" method', function() { + eq (S.Nothing[FL.lte].length) (1); + eq (S.Nothing[FL.lte] (S.Nothing)) (true); + eq (S.Nothing[FL.lte] (S.Just (0))) (true); - eq(Z.Ord.test(S.Nothing), true); + eq (Z.Ord.test (S.Nothing)) (true); }); - test('"fantasy-land/map" method', function() { - eq(S.Nothing[FL.map].length, 1); - eq(S.Nothing[FL.map](function() { return 42; }), S.Nothing); + test ('"fantasy-land/map" method', function() { + eq (S.Nothing[FL.map].length) (1); + eq (S.Nothing[FL.map] (function() { return 42; })) (S.Nothing); }); - test('"fantasy-land/reduce" method', function() { - eq(S.Nothing[FL.reduce].length, 2); - eq(S.Nothing[FL.reduce](function(x, y) { return x - y; }, 42), 42); + test ('"fantasy-land/reduce" method', function() { + eq (S.Nothing[FL.reduce].length) (2); + eq (S.Nothing[FL.reduce] (function(x, y) { return x - y; }, 42)) (42); }); - test('"toString" method', function() { - eq(S.Nothing.toString.length, 0); - eq(S.Nothing.toString(), 'Nothing'); + test ('"toString" method', function() { + eq (S.Nothing.toString.length) (0); + eq (S.Nothing.toString ()) ('Nothing'); }); - test('"inspect" method', function() { - eq(S.Nothing.inspect.length, 0); - eq(S.Nothing.inspect(), 'Nothing'); + test ('"inspect" method', function() { + eq (S.Nothing.inspect.length) (0); + eq (S.Nothing.inspect ()) ('Nothing'); }); }); diff --git a/test/T.js b/test/T.js index cf392938..d9382d99 100644 --- a/test/T.js +++ b/test/T.js @@ -1,18 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var map = require('./internal/map'); +var eq = require ('./internal/eq'); -test('T', function() { +test ('T', function() { - eq(typeof S.T, 'function'); - eq(S.T.length, 2); - eq(S.T.toString(), 'T :: a -> (a -> b) -> b'); + eq (typeof S.T) ('function'); + eq (S.T.length) (1); + eq (String (S.T)) ('T :: a -> (a -> b) -> b'); - eq(S.T(42, S.add(1)), 43); - eq(map(S.T(100))([S.add(1), Math.sqrt]), [101, 10]); + eq (S.T ('!') (S.concat ('foo'))) ('foo!'); + eq (S.T ('!') (S.concat ('bar'))) ('bar!'); }); diff --git a/test/add.js b/test/add.js index 737a2529..82b0c315 100644 --- a/test/add.js +++ b/test/add.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('add', function() { +test ('add', function() { - eq(typeof S.add, 'function'); - eq(S.add.length, 2); - eq(S.add.toString(), 'add :: FiniteNumber -> FiniteNumber -> FiniteNumber'); + eq (typeof S.add) ('function'); + eq (S.add.length) (1); + eq (String (S.add)) ('add :: FiniteNumber -> FiniteNumber -> FiniteNumber'); - eq(S.add(1, 1), 2); - eq(S.add(-1, -1), -2); - eq(S.add(1.5, 1), 2.5); - eq(S.add(-1.5, -1), -2.5); + eq (S.add (1) (1)) (2); + eq (S.add (-1) (-1)) (-2); + eq (S.add (1.5) (1)) (2.5); + eq (S.add (-1.5) (-1)) (-2.5); }); diff --git a/test/allPass.js b/test/allPass.js index 998421ad..28e97787 100644 --- a/test/allPass.js +++ b/test/allPass.js @@ -1,31 +1,31 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var List = require('./internal/List'); -var eq = require('./internal/eq'); +var List = require ('./internal/List'); +var eq = require ('./internal/eq'); var Cons = List.Cons; var Nil = List.Nil; -test('allPass', function() { +test ('allPass', function() { - eq(typeof S.allPass, 'function'); - eq(S.allPass.length, 2); - eq(S.allPass.toString(), 'allPass :: Foldable f => f (a -> Boolean) -> a -> Boolean'); + eq (typeof S.allPass) ('function'); + eq (S.allPass.length) (1); + eq (String (S.allPass)) ('allPass :: Foldable f => f (a -> Boolean) -> a -> Boolean'); - eq(S.allPass([], 'abacus'), true); - eq(S.allPass([S.test(/a/), S.test(/b/), S.test(/c/)], 'abacus'), true); - eq(S.allPass([S.test(/a/), S.test(/b/), S.test(/c/)], 'banana'), false); + eq (S.allPass ([]) ('abacus')) (true); + eq (S.allPass ([S.test (/a/), S.test (/b/), S.test (/c/)]) ('abacus')) (true); + eq (S.allPass ([S.test (/a/), S.test (/b/), S.test (/c/)]) ('banana')) (false); - eq(S.allPass(Nil, 'abacus'), true); - eq(S.allPass(Cons(S.test(/a/), Cons(S.test(/b/), Cons(S.test(/c/), Nil))), 'abacus'), true); - eq(S.allPass(Cons(S.test(/a/), Cons(S.test(/b/), Cons(S.test(/c/), Nil))), 'banana'), false); + eq (S.allPass (Nil) ('abacus')) (true); + eq (S.allPass (Cons (S.test (/a/)) (Cons (S.test (/b/)) (Cons (S.test (/c/)) (Nil)))) ('abacus')) (true); + eq (S.allPass (Cons (S.test (/a/)) (Cons (S.test (/b/)) (Cons (S.test (/c/)) (Nil)))) ('banana')) (false); var e = false; - eq(S.allPass([S.test(/a/), function() { e = true; }], 'monkey'), false); - eq(e, false); + eq (S.allPass ([S.test (/a/), function() { e = true; }]) ('monkey')) (false); + eq (e) (false); }); diff --git a/test/alt.js b/test/alt.js index 0649551f..d8b30572 100644 --- a/test/alt.js +++ b/test/alt.js @@ -1,28 +1,28 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('alt', function() { +test ('alt', function() { - eq(typeof S.alt, 'function'); - eq(S.alt.length, 2); - eq(S.alt.toString(), 'alt :: Alt f => f a -> f a -> f a'); + eq (typeof S.alt) ('function'); + eq (S.alt.length) (1); + eq (String (S.alt)) ('alt :: Alt f => f a -> f a -> f a'); - eq(S.alt([], []), []); - eq(S.alt([], [1, 2, 3]), [1, 2, 3]); - eq(S.alt([1, 2, 3], []), [1, 2, 3]); - eq(S.alt([1, 2, 3], [4, 5, 6]), [1, 2, 3, 4, 5, 6]); - eq(S.alt({}, {}), {}); - eq(S.alt({}, {a: 1, b: 2, c: 3}), {a: 1, b: 2, c: 3}); - eq(S.alt({a: 1, b: 2, c: 3}, {}), {a: 1, b: 2, c: 3}); - eq(S.alt({a: 1, b: 2, c: 3}, {d: 4, e: 5, f: 6}), {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}); - eq(S.alt({a: 1, b: 2, c: 3}, {c: 4, d: 5, e: 6}), {a: 1, b: 2, c: 4, d: 5, e: 6}); - eq(S.alt(S.Nothing, S.Nothing), S.Nothing); - eq(S.alt(S.Nothing, S.Just(1)), S.Just(1)); - eq(S.alt(S.Just(2), S.Nothing), S.Just(2)); - eq(S.alt(S.Just(3), S.Just(4)), S.Just(3)); + eq (S.alt ([]) ([])) ([]); + eq (S.alt ([]) ([1, 2, 3])) ([1, 2, 3]); + eq (S.alt ([1, 2, 3]) ([])) ([1, 2, 3]); + eq (S.alt ([1, 2, 3]) ([4, 5, 6])) ([1, 2, 3, 4, 5, 6]); + eq (S.alt ({}) ({})) ({}); + eq (S.alt ({}) ({a: 1, b: 2, c: 3})) ({a: 1, b: 2, c: 3}); + eq (S.alt ({a: 1, b: 2, c: 3}) ({})) ({a: 1, b: 2, c: 3}); + eq (S.alt ({a: 1, b: 2, c: 3}) ({d: 4, e: 5, f: 6})) ({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}); + eq (S.alt ({a: 1, b: 2, c: 3}) ({c: 4, d: 5, e: 6})) ({a: 1, b: 2, c: 4, d: 5, e: 6}); + eq (S.alt (S.Nothing) (S.Nothing)) (S.Nothing); + eq (S.alt (S.Nothing) (S.Just (1))) (S.Just (1)); + eq (S.alt (S.Just (2)) (S.Nothing)) (S.Just (2)); + eq (S.alt (S.Just (3)) (S.Just (4))) (S.Just (3)); }); diff --git a/test/and.js b/test/and.js index f9b10098..fc2e68d0 100644 --- a/test/and.js +++ b/test/and.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('and', function() { +test ('and', function() { - eq(typeof S.and, 'function'); - eq(S.and.length, 2); - eq(S.and.toString(), 'and :: Boolean -> Boolean -> Boolean'); + eq (typeof S.and) ('function'); + eq (S.and.length) (1); + eq (String (S.and)) ('and :: Boolean -> Boolean -> Boolean'); - eq(S.and(false, false), false); - eq(S.and(false, true), false); - eq(S.and(true, false), false); - eq(S.and(true, true), true); + eq (S.and (false) (false)) (false); + eq (S.and (false) (true)) (false); + eq (S.and (true) (false)) (false); + eq (S.and (true) (true)) (true); }); diff --git a/test/anyPass.js b/test/anyPass.js index 331ffe08..002316bb 100644 --- a/test/anyPass.js +++ b/test/anyPass.js @@ -1,31 +1,31 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var List = require('./internal/List'); -var eq = require('./internal/eq'); +var List = require ('./internal/List'); +var eq = require ('./internal/eq'); var Cons = List.Cons; var Nil = List.Nil; -test('anyPass', function() { +test ('anyPass', function() { - eq(typeof S.anyPass, 'function'); - eq(S.anyPass.length, 2); - eq(S.anyPass.toString(), 'anyPass :: Foldable f => f (a -> Boolean) -> a -> Boolean'); + eq (typeof S.anyPass) ('function'); + eq (S.anyPass.length) (1); + eq (String (S.anyPass)) ('anyPass :: Foldable f => f (a -> Boolean) -> a -> Boolean'); - eq(S.anyPass([], 'dolphin'), false); - eq(S.anyPass([S.test(/a/), S.test(/b/), S.test(/c/)], 'dolphin'), false); - eq(S.anyPass([S.test(/a/), S.test(/b/), S.test(/c/)], 'narwhal'), true); + eq (S.anyPass ([]) ('dolphin')) (false); + eq (S.anyPass ([S.test (/a/), S.test (/b/), S.test (/c/)]) ('dolphin')) (false); + eq (S.anyPass ([S.test (/a/), S.test (/b/), S.test (/c/)]) ('narwhal')) (true); - eq(S.anyPass(Nil, 'dolphin'), false); - eq(S.anyPass(Cons(S.test(/a/), Cons(S.test(/b/), Cons(S.test(/c/), Nil))), 'dolphin'), false); - eq(S.anyPass(Cons(S.test(/a/), Cons(S.test(/b/), Cons(S.test(/c/), Nil))), 'narwhal'), true); + eq (S.anyPass (Nil) ('dolphin')) (false); + eq (S.anyPass (Cons (S.test (/a/)) (Cons (S.test (/b/)) (Cons (S.test (/c/)) (Nil)))) ('dolphin')) (false); + eq (S.anyPass (Cons (S.test (/a/)) (Cons (S.test (/b/)) (Cons (S.test (/c/)) (Nil)))) ('narwhal')) (true); var e = false; - eq(S.anyPass([S.test(/a/), function() { e = true; }], 'narwhal'), true); - eq(e, false); + eq (S.anyPass ([S.test (/a/), function() { e = true; }]) ('narwhal')) (true); + eq (e) (false); }); diff --git a/test/ap.js b/test/ap.js index a75345c8..a1d63c13 100644 --- a/test/ap.js +++ b/test/ap.js @@ -1,29 +1,29 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('ap', function() { +test ('ap', function() { - eq(typeof S.ap, 'function'); - eq(S.ap.length, 2); - eq(S.ap.toString(), 'ap :: Apply f => f (a -> b) -> f a -> f b'); + eq (typeof S.ap) ('function'); + eq (S.ap.length) (1); + eq (String (S.ap)) ('ap :: Apply f => f (a -> b) -> f a -> f b'); - eq(S.ap([], []), []); - eq(S.ap([], [1, 2, 3]), []); - eq(S.ap([S.add(1)], []), []); - eq(S.ap([S.add(1)], [1, 2, 3]), [2, 3, 4]); - eq(S.ap([S.sub(1), Math.sqrt], [1, 4, 9]), [0, 3, 8, 1, 2, 3]); - eq(S.ap({}, {}), {}); - eq(S.ap({}, {x: 1, y: 2, z: 3}), {}); - eq(S.ap({x: S.add(1)}, {}), {}); - eq(S.ap({x: S.add(1)}, {x: 1}), {x: 2}); - eq(S.ap({x: S.add(1), y: S.sub(1), z: Math.sqrt}, {w: 0, x: 1, y: 2}), {x: 2, y: 1}); - eq(S.ap(S.Nothing, S.Nothing), S.Nothing); - eq(S.ap(S.Nothing, S.Just(9)), S.Nothing); - eq(S.ap(S.Just(Math.sqrt), S.Nothing), S.Nothing); - eq(S.ap(S.Just(Math.sqrt), S.Just(9)), S.Just(3)); + eq (S.ap ([]) ([])) ([]); + eq (S.ap ([]) ([1, 2, 3])) ([]); + eq (S.ap ([S.add (1)]) ([])) ([]); + eq (S.ap ([S.add (1)]) ([1, 2, 3])) ([2, 3, 4]); + eq (S.ap ([S.sub (1), Math.sqrt]) ([1, 4, 9])) ([0, 3, 8, 1, 2, 3]); + eq (S.ap ({}) ({})) ({}); + eq (S.ap ({}) ({x: 1, y: 2, z: 3})) ({}); + eq (S.ap ({x: S.add (1)}) ({})) ({}); + eq (S.ap ({x: S.add (1)}) ({x: 1})) ({x: 2}); + eq (S.ap ({x: S.add (1), y: S.sub (1), z: Math.sqrt}) ({w: 0, x: 1, y: 2})) ({x: 2, y: 1}); + eq (S.ap (S.Nothing) (S.Nothing)) (S.Nothing); + eq (S.ap (S.Nothing) (S.Just (9))) (S.Nothing); + eq (S.ap (S.Just (Math.sqrt)) (S.Nothing)) (S.Nothing); + eq (S.ap (S.Just (Math.sqrt)) (S.Just (9))) (S.Just (3)); }); diff --git a/test/apFirst.js b/test/apFirst.js index c5f3e68b..9a1bd19c 100644 --- a/test/apFirst.js +++ b/test/apFirst.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('apFirst', function() { +test ('apFirst', function() { - eq(typeof S.apFirst, 'function'); - eq(S.apFirst.length, 2); - eq(S.apFirst.toString(), 'apFirst :: Apply f => f a -> f b -> f a'); + eq (typeof S.apFirst) ('function'); + eq (S.apFirst.length) (1); + eq (String (S.apFirst)) ('apFirst :: Apply f => f a -> f b -> f a'); - eq(S.apFirst([1, 2], [3, 4]), [1, 1, 2, 2]); - eq(S.apFirst(S.Just(1), S.Just(2)), S.Just(1)); + eq (S.apFirst ([1, 2]) ([3, 4])) ([1, 1, 2, 2]); + eq (S.apFirst (S.Just (1)) (S.Just (2))) (S.Just (1)); }); diff --git a/test/apSecond.js b/test/apSecond.js index 38c6d3ef..e134193c 100644 --- a/test/apSecond.js +++ b/test/apSecond.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('apSecond', function() { +test ('apSecond', function() { - eq(typeof S.apSecond, 'function'); - eq(S.apSecond.length, 2); - eq(S.apSecond.toString(), 'apSecond :: Apply f => f a -> f b -> f b'); + eq (typeof S.apSecond) ('function'); + eq (S.apSecond.length) (1); + eq (String (S.apSecond)) ('apSecond :: Apply f => f a -> f b -> f b'); - eq(S.apSecond([1, 2], [3, 4]), [3, 4, 3, 4]); - eq(S.apSecond(S.Just(1), S.Just(2)), S.Just(2)); + eq (S.apSecond ([1, 2]) ([3, 4])) ([3, 4, 3, 4]); + eq (S.apSecond (S.Just (1)) (S.Just (2))) (S.Just (2)); }); diff --git a/test/append.js b/test/append.js index 51f58d65..d8297f30 100644 --- a/test/append.js +++ b/test/append.js @@ -1,24 +1,24 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('append', function() { +test ('append', function() { - eq(typeof S.append, 'function'); - eq(S.append.length, 2); - eq(S.append.toString(), 'append :: (Applicative f, Semigroup f) => a -> f a -> f a'); + eq (typeof S.append) ('function'); + eq (S.append.length) (1); + eq (String (S.append)) ('append :: (Applicative f, Semigroup f) => a -> f a -> f a'); - eq(S.append(3, []), [3]); - eq(S.append(3, [1, 2]), [1, 2, 3]); - eq(S.append([5, 6], [[1, 2], [3, 4]]), [[1, 2], [3, 4], [5, 6]]); + eq (S.append (3) ([])) ([3]); + eq (S.append (3) ([1, 2])) ([1, 2, 3]); + eq (S.append ([5, 6]) ([[1, 2], [3, 4]])) ([[1, 2], [3, 4], [5, 6]]); - eq(S.append([2], S.Nothing), S.Just([2])); - eq(S.append([2], S.Just([1])), S.Just([1, 2])); + eq (S.append ([2]) (S.Nothing)) (S.Just ([2])); + eq (S.append ([2]) (S.Just ([1]))) (S.Just ([1, 2])); - eq(S.append([2], S.Left('error')), S.Right([2])); - eq(S.append([2], S.Right([1])), S.Right([1, 2])); + eq (S.append ([2]) (S.Left ('error'))) (S.Right ([2])); + eq (S.append ([2]) (S.Right ([1]))) (S.Right ([1, 2])); }); diff --git a/test/at.js b/test/at.js index c25de285..c98e9908 100644 --- a/test/at.js +++ b/test/at.js @@ -1,24 +1,24 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('at', function() { +test ('at', function() { - eq(typeof S.at, 'function'); - eq(S.at.length, 2); - eq(S.at.toString(), 'at :: Integer -> Array a -> Maybe a'); + eq (typeof S.at) ('function'); + eq (S.at.length) (1); + eq (String (S.at)) ('at :: Integer -> Array a -> Maybe a'); - eq(S.at(-4, ['foo', 'bar', 'baz']), S.Nothing); - eq(S.at(-3, ['foo', 'bar', 'baz']), S.Just('foo')); - eq(S.at(-2, ['foo', 'bar', 'baz']), S.Just('bar')); - eq(S.at(-1, ['foo', 'bar', 'baz']), S.Just('baz')); + eq (S.at (-4) (['foo', 'bar', 'baz'])) (S.Nothing); + eq (S.at (-3) (['foo', 'bar', 'baz'])) (S.Just ('foo')); + eq (S.at (-2) (['foo', 'bar', 'baz'])) (S.Just ('bar')); + eq (S.at (-1) (['foo', 'bar', 'baz'])) (S.Just ('baz')); - eq(S.at(0, ['foo', 'bar', 'baz']), S.Just('foo')); - eq(S.at(1, ['foo', 'bar', 'baz']), S.Just('bar')); - eq(S.at(2, ['foo', 'bar', 'baz']), S.Just('baz')); - eq(S.at(3, ['foo', 'bar', 'baz']), S.Nothing); + eq (S.at (0) (['foo', 'bar', 'baz'])) (S.Just ('foo')); + eq (S.at (1) (['foo', 'bar', 'baz'])) (S.Just ('bar')); + eq (S.at (2) (['foo', 'bar', 'baz'])) (S.Just ('baz')); + eq (S.at (3) (['foo', 'bar', 'baz'])) (S.Nothing); }); diff --git a/test/bimap.js b/test/bimap.js index c9c067f9..89c116d7 100644 --- a/test/bimap.js +++ b/test/bimap.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('bimap', function() { +test ('bimap', function() { - eq(typeof S.bimap, 'function'); - eq(S.bimap.length, 3); - eq(S.bimap.toString(), 'bimap :: Bifunctor p => (a -> b) -> (c -> d) -> p a c -> p b d'); + eq (typeof S.bimap) ('function'); + eq (S.bimap.length) (1); + eq (String (S.bimap)) ('bimap :: Bifunctor p => (a -> b) -> (c -> d) -> p a c -> p b d'); - eq(S.bimap(S.toUpper, S.add(1), S.Left('xxx')), S.Left('XXX')); - eq(S.bimap(S.toUpper, S.add(1), S.Right(1000)), S.Right(1001)); + eq (S.bimap (S.toUpper) (S.add (1)) (S.Left ('xxx'))) (S.Left ('XXX')); + eq (S.bimap (S.toUpper) (S.add (1)) (S.Right (1000))) (S.Right (1001)); }); diff --git a/test/chain.js b/test/chain.js index 7ce874a1..1a02b3fb 100644 --- a/test/chain.js +++ b/test/chain.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('chain', function() { +test ('chain', function() { - eq(typeof S.chain, 'function'); - eq(S.chain.length, 2); - eq(S.chain.toString(), 'chain :: Chain m => (a -> m b) -> m a -> m b'); + eq (typeof S.chain) ('function'); + eq (S.chain.length) (1); + eq (String (S.chain)) ('chain :: Chain m => (a -> m b) -> m a -> m b'); - eq(S.chain(S.I, [[1, 2], [3, 4], [5, 6]]), [1, 2, 3, 4, 5, 6]); - eq(S.chain(S.parseFloat, S.Nothing), S.Nothing); - eq(S.chain(S.parseFloat, S.Just('X')), S.Nothing); - eq(S.chain(S.parseFloat, S.Just('0')), S.Just(0)); + eq (S.chain (S.I) ([[1, 2], [3, 4], [5, 6]])) ([1, 2, 3, 4, 5, 6]); + eq (S.chain (S.parseFloat) (S.Nothing)) (S.Nothing); + eq (S.chain (S.parseFloat) (S.Just ('X'))) (S.Nothing); + eq (S.chain (S.parseFloat) (S.Just ('0'))) (S.Just (0)); }); diff --git a/test/chainRec.js b/test/chainRec.js index 31539205..11bc743d 100644 --- a/test/chainRec.js +++ b/test/chainRec.js @@ -1,31 +1,31 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var map = require('./internal/map'); +var eq = require ('./internal/eq'); +var map = require ('./internal/map'); -test('chainRec', function() { +test ('chainRec', function() { - eq(typeof S.chainRec, 'function'); - eq(S.chainRec.length, 3); - eq(S.chainRec.toString(), 'chainRec :: ChainRec m => TypeRep m -> (a -> m (Either a b)) -> a -> m b'); + eq (typeof S.chainRec) ('function'); + eq (S.chainRec.length) (1); + eq (String (S.chainRec)) ('chainRec :: ChainRec m => TypeRep m -> (a -> m (Either a b)) -> a -> m b'); function permute(s) { - return s.length === 2 ? map(S.Right)([s + '!', s + '?']) - : map(S.Left)([s + 'o', s + 'n']); + return s.length === 2 ? map (S.Right) ([s + '!', s + '?']) + : map (S.Left) ([s + 'o', s + 'n']); } - eq(S.chainRec(Array, permute, ''), ['oo!', 'oo?', 'on!', 'on?', 'no!', 'no?', 'nn!', 'nn?']); + eq (S.chainRec (Array) (permute) ('')) (['oo!', 'oo?', 'on!', 'on?', 'no!', 'no?', 'nn!', 'nn?']); // The following test case is concerned with stack usage rather than with // the correctness of the result. This test case is a slightly modified // version of one from sanctuary-type-classes. The "stop" value is lower // to prevent the execution time from exceeding the test runner's timeout. function stepper(n) { - return n === 3000 ? map(S.Right)(function(env) { return n + env.inc; }) - : map(S.Left)(function(env) { return n + env.step; }); + return n === 3000 ? map (S.Right) (function(env) { return n + env.inc; }) + : map (S.Left) (function(env) { return n + env.step; }); } - eq(S.chainRec(Function, stepper, 0)({step: 2, inc: 100}), 3100); + eq (S.chainRec (Function) (stepper) (0) ({step: 2, inc: 100})) (3100); }); diff --git a/test/complement.js b/test/complement.js index 2c15895e..8e075742 100644 --- a/test/complement.js +++ b/test/complement.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('complement', function() { +test ('complement', function() { - eq(typeof S.complement, 'function'); - eq(S.complement.length, 2); - eq(S.complement.toString(), 'complement :: (a -> Boolean) -> a -> Boolean'); + eq (typeof S.complement) ('function'); + eq (S.complement.length) (1); + eq (String (S.complement)) ('complement :: (a -> Boolean) -> a -> Boolean'); - eq(S.complement(S.odd, 1), false); - eq(S.complement(S.odd, 2), true); + eq (S.complement (S.odd) (1)) (false); + eq (S.complement (S.odd) (2)) (true); }); diff --git a/test/compose.js b/test/compose.js index 4fe1c0a1..c974292d 100644 --- a/test/compose.js +++ b/test/compose.js @@ -1,16 +1,16 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('compose', function() { +test ('compose', function() { - eq(typeof S.compose, 'function'); - eq(S.compose.length, 2); - eq(S.compose.toString(), 'compose :: Semigroupoid s => s b c -> s a b -> s a c'); + eq (typeof S.compose) ('function'); + eq (S.compose.length) (1); + eq (String (S.compose)) ('compose :: Semigroupoid s => s b c -> s a b -> s a c'); - eq(S.compose(S.mult(2), S.add(1))(20), 42); + eq (S.compose (S.mult (2)) (S.add (1)) (20)) (42); }); diff --git a/test/concat.js b/test/concat.js index 03dd7d28..d393b9a9 100644 --- a/test/concat.js +++ b/test/concat.js @@ -1,34 +1,34 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('concat', function() { +test ('concat', function() { - eq(typeof S.concat, 'function'); - eq(S.concat.length, 2); - eq(S.concat.toString(), 'concat :: Semigroup a => a -> a -> a'); + eq (typeof S.concat) ('function'); + eq (S.concat.length) (1); + eq (String (S.concat)) ('concat :: Semigroup a => a -> a -> a'); - eq(S.concat([], []), []); - eq(S.concat([1, 2, 3], []), [1, 2, 3]); - eq(S.concat([], [4, 5, 6]), [4, 5, 6]); - eq(S.concat([1, 2, 3], [4, 5, 6]), [1, 2, 3, 4, 5, 6]); + eq (S.concat ([]) ([])) ([]); + eq (S.concat ([1, 2, 3]) ([])) ([1, 2, 3]); + eq (S.concat ([]) ([4, 5, 6])) ([4, 5, 6]); + eq (S.concat ([1, 2, 3]) ([4, 5, 6])) ([1, 2, 3, 4, 5, 6]); - eq(S.concat('', ''), ''); - eq(S.concat('foo', ''), 'foo'); - eq(S.concat('', 'bar'), 'bar'); - eq(S.concat('foo', 'bar'), 'foobar'); + eq (S.concat ('') ('')) (''); + eq (S.concat ('foo') ('')) ('foo'); + eq (S.concat ('') ('bar')) ('bar'); + eq (S.concat ('foo') ('bar')) ('foobar'); - eq(S.concat(S.Nothing, S.Nothing), S.Nothing); - eq(S.concat(S.Just('foo'), S.Nothing), S.Just('foo')); - eq(S.concat(S.Nothing, S.Just('bar')), S.Just('bar')); - eq(S.concat(S.Just('foo'), S.Just('bar')), S.Just('foobar')); + eq (S.concat (S.Nothing) (S.Nothing)) (S.Nothing); + eq (S.concat (S.Just ('foo')) (S.Nothing)) (S.Just ('foo')); + eq (S.concat (S.Nothing) (S.Just ('bar'))) (S.Just ('bar')); + eq (S.concat (S.Just ('foo')) (S.Just ('bar'))) (S.Just ('foobar')); - eq(S.concat(S.Left('abc'), S.Left('def')), S.Left('abcdef')); - eq(S.concat(S.Right([1, 2, 3]), S.Left('def')), S.Right([1, 2, 3])); - eq(S.concat(S.Left('abc'), S.Right([4, 5, 6])), S.Right([4, 5, 6])); - eq(S.concat(S.Right([1, 2, 3]), S.Right([4, 5, 6])), S.Right([1, 2, 3, 4, 5, 6])); + eq (S.concat (S.Left ('abc')) (S.Left ('def'))) (S.Left ('abcdef')); + eq (S.concat (S.Right ([1, 2, 3])) (S.Left ('def'))) (S.Right ([1, 2, 3])); + eq (S.concat (S.Left ('abc')) (S.Right ([4, 5, 6]))) (S.Right ([4, 5, 6])); + eq (S.concat (S.Right ([1, 2, 3])) (S.Right ([4, 5, 6]))) (S.Right ([1, 2, 3, 4, 5, 6])); }); diff --git a/test/contramap.js b/test/contramap.js index 0278d4b8..ebe62f04 100644 --- a/test/contramap.js +++ b/test/contramap.js @@ -1,16 +1,16 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('contramap', function() { +test ('contramap', function() { - eq(typeof S.contramap, 'function'); - eq(S.contramap.length, 2); - eq(S.contramap.toString(), 'contramap :: Contravariant f => (b -> a) -> f a -> f b'); + eq (typeof S.contramap) ('function'); + eq (S.contramap.length) (1); + eq (String (S.contramap)) ('contramap :: Contravariant f => (b -> a) -> f a -> f b'); - eq(S.contramap(S.prop('length'), Math.sqrt)('Sanctuary'), 3); + eq (S.contramap (S.prop ('length')) (Math.sqrt) ('Sanctuary')) (3); }); diff --git a/test/create.js b/test/create.js index 81845a34..fe499d68 100644 --- a/test/create.js +++ b/test/create.js @@ -1,52 +1,51 @@ 'use strict'; -var $ = require('sanctuary-def'); +var $ = require ('sanctuary-def'); -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var throws = require('./internal/throws'); +var eq = require ('./internal/eq'); +var throws = require ('./internal/throws'); // FooTrue42 :: Type -var FooTrue42 = $.EnumType('my-package/FooTrue42', '', ['foo', true, 42]); +var FooTrue42 = $.EnumType ('my-package/FooTrue42') ('') (['foo', true, 42]); // customEnv :: Array Type -var customEnv = S.env.concat([FooTrue42]); - -var checkedDefaultEnv = S.create({checkTypes: true, env: S.env}); -var checkedCustomEnv = S.create({checkTypes: true, env: customEnv}); -var uncheckedDefaultEnv = S.create({checkTypes: false, env: S.env}); -var uncheckedCustomEnv = S.create({checkTypes: false, env: customEnv}); - - -test('create', function() { - - eq(typeof S.create, 'function'); - eq(S.create.length, 1); - eq(S.create.toString(), 'create :: { checkTypes :: Boolean, env :: Array Any } -> Object'); - - var expected = S.sort(Object.keys(S)); - eq(S.sort(Object.keys(checkedDefaultEnv)), expected); - eq(S.sort(Object.keys(checkedCustomEnv)), expected); - eq(S.sort(Object.keys(uncheckedDefaultEnv)), expected); - eq(S.sort(Object.keys(uncheckedCustomEnv)), expected); - - eq(uncheckedDefaultEnv.add(1, 42), S.add(1, 42)); - eq(uncheckedDefaultEnv.add(1, 'XXX'), '1XXX'); - - throws(function() { S.I(['foo', 'foo', 42]); }, - TypeError, - 'Type-variable constraint violation\n' + - '\n' + - 'I :: a -> a\n' + - ' ^\n' + - ' 1\n' + - '\n' + - '1) ["foo", "foo", 42] :: Array ???\n' + - '\n' + - 'Since there is no type of which all the above values are members, the type-variable constraint has been violated.\n'); - - eq(checkedCustomEnv.I(['foo', 'foo', 42]), ['foo', 'foo', 42]); +var customEnv = S.env.concat ([FooTrue42]); + +var checkedDefaultEnv = S.create ({checkTypes: true, env: S.env}); +var checkedCustomEnv = S.create ({checkTypes: true, env: customEnv}); +var uncheckedDefaultEnv = S.create ({checkTypes: false, env: S.env}); +var uncheckedCustomEnv = S.create ({checkTypes: false, env: customEnv}); + + +test ('create', function() { + + eq (typeof S.create) ('function'); + eq (S.create.length) (1); + eq (String (S.create)) ('create :: { checkTypes :: Boolean, env :: Array Any } -> Object'); + + var expected = S.sort (Object.keys (S)); + eq (S.sort (Object.keys (checkedDefaultEnv))) (expected); + eq (S.sort (Object.keys (checkedCustomEnv))) (expected); + eq (S.sort (Object.keys (uncheckedDefaultEnv))) (expected); + eq (S.sort (Object.keys (uncheckedCustomEnv))) (expected); + + eq (uncheckedDefaultEnv.add (1) (42)) (S.add (1) (42)); + eq (uncheckedDefaultEnv.add (1) ('XXX')) ('1XXX'); + + throws (function() { S.I (['foo', 'foo', 42]); }) + (new TypeError ('Type-variable constraint violation\n' + + '\n' + + 'I :: a -> a\n' + + ' ^\n' + + ' 1\n' + + '\n' + + '1) ["foo", "foo", 42] :: Array ???\n' + + '\n' + + 'Since there is no type of which all the above values are members, the type-variable constraint has been violated.\n')); + + eq (checkedCustomEnv.I (['foo', 'foo', 42])) (['foo', 'foo', 42]); }); diff --git a/test/curry2.js b/test/curry2.js index fb6b2fa7..90c1fd09 100644 --- a/test/curry2.js +++ b/test/curry2.js @@ -1,19 +1,18 @@ 'use strict'; -var S = require('..'); +var Z = require ('sanctuary-type-classes'); -var add_ = require('./internal/add_'); -var eq = require('./internal/eq'); +var S = require ('..'); +var eq = require ('./internal/eq'); -test('curry2', function() { - eq(typeof S.curry2, 'function'); - eq(S.curry2.length, 3); - eq(S.curry2.toString(), 'curry2 :: ((a, b) -> c) -> a -> b -> c'); +test ('curry2', function() { - var curried = S.curry2(add_); - eq(curried(1, 2), 3); - eq(curried(1)(2), 3); + eq (typeof S.curry2) ('function'); + eq (S.curry2.length) (1); + eq (String (S.curry2)) ('curry2 :: ((a, b) -> c) -> a -> b -> c'); + + eq (S.curry2 (Z.concat) ('foo') ('bar')) ('foobar'); }); diff --git a/test/curry3.js b/test/curry3.js index b0f061f7..718889b7 100644 --- a/test/curry3.js +++ b/test/curry3.js @@ -1,20 +1,16 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('curry3', function() { +test ('curry3', function() { - eq(typeof S.curry3, 'function'); - eq(S.curry3.length, 4); - eq(S.curry3.toString(), 'curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d'); + eq (typeof S.curry3) ('function'); + eq (S.curry3.length) (1); + eq (String (S.curry3)) ('curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d'); - var curried = S.curry3(function(x, y, z) { return x + y + z; }); - eq(curried(1, 2, 3), 6); - eq(curried(1, 2)(3), 6); - eq(curried(1)(2, 3), 6); - eq(curried(1)(2)(3), 6); + eq (S.curry3 (function(x, y, z) { return x + y + z; }) ('x') ('y') ('z')) ('xyz'); }); diff --git a/test/curry4.js b/test/curry4.js index 459def0a..b8a51bd3 100644 --- a/test/curry4.js +++ b/test/curry4.js @@ -1,24 +1,16 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('curry4', function() { +test ('curry4', function() { - eq(typeof S.curry4, 'function'); - eq(S.curry4.length, 5); - eq(S.curry4.toString(), 'curry4 :: ((a, b, c, d) -> e) -> a -> b -> c -> d -> e'); + eq (typeof S.curry4) ('function'); + eq (S.curry4.length) (1); + eq (String (S.curry4)) ('curry4 :: ((a, b, c, d) -> e) -> a -> b -> c -> d -> e'); - var curried = S.curry4(function(w, x, y, z) { return w + x + y + z; }); - eq(curried(1, 2, 3, 4), 10); - eq(curried(1, 2, 3)(4), 10); - eq(curried(1, 2)(3, 4), 10); - eq(curried(1, 2)(3)(4), 10); - eq(curried(1)(2, 3, 4), 10); - eq(curried(1)(2, 3)(4), 10); - eq(curried(1)(2)(3, 4), 10); - eq(curried(1)(2)(3)(4), 10); + eq (S.curry4 (function(w, x, y, z) { return w + x + y + z; }) ('w') ('x') ('y') ('z')) ('wxyz'); }); diff --git a/test/curry5.js b/test/curry5.js index e36c03f7..d68dff38 100644 --- a/test/curry5.js +++ b/test/curry5.js @@ -1,32 +1,16 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('curry5', function() { +test ('curry5', function() { - eq(typeof S.curry5, 'function'); - eq(S.curry5.length, 6); - eq(S.curry5.toString(), 'curry5 :: ((a, b, c, d, e) -> r) -> a -> b -> c -> d -> e -> r'); + eq (typeof S.curry5) ('function'); + eq (S.curry5.length) (1); + eq (String (S.curry5)) ('curry5 :: ((a, b, c, d, e) -> r) -> a -> b -> c -> d -> e -> r'); - var curried = S.curry5(function(v, w, x, y, z) { return v + w + x + y + z; }); - eq(curried(1, 2, 3, 4, 5), 15); - eq(curried(1, 2, 3, 4)(5), 15); - eq(curried(1, 2, 3)(4, 5), 15); - eq(curried(1, 2, 3)(4)(5), 15); - eq(curried(1, 2)(3, 4, 5), 15); - eq(curried(1, 2)(3, 4)(5), 15); - eq(curried(1, 2)(3)(4, 5), 15); - eq(curried(1, 2)(3)(4)(5), 15); - eq(curried(1)(2, 3, 4, 5), 15); - eq(curried(1)(2, 3, 4)(5), 15); - eq(curried(1)(2, 3)(4, 5), 15); - eq(curried(1)(2, 3)(4)(5), 15); - eq(curried(1)(2)(3, 4, 5), 15); - eq(curried(1)(2)(3, 4)(5), 15); - eq(curried(1)(2)(3)(4, 5), 15); - eq(curried(1)(2)(3)(4)(5), 15); + eq (S.curry5 (function(v, w, x, y, z) { return v + w + x + y + z; }) ('v') ('w') ('x') ('y') ('z')) ('vwxyz'); }); diff --git a/test/div.js b/test/div.js index 3739a9cb..ece64191 100644 --- a/test/div.js +++ b/test/div.js @@ -1,16 +1,16 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('div', function() { +test ('div', function() { - eq(typeof S.div, 'function'); - eq(S.div.length, 1); - eq(S.div.toString(), 'div :: NonZeroFiniteNumber -> (FiniteNumber -> FiniteNumber)'); + eq (typeof S.div) ('function'); + eq (S.div.length) (1); + eq (String (S.div)) ('div :: NonZeroFiniteNumber -> FiniteNumber -> FiniteNumber'); - eq(S.map(S.div(2), [0, 1, 2, 3]), [0, 0.5, 1, 1.5]); + eq (S.map (S.div (2)) ([0, 1, 2, 3])) ([0, 0.5, 1, 1.5]); }); diff --git a/test/drop.js b/test/drop.js index 931882da..c995e8f7 100644 --- a/test/drop.js +++ b/test/drop.js @@ -1,24 +1,24 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('drop', function() { +test ('drop', function() { - eq(typeof S.drop, 'function'); - eq(S.drop.length, 2); - eq(S.drop.toString(), 'drop :: Integer -> Array a -> Maybe (Array a)'); + eq (typeof S.drop) ('function'); + eq (S.drop.length) (1); + eq (String (S.drop)) ('drop :: Integer -> Array a -> Maybe (Array a)'); - eq(S.drop(0, [1, 2, 3, 4, 5]), S.Just([1, 2, 3, 4, 5])); - eq(S.drop(1, [1, 2, 3, 4, 5]), S.Just([2, 3, 4, 5])); - eq(S.drop(2, [1, 2, 3, 4, 5]), S.Just([3, 4, 5])); - eq(S.drop(3, [1, 2, 3, 4, 5]), S.Just([4, 5])); - eq(S.drop(4, [1, 2, 3, 4, 5]), S.Just([5])); - eq(S.drop(5, [1, 2, 3, 4, 5]), S.Just([])); - eq(S.drop(6, [1, 2, 3, 4, 5]), S.Nothing); + eq (S.drop (0) ([1, 2, 3, 4, 5])) (S.Just ([1, 2, 3, 4, 5])); + eq (S.drop (1) ([1, 2, 3, 4, 5])) (S.Just ([2, 3, 4, 5])); + eq (S.drop (2) ([1, 2, 3, 4, 5])) (S.Just ([3, 4, 5])); + eq (S.drop (3) ([1, 2, 3, 4, 5])) (S.Just ([4, 5])); + eq (S.drop (4) ([1, 2, 3, 4, 5])) (S.Just ([5])); + eq (S.drop (5) ([1, 2, 3, 4, 5])) (S.Just ([])); + eq (S.drop (6) ([1, 2, 3, 4, 5])) (S.Nothing); - eq(S.drop(-1, [1, 2, 3, 4, 5]), S.Nothing); + eq (S.drop (-1) ([1, 2, 3, 4, 5])) (S.Nothing); }); diff --git a/test/dropLast.js b/test/dropLast.js index 2cef5b7f..1375f1bd 100644 --- a/test/dropLast.js +++ b/test/dropLast.js @@ -1,24 +1,24 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('dropLast', function() { +test ('dropLast', function() { - eq(typeof S.dropLast, 'function'); - eq(S.dropLast.length, 2); - eq(S.dropLast.toString(), 'dropLast :: Integer -> Array a -> Maybe (Array a)'); + eq (typeof S.dropLast) ('function'); + eq (S.dropLast.length) (1); + eq (String (S.dropLast)) ('dropLast :: Integer -> Array a -> Maybe (Array a)'); - eq(S.dropLast(0, [1, 2, 3, 4, 5]), S.Just([1, 2, 3, 4, 5])); - eq(S.dropLast(1, [1, 2, 3, 4, 5]), S.Just([1, 2, 3, 4])); - eq(S.dropLast(2, [1, 2, 3, 4, 5]), S.Just([1, 2, 3])); - eq(S.dropLast(3, [1, 2, 3, 4, 5]), S.Just([1, 2])); - eq(S.dropLast(4, [1, 2, 3, 4, 5]), S.Just([1])); - eq(S.dropLast(5, [1, 2, 3, 4, 5]), S.Just([])); - eq(S.dropLast(6, [1, 2, 3, 4, 5]), S.Nothing); + eq (S.dropLast (0) ([1, 2, 3, 4, 5])) (S.Just ([1, 2, 3, 4, 5])); + eq (S.dropLast (1) ([1, 2, 3, 4, 5])) (S.Just ([1, 2, 3, 4])); + eq (S.dropLast (2) ([1, 2, 3, 4, 5])) (S.Just ([1, 2, 3])); + eq (S.dropLast (3) ([1, 2, 3, 4, 5])) (S.Just ([1, 2])); + eq (S.dropLast (4) ([1, 2, 3, 4, 5])) (S.Just ([1])); + eq (S.dropLast (5) ([1, 2, 3, 4, 5])) (S.Just ([])); + eq (S.dropLast (6) ([1, 2, 3, 4, 5])) (S.Nothing); - eq(S.dropLast(-1, [1, 2, 3, 4, 5]), S.Nothing); + eq (S.dropLast (-1) ([1, 2, 3, 4, 5])) (S.Nothing); }); diff --git a/test/dropWhile.js b/test/dropWhile.js index ef57dc5b..d9b766be 100644 --- a/test/dropWhile.js +++ b/test/dropWhile.js @@ -1,22 +1,22 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('dropWhile', function() { +test ('dropWhile', function() { - eq(typeof S.dropWhile, 'function'); - eq(S.dropWhile.length, 2); - eq(S.dropWhile.toString(), 'dropWhile :: Filterable f => (a -> Boolean) -> f a -> f a'); + eq (typeof S.dropWhile) ('function'); + eq (S.dropWhile.length) (1); + eq (String (S.dropWhile)) ('dropWhile :: Filterable f => (a -> Boolean) -> f a -> f a'); - eq(S.dropWhile(S.odd, [3, 3, 3, 7, 6, 3, 5, 4]), [6, 3, 5, 4]); - eq(S.dropWhile(S.even, [3, 3, 3, 7, 6, 3, 5, 4]), [3, 3, 3, 7, 6, 3, 5, 4]); - eq(S.dropWhile(S.odd, []), []); + eq (S.dropWhile (S.odd) ([3, 3, 3, 7, 6, 3, 5, 4])) ([6, 3, 5, 4]); + eq (S.dropWhile (S.even) ([3, 3, 3, 7, 6, 3, 5, 4])) ([3, 3, 3, 7, 6, 3, 5, 4]); + eq (S.dropWhile (S.odd) ([])) ([]); - eq(S.dropWhile(S.odd, S.Just(1)), S.Nothing); - eq(S.dropWhile(S.even, S.Just(1)), S.Just(1)); - eq(S.dropWhile(S.odd, S.Nothing), S.Nothing); + eq (S.dropWhile (S.odd) (S.Just (1))) (S.Nothing); + eq (S.dropWhile (S.even) (S.Just (1))) (S.Just (1)); + eq (S.dropWhile (S.odd) (S.Nothing)) (S.Nothing); }); diff --git a/test/duplicate.js b/test/duplicate.js index d10a7476..d45189df 100644 --- a/test/duplicate.js +++ b/test/duplicate.js @@ -1,21 +1,21 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('duplicate', function() { +test ('duplicate', function() { - eq(typeof S.duplicate, 'function'); - eq(S.duplicate.length, 1); - eq(S.duplicate.toString(), 'duplicate :: Extend w => w a -> w (w a)'); + eq (typeof S.duplicate) ('function'); + eq (S.duplicate.length) (1); + eq (String (S.duplicate)) ('duplicate :: Extend w => w a -> w (w a)'); - eq(S.duplicate([]), []); - eq(S.duplicate([1]), [[1]]); - eq(S.duplicate([1, 2]), [[1, 2], [2]]); - eq(S.duplicate([1, 2, 3]), [[1, 2, 3], [2, 3], [3]]); - eq(S.duplicate(S.reverse)([1, 2])([3, 4]), [4, 3, 2, 1]); - eq(S.duplicate(S.Just(1)), S.Just(S.Just(1))); + eq (S.duplicate ([])) ([]); + eq (S.duplicate ([1])) ([[1]]); + eq (S.duplicate ([1, 2])) ([[1, 2], [2]]); + eq (S.duplicate ([1, 2, 3])) ([[1, 2, 3], [2, 3], [3]]); + eq (S.duplicate (S.reverse) ([1, 2]) ([3, 4])) ([4, 3, 2, 1]); + eq (S.duplicate (S.Just (1))) (S.Just (S.Just (1))); }); diff --git a/test/either.js b/test/either.js index 52bda347..e9e35d5e 100644 --- a/test/either.js +++ b/test/either.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('either', function() { +test ('either', function() { - eq(typeof S.either, 'function'); - eq(S.either.length, 3); - eq(S.either.toString(), 'either :: (a -> c) -> (b -> c) -> Either a b -> c'); + eq (typeof S.either) ('function'); + eq (S.either.length) (1); + eq (String (S.either)) ('either :: (a -> c) -> (b -> c) -> Either a b -> c'); - eq(S.either(S.prop('length'), Math.sqrt, S.Left('abc')), 3); - eq(S.either(S.prop('length'), Math.sqrt, S.Right(256)), 16); + eq (S.either (S.prop ('length')) (Math.sqrt) (S.Left ('abc'))) (3); + eq (S.either (S.prop ('length')) (Math.sqrt) (S.Right (256))) (16); }); diff --git a/test/eitherToMaybe.js b/test/eitherToMaybe.js index 6cee8a31..d905e972 100644 --- a/test/eitherToMaybe.js +++ b/test/eitherToMaybe.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('eitherToMaybe', function() { +test ('eitherToMaybe', function() { - eq(typeof S.eitherToMaybe, 'function'); - eq(S.eitherToMaybe.length, 1); - eq(S.eitherToMaybe.toString(), 'eitherToMaybe :: Either a b -> Maybe b'); + eq (typeof S.eitherToMaybe) ('function'); + eq (S.eitherToMaybe.length) (1); + eq (String (S.eitherToMaybe)) ('eitherToMaybe :: Either a b -> Maybe b'); - eq(S.eitherToMaybe(S.Left('Cannot divide by zero')), S.Nothing); - eq(S.eitherToMaybe(S.Right(42)), S.Just(42)); + eq (S.eitherToMaybe (S.Left ('Cannot divide by zero'))) (S.Nothing); + eq (S.eitherToMaybe (S.Right (42))) (S.Just (42)); }); diff --git a/test/elem.js b/test/elem.js index 32249a50..b4035c46 100644 --- a/test/elem.js +++ b/test/elem.js @@ -1,22 +1,22 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('elem', function() { +test ('elem', function() { - eq(typeof S.elem, 'function'); - eq(S.elem.length, 2); - eq(S.elem.toString(), 'elem :: (Setoid a, Foldable f) => a -> f a -> Boolean'); + eq (typeof S.elem) ('function'); + eq (S.elem.length) (1); + eq (String (S.elem)) ('elem :: (Setoid a, Foldable f) => a -> f a -> Boolean'); - eq(S.elem('c', ['a', 'b', 'c']), true); - eq(S.elem('x', ['a', 'b', 'c']), false); - eq(S.elem(3, {x: 1, y: 2, z: 3}), true); - eq(S.elem(8, {x: 1, y: 2, z: 3}), false); - eq(S.elem(0, S.Just(0)), true); - eq(S.elem(0, S.Just(1)), false); - eq(S.elem(0, S.Nothing), false); + eq (S.elem ('c') (['a', 'b', 'c'])) (true); + eq (S.elem ('x') (['a', 'b', 'c'])) (false); + eq (S.elem (3) ({x: 1, y: 2, z: 3})) (true); + eq (S.elem (8) ({x: 1, y: 2, z: 3})) (false); + eq (S.elem (0) (S.Just (0))) (true); + eq (S.elem (0) (S.Just (1))) (false); + eq (S.elem (0) (S.Nothing)) (false); }); diff --git a/test/empty.js b/test/empty.js index e18a7e0e..1add0cde 100644 --- a/test/empty.js +++ b/test/empty.js @@ -1,18 +1,18 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('empty', function() { +test ('empty', function() { - eq(typeof S.empty, 'function'); - eq(S.empty.length, 1); - eq(S.empty.toString(), 'empty :: Monoid a => TypeRep a -> a'); + eq (typeof S.empty) ('function'); + eq (S.empty.length) (1); + eq (String (S.empty)) ('empty :: Monoid a => TypeRep a -> a'); - eq(S.empty(String), ''); - eq(S.empty(Array), []); - eq(S.empty(Object), {}); + eq (S.empty (String)) (''); + eq (S.empty (Array)) ([]); + eq (S.empty (Object)) ({}); }); diff --git a/test/encase.js b/test/encase.js index aede537b..97601744 100644 --- a/test/encase.js +++ b/test/encase.js @@ -1,18 +1,18 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var factorial = require('./internal/factorial'); +var eq = require ('./internal/eq'); +var factorial = require ('./internal/factorial'); -test('encase', function() { +test ('encase', function() { - eq(typeof S.encase, 'function'); - eq(S.encase.length, 2); - eq(S.encase.toString(), 'encase :: (a -> b) -> a -> Maybe b'); + eq (typeof S.encase) ('function'); + eq (S.encase.length) (1); + eq (String (S.encase)) ('encase :: (a -> b) -> a -> Maybe b'); - eq(S.encase(factorial, 5), S.Just(120)); - eq(S.encase(factorial, -1), S.Nothing); + eq (S.encase (factorial) (5)) (S.Just (120)); + eq (S.encase (factorial) (-1)) (S.Nothing); }); diff --git a/test/encase2.js b/test/encase2.js index be62355b..040f8332 100644 --- a/test/encase2.js +++ b/test/encase2.js @@ -1,18 +1,18 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var rem = require('./internal/rem'); +var eq = require ('./internal/eq'); +var rem = require ('./internal/rem'); -test('encase2', function() { +test ('encase2', function() { - eq(typeof S.encase2, 'function'); - eq(S.encase2.length, 3); - eq(S.encase2.toString(), 'encase2 :: (a -> b -> c) -> a -> b -> Maybe c'); + eq (typeof S.encase2) ('function'); + eq (S.encase2.length) (1); + eq (String (S.encase2)) ('encase2 :: (a -> b -> c) -> a -> b -> Maybe c'); - eq(S.encase2(rem, 42, 5), S.Just(2)); - eq(S.encase2(rem, 42, 0), S.Nothing); + eq (S.encase2 (rem) (42) (5)) (S.Just (2)); + eq (S.encase2 (rem) (42) (0)) (S.Nothing); }); diff --git a/test/encase3.js b/test/encase3.js index c86df5cf..c141de29 100644 --- a/test/encase3.js +++ b/test/encase3.js @@ -1,18 +1,18 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var area = require('./internal/area'); -var eq = require('./internal/eq'); +var area = require ('./internal/area'); +var eq = require ('./internal/eq'); -test('encase3', function() { +test ('encase3', function() { - eq(typeof S.encase3, 'function'); - eq(S.encase3.length, 4); - eq(S.encase3.toString(), 'encase3 :: (a -> b -> c -> d) -> a -> b -> c -> Maybe d'); + eq (typeof S.encase3) ('function'); + eq (S.encase3.length) (1); + eq (String (S.encase3)) ('encase3 :: (a -> b -> c -> d) -> a -> b -> c -> Maybe d'); - eq(S.encase3(area, 3, 4, 5), S.Just(6)); - eq(S.encase3(area, 2, 2, 5), S.Nothing); + eq (S.encase3 (area) (3) (4) (5)) (S.Just (6)); + eq (S.encase3 (area) (2) (2) (5)) (S.Nothing); }); diff --git a/test/encaseEither.js b/test/encaseEither.js index 42862ab6..a85a34c0 100644 --- a/test/encaseEither.js +++ b/test/encaseEither.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var factorial = require('./internal/factorial'); +var eq = require ('./internal/eq'); +var factorial = require ('./internal/factorial'); -test('encaseEither', function() { +test ('encaseEither', function() { - eq(typeof S.encaseEither, 'function'); - eq(S.encaseEither.length, 3); - eq(S.encaseEither.toString(), 'encaseEither :: (Error -> l) -> (a -> r) -> a -> Either l r'); + eq (typeof S.encaseEither) ('function'); + eq (S.encaseEither.length) (1); + eq (String (S.encaseEither)) ('encaseEither :: (Error -> l) -> (a -> r) -> a -> Either l r'); - eq(S.encaseEither(S.I, factorial, 5), S.Right(120)); - eq(S.encaseEither(S.I, factorial, -1), S.Left(new Error('Cannot determine factorial of negative number'))); - eq(S.encaseEither(S.prop('message'), factorial, -1), S.Left('Cannot determine factorial of negative number')); + eq (S.encaseEither (S.I) (factorial) (5)) (S.Right (120)); + eq (S.encaseEither (S.I) (factorial) (-1)) (S.Left (new Error ('Cannot determine factorial of negative number'))); + eq (S.encaseEither (S.prop ('message')) (factorial) (-1)) (S.Left ('Cannot determine factorial of negative number')); }); diff --git a/test/encaseEither2.js b/test/encaseEither2.js index 3c686e37..d4dc32f1 100644 --- a/test/encaseEither2.js +++ b/test/encaseEither2.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var rem = require('./internal/rem'); +var eq = require ('./internal/eq'); +var rem = require ('./internal/rem'); -test('encaseEither2', function() { +test ('encaseEither2', function() { - eq(typeof S.encaseEither2, 'function'); - eq(S.encaseEither2.length, 4); - eq(S.encaseEither2.toString(), 'encaseEither2 :: (Error -> l) -> (a -> b -> r) -> a -> b -> Either l r'); + eq (typeof S.encaseEither2) ('function'); + eq (S.encaseEither2.length) (1); + eq (String (S.encaseEither2)) ('encaseEither2 :: (Error -> l) -> (a -> b -> r) -> a -> b -> Either l r'); - eq(S.encaseEither2(S.I, rem, 42, 5), S.Right(2)); - eq(S.encaseEither2(S.I, rem, 42, 0), S.Left(new Error('Cannot divide by zero'))); - eq(S.encaseEither2(S.prop('message'), rem, 42, 0), S.Left('Cannot divide by zero')); + eq (S.encaseEither2 (S.I) (rem) (42) (5)) (S.Right (2)); + eq (S.encaseEither2 (S.I) (rem) (42) (0)) (S.Left (new Error ('Cannot divide by zero'))); + eq (S.encaseEither2 (S.prop ('message')) (rem) (42) (0)) (S.Left ('Cannot divide by zero')); }); diff --git a/test/encaseEither3.js b/test/encaseEither3.js index 6486b137..445c1c84 100644 --- a/test/encaseEither3.js +++ b/test/encaseEither3.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var area = require('./internal/area'); -var eq = require('./internal/eq'); +var area = require ('./internal/area'); +var eq = require ('./internal/eq'); -test('encaseEither3', function() { +test ('encaseEither3', function() { - eq(typeof S.encaseEither3, 'function'); - eq(S.encaseEither3.length, 5); - eq(S.encaseEither3.toString(), 'encaseEither3 :: (Error -> l) -> (a -> b -> c -> r) -> a -> b -> c -> Either l r'); + eq (typeof S.encaseEither3) ('function'); + eq (S.encaseEither3.length) (1); + eq (String (S.encaseEither3)) ('encaseEither3 :: (Error -> l) -> (a -> b -> c -> r) -> a -> b -> c -> Either l r'); - eq(S.encaseEither3(S.I, area, 3, 4, 5), S.Right(6)); - eq(S.encaseEither3(S.I, area, 2, 2, 5), S.Left(new Error('Impossible triangle'))); - eq(S.encaseEither3(S.prop('message'), area, 2, 2, 5), S.Left('Impossible triangle')); + eq (S.encaseEither3 (S.I) (area) (3) (4) (5)) (S.Right (6)); + eq (S.encaseEither3 (S.I) (area) (2) (2) (5)) (S.Left (new Error ('Impossible triangle'))); + eq (S.encaseEither3 (S.prop ('message')) (area) (2) (2) (5)) (S.Left ('Impossible triangle')); }); diff --git a/test/env.js b/test/env.js index afe47453..e10ff923 100644 --- a/test/env.js +++ b/test/env.js @@ -1,15 +1,15 @@ 'use strict'; -var $ = require('sanctuary-def'); +var $ = require ('sanctuary-def'); -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('env', function() { +test ('env', function() { - eq(typeof S.env, 'object'); - eq($.test([], $.Array($.Type), S.env), true); + eq (typeof S.env) ('object'); + eq ($.test ([]) ($.Array ($.Type)) (S.env)) (true); }); diff --git a/test/equals.js b/test/equals.js index aa6cadea..8cfa00e7 100644 --- a/test/equals.js +++ b/test/equals.js @@ -1,28 +1,28 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('equals', function() { +test ('equals', function() { - eq(typeof S.equals, 'function'); - eq(S.equals.length, 2); - eq(S.equals.toString(), 'equals :: Setoid a => a -> a -> Boolean'); + eq (typeof S.equals) ('function'); + eq (S.equals.length) (1); + eq (String (S.equals)) ('equals :: Setoid a => a -> a -> Boolean'); - eq(S.equals(S.Nothing, S.Nothing), true); - eq(S.equals(S.Just(NaN), S.Just(NaN)), true); - eq(S.equals(S.Just(0), S.Just(-0)), true); - eq(S.equals(S.Nothing, S.Just(0)), false); - eq(S.equals(S.Just(0), S.Just(1)), false); + eq (S.equals (S.Nothing) (S.Nothing)) (true); + eq (S.equals (S.Just (NaN)) (S.Just (NaN))) (true); + eq (S.equals (S.Just (0)) (S.Just (-0))) (true); + eq (S.equals (S.Nothing) (S.Just (0))) (false); + eq (S.equals (S.Just (0)) (S.Just (1))) (false); - eq(S.equals(S.Left(NaN), S.Left(NaN)), true); - eq(S.equals(S.Left(0), S.Left(-0)), true); - eq(S.equals(S.Right(NaN), S.Right(NaN)), true); - eq(S.equals(S.Right(0), S.Right(-0)), true); - eq(S.equals(S.Left(10), S.Left(20)), false); - eq(S.equals(S.Left(10), S.Right(0)), false); - eq(S.equals(S.Right(0), S.Right(1)), false); + eq (S.equals (S.Left (NaN)) (S.Left (NaN))) (true); + eq (S.equals (S.Left (0)) (S.Left (-0))) (true); + eq (S.equals (S.Right (NaN)) (S.Right (NaN))) (true); + eq (S.equals (S.Right (0)) (S.Right (-0))) (true); + eq (S.equals (S.Left (10)) (S.Left (20))) (false); + eq (S.equals (S.Left (10)) (S.Right (0))) (false); + eq (S.equals (S.Right (0)) (S.Right (1))) (false); }); diff --git a/test/even.js b/test/even.js index 479cad5f..aef08887 100644 --- a/test/even.js +++ b/test/even.js @@ -1,21 +1,21 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('even', function() { +test ('even', function() { - eq(typeof S.even, 'function'); - eq(S.even.length, 1); - eq(S.even.toString(), 'even :: Integer -> Boolean'); + eq (typeof S.even) ('function'); + eq (S.even.length) (1); + eq (String (S.even)) ('even :: Integer -> Boolean'); - eq(S.even(0), true); - eq(S.even(2), true); - eq(S.even(-2), true); + eq (S.even (0)) (true); + eq (S.even (2)) (true); + eq (S.even (-2)) (true); - eq(S.even(1), false); - eq(S.even(-1), false); + eq (S.even (1)) (false); + eq (S.even (-1)) (false); }); diff --git a/test/extend.js b/test/extend.js index bcf50057..f0bb3e9c 100644 --- a/test/extend.js +++ b/test/extend.js @@ -1,22 +1,22 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var Identity = require('./internal/Identity'); -var eq = require('./internal/eq'); +var Identity = require ('./internal/Identity'); +var eq = require ('./internal/eq'); -test('extend', function() { +test ('extend', function() { - eq(typeof S.extend, 'function'); - eq(S.extend.length, 2); - eq(S.extend.toString(), 'extend :: Extend w => (w a -> b) -> w a -> w b'); + eq (typeof S.extend) ('function'); + eq (S.extend.length) (1); + eq (String (S.extend)) ('extend :: Extend w => (w a -> b) -> w a -> w b'); - eq(S.extend(S.joinWith(''), []), []); - eq(S.extend(S.joinWith(''), ['x']), ['x']); - eq(S.extend(S.joinWith(''), ['x', 'y']), ['xy', 'y']); - eq(S.extend(S.joinWith(''), ['x', 'y', 'z']), ['xyz', 'yz', 'z']); - eq(S.extend(S.reduce(S.add, 1), Identity(42)), Identity(43)); - eq(S.extend(S.T([3, 4]), S.reverse)([1, 2]), [4, 3, 2, 1]); + eq (S.extend (S.joinWith ('')) ([])) ([]); + eq (S.extend (S.joinWith ('')) (['x'])) (['x']); + eq (S.extend (S.joinWith ('')) (['x', 'y'])) (['xy', 'y']); + eq (S.extend (S.joinWith ('')) (['x', 'y', 'z'])) (['xyz', 'yz', 'z']); + eq (S.extend (S.reduce (S.add) (1)) (Identity (42))) (Identity (43)); + eq (S.extend (S.T ([3, 4])) (S.reverse) ([1, 2])) ([4, 3, 2, 1]); }); diff --git a/test/extract.js b/test/extract.js index 00252651..031da837 100644 --- a/test/extract.js +++ b/test/extract.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var Identity = require('./internal/Identity'); -var eq = require('./internal/eq'); +var Identity = require ('./internal/Identity'); +var eq = require ('./internal/eq'); -test('extract', function() { +test ('extract', function() { - eq(typeof S.extract, 'function'); - eq(S.extract.length, 1); - eq(S.extract.toString(), 'extract :: Comonad w => w a -> a'); + eq (typeof S.extract) ('function'); + eq (S.extract.length) (1); + eq (String (S.extract)) ('extract :: Comonad w => w a -> a'); - eq(S.extract(Identity(42)), 42); + eq (S.extract (Identity (42))) (42); }); diff --git a/test/filter.js b/test/filter.js index ca65a7fc..4d788203 100644 --- a/test/filter.js +++ b/test/filter.js @@ -1,38 +1,38 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var List = require('./internal/List'); -var eq = require('./internal/eq'); +var List = require ('./internal/List'); +var eq = require ('./internal/eq'); var Cons = List.Cons; var Nil = List.Nil; -test('filter', function() { +test ('filter', function() { - eq(typeof S.filter, 'function'); - eq(S.filter.length, 2); - eq(S.filter.toString(), 'filter :: Filterable f => (a -> Boolean) -> f a -> f a'); + eq (typeof S.filter) ('function'); + eq (S.filter.length) (1); + eq (String (S.filter)) ('filter :: Filterable f => (a -> Boolean) -> f a -> f a'); - eq(S.filter(S.odd, []), []); - eq(S.filter(S.odd, [0, 2, 4, 6, 8]), []); - eq(S.filter(S.odd, [1, 3, 5, 7, 9]), [1, 3, 5, 7, 9]); - eq(S.filter(S.odd, [1, 2, 3, 4, 5]), [1, 3, 5]); + eq (S.filter (S.odd) ([])) ([]); + eq (S.filter (S.odd) ([0, 2, 4, 6, 8])) ([]); + eq (S.filter (S.odd) ([1, 3, 5, 7, 9])) ([1, 3, 5, 7, 9]); + eq (S.filter (S.odd) ([1, 2, 3, 4, 5])) ([1, 3, 5]); - eq(S.filter(S.odd, {}), {}); - eq(S.filter(S.odd, {x: 1}), {x: 1}); - eq(S.filter(S.odd, {x: 1, y: 2}), {x: 1}); - eq(S.filter(S.odd, {x: 1, y: 2, z: 3}), {x: 1, z: 3}); + eq (S.filter (S.odd) ({})) ({}); + eq (S.filter (S.odd) ({x: 1})) ({x: 1}); + eq (S.filter (S.odd) ({x: 1, y: 2})) ({x: 1}); + eq (S.filter (S.odd) ({x: 1, y: 2, z: 3})) ({x: 1, z: 3}); - eq(S.filter(S.odd, S.Nothing), S.Nothing); - eq(S.filter(S.odd, S.Just(0)), S.Nothing); - eq(S.filter(S.odd, S.Just(1)), S.Just(1)); + eq (S.filter (S.odd) (S.Nothing)) (S.Nothing); + eq (S.filter (S.odd) (S.Just (0))) (S.Nothing); + eq (S.filter (S.odd) (S.Just (1))) (S.Just (1)); - eq(S.filter(S.odd, Nil), Nil); - eq(S.filter(S.odd, Cons(1, Nil)), Cons(1, Nil)); - eq(S.filter(S.odd, Cons(1, Cons(2, Nil))), Cons(1, Nil)); - eq(S.filter(S.odd, Cons(1, Cons(2, Cons(3, Nil)))), Cons(1, Cons(3, Nil))); + eq (S.filter (S.odd) (Nil)) (Nil); + eq (S.filter (S.odd) (Cons (1) (Nil))) (Cons (1) (Nil)); + eq (S.filter (S.odd) (Cons (1) (Cons (2) (Nil)))) (Cons (1) (Nil)); + eq (S.filter (S.odd) (Cons (1) (Cons (2) (Cons (3) (Nil))))) (Cons (1) (Cons (3) (Nil))); }); diff --git a/test/find.js b/test/find.js index 706726ad..e8bcefbc 100644 --- a/test/find.js +++ b/test/find.js @@ -1,22 +1,22 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('find', function() { +test ('find', function() { - eq(typeof S.find, 'function'); - eq(S.find.length, 2); - eq(S.find.toString(), 'find :: Foldable f => (a -> Boolean) -> f a -> Maybe a'); + eq (typeof S.find) ('function'); + eq (S.find.length) (1); + eq (String (S.find)) ('find :: Foldable f => (a -> Boolean) -> f a -> Maybe a'); - eq(S.find(S.even, []), S.Nothing); - eq(S.find(S.even, [1, 3, 5, 7, 9]), S.Nothing); - eq(S.find(S.even, [1, 2, 3, 4, 5]), S.Just(2)); - eq(S.find(S.even, {}), S.Nothing); - eq(S.find(S.even, {a: 1, b: 3, c: 5, d: 7, e: 9}), S.Nothing); - eq(S.find(S.even, {a: 1, b: 2, c: 3, d: 4, e: 5}), S.Just(2)); - eq(S.find(S.even, {e: 5, d: 4, c: 3, b: 2, a: 1}), S.Just(2)); + eq (S.find (S.even) ([])) (S.Nothing); + eq (S.find (S.even) ([1, 3, 5, 7, 9])) (S.Nothing); + eq (S.find (S.even) ([1, 2, 3, 4, 5])) (S.Just (2)); + eq (S.find (S.even) ({})) (S.Nothing); + eq (S.find (S.even) ({a: 1, b: 3, c: 5, d: 7, e: 9})) (S.Nothing); + eq (S.find (S.even) ({a: 1, b: 2, c: 3, d: 4, e: 5})) (S.Just (2)); + eq (S.find (S.even) ({e: 5, d: 4, c: 3, b: 2, a: 1})) (S.Just (2)); }); diff --git a/test/flip.js b/test/flip.js index 1bef6b89..4de57469 100644 --- a/test/flip.js +++ b/test/flip.js @@ -1,18 +1,18 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var map = require('./internal/map'); +var eq = require ('./internal/eq'); +var map = require ('./internal/map'); -test('flip', function() { +test ('flip', function() { - eq(typeof S.flip, 'function'); - eq(S.flip.length, 3); - eq(S.flip.toString(), 'flip :: (a -> b -> c) -> b -> a -> c'); + eq (typeof S.flip) ('function'); + eq (S.flip.length) (1); + eq (String (S.flip)) ('flip :: (a -> b -> c) -> b -> a -> c'); - eq(S.flip(S.concat, 'foo', 'bar'), 'barfoo'); - eq(map(S.flip(S.concat, '!'))(['BAM', 'POW', 'KA-POW']), ['BAM!', 'POW!', 'KA-POW!']); + eq (S.flip (S.concat) ('foo') ('bar')) ('barfoo'); + eq (map (S.flip (S.concat) ('!')) (['BAM', 'POW', 'KA-POW'])) (['BAM!', 'POW!', 'KA-POW!']); }); diff --git a/test/fromEither.js b/test/fromEither.js index f1baaea2..6ea514a6 100644 --- a/test/fromEither.js +++ b/test/fromEither.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('fromEither', function() { +test ('fromEither', function() { - eq(typeof S.fromEither, 'function'); - eq(S.fromEither.length, 2); - eq(S.fromEither.toString(), 'fromEither :: b -> Either a b -> b'); + eq (typeof S.fromEither) ('function'); + eq (S.fromEither.length) (1); + eq (String (S.fromEither)) ('fromEither :: b -> Either a b -> b'); - eq(S.fromEither(0, S.Left(42)), 0); - eq(S.fromEither(0, S.Right(42)), 42); + eq (S.fromEither (0) (S.Left (42))) (0); + eq (S.fromEither (0) (S.Right (42))) (42); }); diff --git a/test/fromMaybe.js b/test/fromMaybe.js index deccd60c..34285944 100644 --- a/test/fromMaybe.js +++ b/test/fromMaybe.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('fromMaybe', function() { +test ('fromMaybe', function() { - eq(typeof S.fromMaybe, 'function'); - eq(S.fromMaybe.length, 2); - eq(S.fromMaybe.toString(), 'fromMaybe :: a -> Maybe a -> a'); + eq (typeof S.fromMaybe) ('function'); + eq (S.fromMaybe.length) (1); + eq (String (S.fromMaybe)) ('fromMaybe :: a -> Maybe a -> a'); - eq(S.fromMaybe(0, S.Nothing), 0); - eq(S.fromMaybe(0, S.Just(42)), 42); + eq (S.fromMaybe (0) (S.Nothing)) (0); + eq (S.fromMaybe (0) (S.Just (42))) (42); }); diff --git a/test/fromMaybe_.js b/test/fromMaybe_.js index 592a3bc1..f0b2752c 100644 --- a/test/fromMaybe_.js +++ b/test/fromMaybe_.js @@ -1,21 +1,21 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('fromMaybe_', function() { +test ('fromMaybe_', function() { - eq(typeof S.fromMaybe_, 'function'); - eq(S.fromMaybe_.length, 2); - eq(S.fromMaybe_.toString(), 'fromMaybe_ :: (() -> a) -> Maybe a -> a'); + eq (typeof S.fromMaybe_) ('function'); + eq (S.fromMaybe_.length) (1); + eq (String (S.fromMaybe_)) ('fromMaybe_ :: (() -> a) -> Maybe a -> a'); - eq(S.fromMaybe_(function() { return 0; }, S.Nothing), 0); - eq(S.fromMaybe_(function() { return 0; }, S.Just(42)), 42); + eq (S.fromMaybe_ (function() { return 0; }) (S.Nothing)) (0); + eq (S.fromMaybe_ (function() { return 0; }) (S.Just (42))) (42); var count = 0; - eq(S.fromMaybe_(function() { return count += 1; }, S.Just(42)), 42); - eq(count, 0); + eq (S.fromMaybe_ (function() { return count += 1; }) (S.Just (42))) (42); + eq (count) (0); }); diff --git a/test/fromPairs.js b/test/fromPairs.js index 790075a3..0892244b 100644 --- a/test/fromPairs.js +++ b/test/fromPairs.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('fromPairs', function() { +test ('fromPairs', function() { - eq(typeof S.fromPairs, 'function'); - eq(S.fromPairs.length, 1); - eq(S.fromPairs.toString(), 'fromPairs :: Foldable f => f (Pair String a) -> StrMap a'); + eq (typeof S.fromPairs) ('function'); + eq (S.fromPairs.length) (1); + eq (String (S.fromPairs)) ('fromPairs :: Foldable f => f (Array2 String a) -> StrMap a'); - eq(S.fromPairs([]), {}); - eq(S.fromPairs([['a', 1], ['b', 2], ['c', 3]]), {a: 1, b: 2, c: 3}); - eq(S.fromPairs({x: ['a', 1], y: ['b', 2], z: ['c', 3]}), {a: 1, b: 2, c: 3}); - eq(S.fromPairs([['x', 1], ['x', 2]]), {x: 2}); + eq (S.fromPairs ([])) ({}); + eq (S.fromPairs ([['a', 1], ['b', 2], ['c', 3]])) ({a: 1, b: 2, c: 3}); + eq (S.fromPairs ({x: ['a', 1], y: ['b', 2], z: ['c', 3]})) ({a: 1, b: 2, c: 3}); + eq (S.fromPairs ([['x', 1], ['x', 2]])) ({x: 2}); }); diff --git a/test/get.js b/test/get.js index 6d22a5dd..417448b9 100644 --- a/test/get.js +++ b/test/get.js @@ -1,31 +1,31 @@ 'use strict'; -var vm = require('vm'); +var vm = require ('vm'); -var $ = require('sanctuary-def'); +var $ = require ('sanctuary-def'); -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('get', function() { +test ('get', function() { - eq(typeof S.get, 'function'); - eq(S.get.length, 3); - eq(S.get.toString(), 'get :: (Any -> Boolean) -> String -> a -> Maybe b'); + eq (typeof S.get) ('function'); + eq (S.get.length) (1); + eq (String (S.get)) ('get :: (Any -> Boolean) -> String -> a -> Maybe b'); - eq(S.get(S.is($.Number), 'x', {x: 0, y: 42}), S.Just(0)); - eq(S.get(S.is($.Number), 'y', {x: 0, y: 42}), S.Just(42)); - eq(S.get(S.is($.Number), 'z', {x: 0, y: 42}), S.Nothing); - eq(S.get(S.is($.String), 'z', {x: 0, y: 42}), S.Nothing); - eq(S.get(S.is($.String), 'x', {x: 0, y: 42}), S.Nothing); - eq(S.get(S.is($.RegExp), 'x', {x: vm.runInNewContext('/.*/')}), S.Just(/.*/)); + eq (S.get (S.is ($.Number)) ('x') ({x: 0, y: 42})) (S.Just (0)); + eq (S.get (S.is ($.Number)) ('y') ({x: 0, y: 42})) (S.Just (42)); + eq (S.get (S.is ($.Number)) ('z') ({x: 0, y: 42})) (S.Nothing); + eq (S.get (S.is ($.String)) ('z') ({x: 0, y: 42})) (S.Nothing); + eq (S.get (S.is ($.String)) ('x') ({x: 0, y: 42})) (S.Nothing); + eq (S.get (S.is ($.RegExp)) ('x') ({x: vm.runInNewContext ('/.*/')})) (S.Just (/.*/)); - eq(S.get(S.K(true), 'valueOf', null), S.Nothing); - eq(S.get(S.K(true), 'valueOf', undefined), S.Nothing); + eq (S.get (S.K (true)) ('valueOf') (null)) (S.Nothing); + eq (S.get (S.K (true)) ('valueOf') (undefined)) (S.Nothing); - eq(S.get(S.is($.Array($.Number)), 'x', {x: [1, 2]}), S.Just([1, 2])); - eq(S.get(S.is($.Array($.Number)), 'x', {x: [1, 2, null]}), S.Nothing); + eq (S.get (S.is ($.Array ($.Number))) ('x') ({x: [1, 2]})) (S.Just ([1, 2])); + eq (S.get (S.is ($.Array ($.Number))) ('x') ({x: [1, 2, null]})) (S.Nothing); }); diff --git a/test/gets.js b/test/gets.js index 232b764c..33052eed 100644 --- a/test/gets.js +++ b/test/gets.js @@ -1,33 +1,33 @@ 'use strict'; -var vm = require('vm'); +var vm = require ('vm'); -var $ = require('sanctuary-def'); +var $ = require ('sanctuary-def'); -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('gets', function() { +test ('gets', function() { - eq(typeof S.gets, 'function'); - eq(S.gets.length, 3); - eq(S.gets.toString(), 'gets :: (Any -> Boolean) -> Array String -> a -> Maybe b'); + eq (typeof S.gets) ('function'); + eq (S.gets.length) (1); + eq (String (S.gets)) ('gets :: (Any -> Boolean) -> Array String -> a -> Maybe b'); - eq(S.gets(S.is($.Number), ['x'], {x: {z: 0}, y: 42}), S.Nothing); - eq(S.gets(S.is($.Number), ['y'], {x: {z: 0}, y: 42}), S.Just(42)); - eq(S.gets(S.is($.Number), ['z'], {x: {z: 0}, y: 42}), S.Nothing); - eq(S.gets(S.is($.Number), ['x', 'z'], {x: {z: 0}, y: 42}), S.Just(0)); - eq(S.gets(S.is($.Number), ['a', 'b', 'c'], {x: {z: 0}, y: 42}), S.Nothing); - eq(S.gets(S.is($.Number), [], {x: {z: 0}, y: 42}), S.Nothing); - eq(S.gets(S.is($.Object), [], {x: {z: 0}, y: 42}), S.Just({x: {z: 0}, y: 42})); - eq(S.gets(S.is($.RegExp), ['x'], {x: vm.runInNewContext('/.*/')}), S.Just(/.*/)); + eq (S.gets (S.is ($.Number)) (['x']) ({x: {z: 0}, y: 42})) (S.Nothing); + eq (S.gets (S.is ($.Number)) (['y']) ({x: {z: 0}, y: 42})) (S.Just (42)); + eq (S.gets (S.is ($.Number)) (['z']) ({x: {z: 0}, y: 42})) (S.Nothing); + eq (S.gets (S.is ($.Number)) (['x', 'z']) ({x: {z: 0}, y: 42})) (S.Just (0)); + eq (S.gets (S.is ($.Number)) (['a', 'b', 'c']) ({x: {z: 0}, y: 42})) (S.Nothing); + eq (S.gets (S.is ($.Number)) ([]) ({x: {z: 0}, y: 42})) (S.Nothing); + eq (S.gets (S.is ($.Object)) ([]) ({x: {z: 0}, y: 42})) (S.Just ({x: {z: 0}, y: 42})); + eq (S.gets (S.is ($.RegExp)) (['x']) ({x: vm.runInNewContext ('/.*/')})) (S.Just (/.*/)); - eq(S.gets(S.K(true), ['valueOf'], null), S.Nothing); - eq(S.gets(S.K(true), ['valueOf'], undefined), S.Nothing); + eq (S.gets (S.K (true)) (['valueOf']) (null)) (S.Nothing); + eq (S.gets (S.K (true)) (['valueOf']) (undefined)) (S.Nothing); - eq(S.gets(S.is($.Array($.Number)), ['x'], {x: [1, 2]}), S.Just([1, 2])); - eq(S.gets(S.is($.Array($.Number)), ['x'], {x: [1, 2, null]}), S.Nothing); + eq (S.gets (S.is ($.Array ($.Number))) (['x']) ({x: [1, 2]})) (S.Just ([1, 2])); + eq (S.gets (S.is ($.Array ($.Number))) (['x']) ({x: [1, 2, null]})) (S.Nothing); }); diff --git a/test/groupBy.js b/test/groupBy.js index da7b783de..b32d6fbf 100644 --- a/test/groupBy.js +++ b/test/groupBy.js @@ -1,18 +1,18 @@ 'use strict'; -var jsc = require('jsverify'); +var jsc = require ('jsverify'); -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var equals = require('./internal/equals'); +var eq = require ('./internal/eq'); +var equals = require ('./internal/equals'); -test('groupBy', function() { +test ('groupBy', function() { - eq(typeof S.groupBy, 'function'); - eq(S.groupBy.length, 2); - eq(S.groupBy.toString(), 'groupBy :: (a -> a -> Boolean) -> Array a -> Array (Array a)'); + eq (typeof S.groupBy) ('function'); + eq (S.groupBy.length) (1); + eq (String (S.groupBy)) ('groupBy :: (a -> a -> Boolean) -> Array a -> Array (Array a)'); function productsOf3(x) { return function(y) { @@ -26,15 +26,15 @@ test('groupBy', function() { }; } - eq(S.groupBy(productsOf3, []), []); - eq(S.groupBy(productsOf3, [1, 2, 3, 4, 5, 6, 7, 8, 9]), [[1], [2, 3], [4], [5, 6], [7], [8, 9]]); - eq(S.groupBy(equals, [1, 1, 2, 1, 1]), [[1, 1], [2], [1, 1]]); - eq(S.groupBy(zeroSum, [2, -3, 3, 3, 3, 4, -4, 4]), [[2], [-3, 3, 3, 3], [4, -4], [4]]); + eq (S.groupBy (productsOf3) ([])) ([]); + eq (S.groupBy (productsOf3) ([1, 2, 3, 4, 5, 6, 7, 8, 9])) ([[1], [2, 3], [4], [5, 6], [7], [8, 9]]); + eq (S.groupBy (equals) ([1, 1, 2, 1, 1])) ([[1, 1], [2], [1, 1]]); + eq (S.groupBy (zeroSum) ([2, -3, 3, 3, 3, 4, -4, 4])) ([[2], [-3, 3, 3, 3], [4, -4], [4]]); - jsc.assert(jsc.forall('nat -> nat -> bool', 'array nat', function(f, xs) { - var lhs = S.join(S.groupBy(f, xs)); + jsc.assert (jsc.forall ('nat -> nat -> bool', 'array nat', function(f, xs) { + var lhs = S.join (S.groupBy (f) (xs)); var rhs = xs; - return equals(lhs)(rhs); + return equals (lhs) (rhs); }), {tests: 1000}); }); diff --git a/test/gt.js b/test/gt.js index b9513209..798273ef 100644 --- a/test/gt.js +++ b/test/gt.js @@ -1,16 +1,16 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('gt', function() { +test ('gt', function() { - eq(typeof S.gt, 'function'); - eq(S.gt.length, 1); - eq(S.gt.toString(), 'gt :: Ord a => a -> (a -> Boolean)'); + eq (typeof S.gt) ('function'); + eq (S.gt.length) (1); + eq (String (S.gt)) ('gt :: Ord a => a -> a -> Boolean'); - eq(S.filter(S.gt(3), [1, 2, 3, 4, 5]), [4, 5]); + eq (S.filter (S.gt (3)) ([1, 2, 3, 4, 5])) ([4, 5]); }); diff --git a/test/gte.js b/test/gte.js index 5b0c3590..34bbbb3a 100644 --- a/test/gte.js +++ b/test/gte.js @@ -1,16 +1,16 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('gte', function() { +test ('gte', function() { - eq(typeof S.gte, 'function'); - eq(S.gte.length, 1); - eq(S.gte.toString(), 'gte :: Ord a => a -> (a -> Boolean)'); + eq (typeof S.gte) ('function'); + eq (S.gte.length) (1); + eq (String (S.gte)) ('gte :: Ord a => a -> a -> Boolean'); - eq(S.filter(S.gte(3), [1, 2, 3, 4, 5]), [3, 4, 5]); + eq (S.filter (S.gte (3)) ([1, 2, 3, 4, 5])) ([3, 4, 5]); }); diff --git a/test/head.js b/test/head.js index 729d6be4..f7544274 100644 --- a/test/head.js +++ b/test/head.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('head', function() { +test ('head', function() { - eq(typeof S.head, 'function'); - eq(S.head.length, 1); - eq(S.head.toString(), 'head :: Array a -> Maybe a'); + eq (typeof S.head) ('function'); + eq (S.head.length) (1); + eq (String (S.head)) ('head :: Array a -> Maybe a'); - eq(S.head([]), S.Nothing); - eq(S.head(['foo']), S.Just('foo')); - eq(S.head(['foo', 'bar']), S.Just('foo')); - eq(S.head(['foo', 'bar', 'baz']), S.Just('foo')); + eq (S.head ([])) (S.Nothing); + eq (S.head (['foo'])) (S.Just ('foo')); + eq (S.head (['foo', 'bar'])) (S.Just ('foo')); + eq (S.head (['foo', 'bar', 'baz'])) (S.Just ('foo')); }); diff --git a/test/id.js b/test/id.js index 5444d5bd..d593eb83 100644 --- a/test/id.js +++ b/test/id.js @@ -1,16 +1,16 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('id', function() { +test ('id', function() { - eq(typeof S.id, 'function'); - eq(S.id.length, 1); - eq(S.id.toString(), 'id :: Category c => TypeRep c -> c'); + eq (typeof S.id) ('function'); + eq (S.id.length) (1); + eq (String (S.id)) ('id :: Category c => TypeRep c -> c'); - eq(S.id(Function)(42), 42); + eq (S.id (Function) (42)) (42); }); diff --git a/test/ifElse.js b/test/ifElse.js index e0854791..01705e64 100644 --- a/test/ifElse.js +++ b/test/ifElse.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('ifElse', function() { +test ('ifElse', function() { - eq(typeof S.ifElse, 'function'); - eq(S.ifElse.length, 4); - eq(S.ifElse.toString(), 'ifElse :: (a -> Boolean) -> (a -> b) -> (a -> b) -> a -> b'); + eq (typeof S.ifElse) ('function'); + eq (S.ifElse.length) (1); + eq (String (S.ifElse)) ('ifElse :: (a -> Boolean) -> (a -> b) -> (a -> b) -> a -> b'); - eq(S.ifElse(S.odd, S.sub(1), S.add(1), 9), 8); - eq(S.ifElse(S.odd, S.sub(1), S.add(1), 0), 1); + eq (S.ifElse (S.odd) (S.sub (1)) (S.add (1)) (9)) (8); + eq (S.ifElse (S.odd) (S.sub (1)) (S.add (1)) (0)) (1); }); diff --git a/test/init.js b/test/init.js index 4b97fe20..c95afcd6 100644 --- a/test/init.js +++ b/test/init.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('init', function() { +test ('init', function() { - eq(typeof S.init, 'function'); - eq(S.init.length, 1); - eq(S.init.toString(), 'init :: Array a -> Maybe (Array a)'); + eq (typeof S.init) ('function'); + eq (S.init.length) (1); + eq (String (S.init)) ('init :: Array a -> Maybe (Array a)'); - eq(S.init([]), S.Nothing); - eq(S.init(['foo']), S.Just([])); - eq(S.init(['foo', 'bar']), S.Just(['foo'])); - eq(S.init(['foo', 'bar', 'baz']), S.Just(['foo', 'bar'])); + eq (S.init ([])) (S.Nothing); + eq (S.init (['foo'])) (S.Just ([])); + eq (S.init (['foo', 'bar'])) (S.Just (['foo'])); + eq (S.init (['foo', 'bar', 'baz'])) (S.Just (['foo', 'bar'])); }); diff --git a/test/insert.js b/test/insert.js index 6c949da3..9e2039cc 100644 --- a/test/insert.js +++ b/test/insert.js @@ -1,28 +1,28 @@ 'use strict'; -var jsc = require('jsverify'); +var jsc = require ('jsverify'); -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var equals = require('./internal/equals'); +var eq = require ('./internal/eq'); +var equals = require ('./internal/equals'); -test('insert', function() { +test ('insert', function() { - eq(typeof S.insert, 'function'); - eq(S.insert.length, 3); - eq(S.insert.toString(), 'insert :: String -> a -> StrMap a -> StrMap a'); + eq (typeof S.insert) ('function'); + eq (S.insert.length) (1); + eq (String (S.insert)) ('insert :: String -> a -> StrMap a -> StrMap a'); - eq(S.insert('a', 1, {}), {a: 1}); - eq(S.insert('b', 2, {a: 1}), {a: 1, b: 2}); - eq(S.insert('c', 3, {a: 1, b: 2, c: 4}), {a: 1, b: 2, c: 3}); + eq (S.insert ('a') (1) ({})) ({a: 1}); + eq (S.insert ('b') (2) ({a: 1})) ({a: 1, b: 2}); + eq (S.insert ('c') (3) ({a: 1, b: 2, c: 4})) ({a: 1, b: 2, c: 3}); - jsc.assert(jsc.forall(jsc.string, jsc.number, jsc.dict(jsc.number), function(key, val, map) { - var insert = S.insert(key, val); - var lhs = insert(insert(map)); - var rhs = insert(map); - return equals(lhs)(rhs); + jsc.assert (jsc.forall (jsc.string, jsc.number, jsc.dict (jsc.number), function(key, val, map) { + var insert = S.insert (key) (val); + var lhs = insert (insert (map)); + var rhs = insert (map); + return equals (lhs) (rhs); }), {tests: 1000}); }); diff --git a/test/internal/$.js b/test/internal/$.js index 7fac9a84..2ce99535 100644 --- a/test/internal/$.js +++ b/test/internal/$.js @@ -3,6 +3,6 @@ // $ :: a -> (a -> b) -> b module.exports = function $(x) { return function(f) { - return f(x); + return f (x); }; }; diff --git a/test/internal/Compose.js b/test/internal/Compose.js index 0b40b850..7ddee132 100644 --- a/test/internal/Compose.js +++ b/test/internal/Compose.js @@ -1,52 +1,52 @@ 'use strict'; -var FL = require('fantasy-land'); +var FL = require ('fantasy-land'); -var ap = require('./ap'); -var equals = require('./equals'); -var map = require('./map'); -var of = require('./of'); -var toString = require('./toString'); +var ap = require ('./ap'); +var equals = require ('./equals'); +var map = require ('./map'); +var of = require ('./of'); +var toString = require ('./toString'); // Compose :: (Apply f, Apply g) => TypeRep f -> TypeRep g -> f (g a) -> Compose f g a module.exports = function Compose(F) { return function ComposeF(G) { function ComposeFG(value) { - if (!(this instanceof ComposeFG)) return new ComposeFG(value); + if (!(this instanceof ComposeFG)) return new ComposeFG (value); this.value = value; } ComposeFG['@@type'] = 'sanctuary/Compose'; ComposeFG[FL.of] = function(x) { - return ComposeFG(of(F)(of(G)(x))); + return ComposeFG (of (F) (of (G) (x))); }; ComposeFG.prototype[FL.equals] = function(other) { - return equals(this.value)(other.value); + return equals (this.value) (other.value); }; ComposeFG.prototype[FL.map] = function(f) { - return ComposeFG(map(map(f))(this.value)); + return ComposeFG (map (map (f)) (this.value)); }; ComposeFG.prototype[FL.ap] = function(other) { - return ComposeFG(ap(map(ap)(other.value))(this.value)); + return ComposeFG (ap (map (ap) (other.value)) (this.value)); }; // name :: TypeRep a -> String function name(typeRep) { return typeof typeRep['@@type'] === 'string' ? - typeRep['@@type'].replace(/^[^/]*[/]/, '') : + typeRep['@@type'].replace (/^[^/]*[/]/, '') : typeRep.name; } ComposeFG.prototype.inspect = ComposeFG.prototype.toString = function() { - return 'Compose(' + name(F) + ')' + - '(' + name(G) + ')' + - '(' + toString(this.value) + ')'; + return 'Compose(' + name (F) + ')' + + '(' + name (G) + ')' + + '(' + toString (this.value) + ')'; }; return ComposeFG; diff --git a/test/internal/EitherArb.js b/test/internal/EitherArb.js index b732aac6..baa84110 100644 --- a/test/internal/EitherArb.js +++ b/test/internal/EitherArb.js @@ -1,14 +1,14 @@ 'use strict'; -var jsc = require('jsverify'); +var jsc = require ('jsverify'); -var S = require('./sanctuary'); +var S = require ('./sanctuary'); -var toString = require('./toString'); +var toString = require ('./toString'); // EitherArb :: Arbitrary a -> Arbitrary b -> Arbitrary (Either a b) module.exports = function EitherArb(lArb, rArb) { - return jsc.oneof(lArb.smap(S.Left, S.prop('value'), toString), - rArb.smap(S.Right, S.prop('value'), toString)); + return jsc.oneof (lArb.smap (S.Left, S.prop ('value'), toString), + rArb.smap (S.Right, S.prop ('value'), toString)); }; diff --git a/test/internal/Identity.js b/test/internal/Identity.js index 84d08227..d7b14310 100644 --- a/test/internal/Identity.js +++ b/test/internal/Identity.js @@ -1,16 +1,16 @@ 'use strict'; -var FL = require('fantasy-land'); +var FL = require ('fantasy-land'); -var concat = require('./concat'); -var equals = require('./equals'); -var map = require('./map'); -var toString = require('./toString'); +var concat = require ('./concat'); +var equals = require ('./equals'); +var map = require ('./map'); +var toString = require ('./toString'); // Identity :: a -> Identity a function Identity(value) { - if (!(this instanceof Identity)) return new Identity(value); + if (!(this instanceof Identity)) return new Identity (value); this.value = value; } @@ -19,35 +19,35 @@ Identity['@@type'] = 'sanctuary/Identity'; Identity[FL.of] = Identity; Identity.prototype[FL.equals] = function(other) { - return equals(this.value)(other.value); + return equals (this.value) (other.value); }; Identity.prototype[FL.concat] = function(other) { - return Identity(concat(this.value)(other.value)); + return Identity (concat (this.value) (other.value)); }; Identity.prototype[FL.map] = function(f) { - return Identity(f(this.value)); + return Identity (f (this.value)); }; Identity.prototype[FL.ap] = function(other) { - return map(other.value)(this); + return map (other.value) (this); }; Identity.prototype[FL.chain] = function(f) { - return f(this.value); + return f (this.value); }; Identity.prototype[FL.reduce] = function(f, x) { - return f(x, this.value); + return f (x, this.value); }; Identity.prototype[FL.traverse] = function(typeRep, f) { - return map(Identity)(f(this.value)); + return map (Identity) (f (this.value)); }; Identity.prototype[FL.extend] = function(f) { - return Identity(f(this)); + return Identity (f (this)); }; Identity.prototype[FL.extract] = function() { @@ -56,7 +56,7 @@ Identity.prototype[FL.extract] = function() { Identity.prototype.inspect = Identity.prototype.toString = function() { - return 'Identity(' + toString(this.value) + ')'; + return 'Identity(' + toString (this.value) + ')'; }; module.exports = Identity; diff --git a/test/internal/IdentityArb.js b/test/internal/IdentityArb.js index 4d28b0af..45870ca7 100644 --- a/test/internal/IdentityArb.js +++ b/test/internal/IdentityArb.js @@ -1,12 +1,12 @@ 'use strict'; -var S = require('./sanctuary'); +var S = require ('./sanctuary'); -var Identity = require('./Identity'); -var toString = require('./toString'); +var Identity = require ('./Identity'); +var toString = require ('./toString'); // IdentityArb :: Arbitrary a -> Arbitrary (Identity a) module.exports = function IdentityArb(arb) { - return arb.smap(Identity, S.prop('value'), toString); + return arb.smap (Identity, S.prop ('value'), toString); }; diff --git a/test/internal/List.js b/test/internal/List.js index 30441eed..e1712e2f 100644 --- a/test/internal/List.js +++ b/test/internal/List.js @@ -1,12 +1,11 @@ 'use strict'; -var FL = require('fantasy-land'); -var $ = require('sanctuary-def'); -var Z = require('sanctuary-type-classes'); -var type = require('sanctuary-type-identifiers'); +var FL = require ('fantasy-land'); +var $ = require ('sanctuary-def'); +var Z = require ('sanctuary-type-classes'); +var type = require ('sanctuary-type-identifiers'); -var curry2 = require('./curry2'); -var eq = require('./eq'); +var eq = require ('./eq'); var List = {prototype: _List.prototype}; @@ -25,27 +24,29 @@ function _List(tag, head, tail) { List['@@type'] = 'sanctuary/List'; // Type :: Type -> Type -List.Type = $.UnaryType( - List['@@type'], - '', - function(x) { return type(x) === List['@@type']; }, - function(list) { - return Z.reduce(function(xs, x) { xs.push(x); return xs; }, [], list); - } -); +List.Type = $.UnaryType + (List['@@type']) + ('') + (function(x) { return type (x) === List['@@type']; }) + (function(list) { + return Z.reduce (function(xs, x) { xs.push (x); return xs; }, [], list); + }); // Nil :: List a -var Nil = List.Nil = new _List('Nil'); - -// Cons :: (a, List a) -> List a -var Cons = List.Cons = function Cons(head, tail) { - eq(arguments.length, Cons.length); - return new _List('Cons', head, tail); +var Nil = List.Nil = new _List ('Nil'); + +// Cons :: a -> List a -> List a +var Cons = List.Cons = function Cons(head) { + eq (arguments.length) (Cons.length); + return function Cons$1(tail) { + eq (arguments.length) (Cons$1.length); + return new _List ('Cons', head, tail); + }; }; List[FL.empty] = function() { return Nil; }; -List[FL.of] = function(x) { return Cons(x, Nil); }; +List[FL.of] = function(x) { return Cons (x) (Nil); }; List[FL.zero] = List[FL.empty]; @@ -53,40 +54,40 @@ List.prototype[FL.equals] = function(other) { return this.isNil ? other.isNil : other.isCons && - Z.equals(other.head, this.head) && - Z.equals(other.tail, this.tail); + Z.equals (other.head, this.head) && + Z.equals (other.tail, this.tail); }; List.prototype[FL.concat] = function(other) { return this.isNil ? other : - Cons(this.head, Z.concat(this.tail, other)); + Cons (this.head) (Z.concat (this.tail, other)); }; List.prototype[FL.filter] = function(pred) { return this.isNil ? Nil : - pred(this.head) ? - Cons(this.head, Z.filter(pred, this.tail)) : - Z.filter(pred, this.tail); + pred (this.head) ? + Cons (this.head) (Z.filter (pred, this.tail)) : + Z.filter (pred, this.tail); }; List.prototype[FL.map] = function(f) { return this.isNil ? Nil : - Cons(f(this.head), Z.map(f, this.tail)); + Cons (f (this.head)) (Z.map (f, this.tail)); }; List.prototype[FL.ap] = function(other) { return this.isNil || other.isNil ? Nil : - Z.concat(Z.map(other.head, this), Z.ap(other.tail, this)); + Z.concat (Z.map (other.head, this), Z.ap (other.tail, this)); }; List.prototype[FL.chain] = function(f) { return this.isNil ? Nil : - Z.concat(f(this.head), Z.chain(f, this.tail)); + Z.concat (f (this.head), Z.chain (f, this.tail)); }; List.prototype[FL.alt] = List.prototype[FL.concat]; @@ -94,20 +95,20 @@ List.prototype[FL.alt] = List.prototype[FL.concat]; List.prototype[FL.reduce] = function(f, x) { return this.isNil ? x : - Z.reduce(f, f(x, this.head), this.tail); + Z.reduce (f, f (x, this.head), this.tail); }; List.prototype[FL.traverse] = function(typeRep, f) { return this.isNil ? - Z.of(typeRep, Nil) : - Z.ap(Z.map(curry2(Cons), f(this.head)), Z.traverse(typeRep, f, this.tail)); + Z.of (typeRep, Nil) : + Z.ap (Z.map (Cons, f (this.head)), Z.traverse (typeRep, f, this.tail)); }; List.prototype.inspect = List.prototype.toString = function() { return this.isNil ? 'Nil' : - 'Cons(' + Z.toString(this.head) + ', ' + Z.toString(this.tail) + ')'; + 'Cons (' + Z.toString (this.head) + ') (' + Z.toString (this.tail) + ')'; }; module.exports = List; diff --git a/test/internal/MaybeArb.js b/test/internal/MaybeArb.js index 79e065ca..fe825bb1 100644 --- a/test/internal/MaybeArb.js +++ b/test/internal/MaybeArb.js @@ -1,14 +1,14 @@ 'use strict'; -var jsc = require('jsverify'); +var jsc = require ('jsverify'); -var S = require('./sanctuary'); +var S = require ('./sanctuary'); -var toString = require('./toString'); +var toString = require ('./toString'); // MaybeArb :: Arbitrary a -> Arbitrary (Maybe a) module.exports = function MaybeArb(arb) { - return jsc.oneof(arb.smap(S.Just, S.prop('value'), toString), - jsc.constant(S.Nothing)); + return jsc.oneof (arb.smap (S.Just, S.prop ('value'), toString), + jsc.constant (S.Nothing)); }; diff --git a/test/internal/Sum.js b/test/internal/Sum.js index 73b68522..7054b02e 100644 --- a/test/internal/Sum.js +++ b/test/internal/Sum.js @@ -1,43 +1,42 @@ 'use strict'; -var FL = require('fantasy-land'); -var $ = require('sanctuary-def'); -var Z = require('sanctuary-type-classes'); -var type = require('sanctuary-type-identifiers'); +var FL = require ('fantasy-land'); +var $ = require ('sanctuary-def'); +var Z = require ('sanctuary-type-classes'); +var type = require ('sanctuary-type-identifiers'); // Sum :: Number -> Sum function Sum(value) { - if (!(this instanceof Sum)) return new Sum(value); + if (!(this instanceof Sum)) return new Sum (value); this.value = value; } Sum['@@type'] = 'sanctuary/Sum'; // Type :: Type -Sum.Type = $.NullaryType( - Sum['@@type'], - '', - function(x) { return type(x) === Sum['@@type']; } -); +Sum.Type = $.NullaryType + (Sum['@@type']) + ('') + (function(x) { return type (x) === Sum['@@type']; }); -Sum[FL.empty] = function() { return Sum(0); }; +Sum[FL.empty] = function() { return Sum (0); }; Sum.prototype[FL.equals] = function(other) { - return Z.equals(this.value, other.value); + return Z.equals (this.value, other.value); }; Sum.prototype[FL.concat] = function(other) { - return Sum(this.value + other.value); + return Sum (this.value + other.value); }; Sum.prototype[FL.invert] = function() { - return Sum(-this.value); + return Sum (-this.value); }; Sum.prototype.inspect = Sum.prototype.toString = function() { - return 'Sum(' + Z.toString(this.value) + ')'; + return 'Sum(' + Z.toString (this.value) + ')'; }; module.exports = Sum; diff --git a/test/internal/alt.js b/test/internal/alt.js index 183ad1de..dcb40d8d 100644 --- a/test/internal/alt.js +++ b/test/internal/alt.js @@ -1,8 +1,8 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var curry2 = require('./curry2'); +var curry2 = require ('./curry2'); // alt :: Alt f => f a -> f a -> f a -module.exports = curry2(Z.alt); +module.exports = curry2 (Z.alt); diff --git a/test/internal/ap.js b/test/internal/ap.js index 4085dd98..5eb2c8c1 100644 --- a/test/internal/ap.js +++ b/test/internal/ap.js @@ -1,8 +1,8 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var curry2 = require('./curry2'); +var curry2 = require ('./curry2'); // ap :: Apply f => f (a -> b) -> f a -> f b -module.exports = curry2(Z.ap); +module.exports = curry2 (Z.ap); diff --git a/test/internal/area.js b/test/internal/area.js index a7f4e95d..a0977084 100644 --- a/test/internal/area.js +++ b/test/internal/area.js @@ -4,11 +4,11 @@ module.exports = function area(a) { return function(b) { return function(c) { - if (Math.max(a, b, c) < (a + b + c) / 2) { + if (Math.max (a, b, c) < (a + b + c) / 2) { var s = (a + b + c) / 2; - return Math.sqrt(s * (s - a) * (s - b) * (s - c)); + return Math.sqrt (s * (s - a) * (s - b) * (s - c)); } else { - throw new Error('Impossible triangle'); + throw new Error ('Impossible triangle'); } }; }; diff --git a/test/internal/area_.js b/test/internal/area_.js index 19f15c75..4523a437 100644 --- a/test/internal/area_.js +++ b/test/internal/area_.js @@ -1,6 +1,6 @@ 'use strict'; -var area = require('./area'); +var area = require ('./area'); // area_ :: (Number, Number, Number) -> Number ! -module.exports = function area_(a, b, c) { return area(a)(b)(c); }; +module.exports = function area_(a, b, c) { return area (a) (b) (c); }; diff --git a/test/internal/bimap.js b/test/internal/bimap.js index bc0d8840..a3d01dcb 100644 --- a/test/internal/bimap.js +++ b/test/internal/bimap.js @@ -1,8 +1,8 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var curry3 = require('./curry3'); +var curry3 = require ('./curry3'); // bimap :: Bifunctor f => (a -> b) -> (c -> d) -> f a c -> f b d -module.exports = curry3(Z.bimap); +module.exports = curry3 (Z.bimap); diff --git a/test/internal/chain.js b/test/internal/chain.js index 3cd2d0e6..3dcab356 100644 --- a/test/internal/chain.js +++ b/test/internal/chain.js @@ -1,8 +1,8 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var curry2 = require('./curry2'); +var curry2 = require ('./curry2'); // chain_ :: Chain m => (a -> m b) -> m a -> m b -module.exports = curry2(Z.chain); +module.exports = curry2 (Z.chain); diff --git a/test/internal/composeK.js b/test/internal/composeK.js index 8dc34887..784ea4ca 100644 --- a/test/internal/composeK.js +++ b/test/internal/composeK.js @@ -1,6 +1,6 @@ 'use strict'; -var chain = require('./chain'); +var chain = require ('./chain'); // composeK :: Chain m => (b -> m c) -> (a -> m b) -> a -> m c // @@ -8,7 +8,7 @@ var chain = require('./chain'); module.exports = function composeK(f) { return function(g) { return function(x) { - return chain(f)(g(x)); + return chain (f) (g (x)); }; }; }; diff --git a/test/internal/compose_.js b/test/internal/compose_.js index 0d4f6240..d9c8d10a 100644 --- a/test/internal/compose_.js +++ b/test/internal/compose_.js @@ -4,7 +4,7 @@ module.exports = function compose(f) { return function(g) { return function(x) { - return f(g(x)); + return f (g (x)); }; }; }; diff --git a/test/internal/concat.js b/test/internal/concat.js index 6c175a9b..c26ad48b 100644 --- a/test/internal/concat.js +++ b/test/internal/concat.js @@ -1,8 +1,8 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var curry2 = require('./curry2'); +var curry2 = require ('./curry2'); // concat :: Semigroup a => a -> a -> a -module.exports = curry2(Z.concat); +module.exports = curry2 (Z.concat); diff --git a/test/internal/curry2.js b/test/internal/curry2.js index f75a28b6..345c5494 100644 --- a/test/internal/curry2.js +++ b/test/internal/curry2.js @@ -4,7 +4,7 @@ module.exports = function curry2(f) { return function(x) { return function(y) { - return f(x, y); + return f (x, y); }; }; }; diff --git a/test/internal/curry3.js b/test/internal/curry3.js index b1dbd58b..5177a4db 100644 --- a/test/internal/curry3.js +++ b/test/internal/curry3.js @@ -5,7 +5,7 @@ module.exports = function curry3(f) { return function(x) { return function(y) { return function(z) { - return f(x, y, z); + return f (x, y, z); }; }; }; diff --git a/test/internal/eq.js b/test/internal/eq.js index e273f40a..e031df9c 100644 --- a/test/internal/eq.js +++ b/test/internal/eq.js @@ -1,13 +1,16 @@ 'use strict'; -var assert = require('assert'); +var assert = require ('assert'); -var equals = require('./equals'); -var toString = require('./toString'); +var equals = require ('./equals'); +var toString = require ('./toString'); -// eq :: (a, b) -> Undefined ! -module.exports = function eq(actual, expected) { - assert.strictEqual(arguments.length, eq.length); - assert.strictEqual(toString(actual), toString(expected)); - assert.strictEqual(equals(actual)(expected), true); +// eq :: a -> b -> Undefined ! +module.exports = function eq(actual) { + assert.strictEqual (arguments.length, eq.length); + return function eq$1(expected) { + assert.strictEqual (arguments.length, eq$1.length); + assert.strictEqual (toString (actual), toString (expected)); + assert.strictEqual (equals (actual) (expected), true); + }; }; diff --git a/test/internal/equals.js b/test/internal/equals.js index 9cee5987..91024ae3 100644 --- a/test/internal/equals.js +++ b/test/internal/equals.js @@ -1,8 +1,8 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var curry2 = require('./curry2'); +var curry2 = require ('./curry2'); // equals :: a -> b -> Boolean -module.exports = curry2(Z.equals); +module.exports = curry2 (Z.equals); diff --git a/test/internal/extend.js b/test/internal/extend.js index ceb81380..42870bd0 100644 --- a/test/internal/extend.js +++ b/test/internal/extend.js @@ -1,8 +1,8 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var curry2 = require('./curry2'); +var curry2 = require ('./curry2'); // extend :: Extend w => (w a -> b) -> w a -> w b -module.exports = curry2(Z.extend); +module.exports = curry2 (Z.extend); diff --git a/test/internal/factorial.js b/test/internal/factorial.js index 1c3a26b1..d46e8d5c 100644 --- a/test/internal/factorial.js +++ b/test/internal/factorial.js @@ -3,10 +3,10 @@ // factorial :: Number -> Number ! module.exports = function factorial(n) { if (n < 0) { - throw new Error('Cannot determine factorial of negative number'); + throw new Error ('Cannot determine factorial of negative number'); } else if (n === 0) { return 1; } else { - return n * factorial(n - 1); + return n * factorial (n - 1); } }; diff --git a/test/internal/forall.js b/test/internal/forall.js index f8836b87..9ca49e1c 100644 --- a/test/internal/forall.js +++ b/test/internal/forall.js @@ -1,16 +1,21 @@ 'use strict'; -var jsc = require('jsverify'); +var jsc = require ('jsverify'); +var Z = require ('sanctuary-type-classes'); // forall :: StrMap Function -> StrMap Function module.exports = function forall(laws) { - return Object.keys(laws).reduce(function(result, name) { - var pred = laws[name]; - result[name] = function() { - var arbs = Array.prototype.slice.call(arguments); - var args = arbs.concat([pred]); - test(name, function() { jsc.assert(jsc.forall.apply(jsc, args)); }); - }; - return result; - }, {}); + return Z.reduce ( + function(result, name) { + var pred = laws[name]; + result[name] = function() { + var arbs = Array.prototype.slice.call (arguments); + var args = arbs.concat ([pred]); + test (name, function() { jsc.assert (jsc.forall.apply (jsc, args)); }); + }; + return result; + }, + {}, + Object.keys (laws) + ); }; diff --git a/test/internal/laws/Alt.js b/test/internal/laws/Alt.js index 876d11dd..8e8be6fd 100644 --- a/test/internal/laws/Alt.js +++ b/test/internal/laws/Alt.js @@ -1,25 +1,25 @@ 'use strict'; -var alt = require('../alt'); -var forall = require('../forall'); -var map = require('../map'); +var alt = require ('../alt'); +var forall = require ('../forall'); +var map = require ('../map'); module.exports = function(equals) { - return forall({ + return forall ({ // (a <|> b) <|> c = a <|> (b <|> c) associativity: function(a, b, c) { - var lhs = alt(alt(a)(b))(c); - var rhs = alt(a)(alt(b)(c)); - return equals(lhs)(rhs); + var lhs = alt (alt (a) (b)) (c); + var rhs = alt (a) (alt (b) (c)); + return equals (lhs) (rhs); }, // f <$> (a <|> b) = (f <$> a) <|> (f <$> b) distributivity: function(a, b, f) { - var lhs = map(f)(alt(a)(b)); - var rhs = alt(map(f)(a))(map(f)(b)); - return equals(lhs)(rhs); + var lhs = map (f) (alt (a) (b)); + var rhs = alt (map (f) (a)) (map (f) (b)); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/Alternative.js b/test/internal/laws/Alternative.js index 3e3b3086..14c56232 100644 --- a/test/internal/laws/Alternative.js +++ b/test/internal/laws/Alternative.js @@ -1,28 +1,28 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var alt = require('../alt'); -var ap = require('../ap'); -var forall = require('../forall'); +var alt = require ('../alt'); +var ap = require ('../ap'); +var forall = require ('../forall'); module.exports = function(equals, A) { - var zero = Z.zero(A); - return forall({ + var zero = Z.zero (A); + return forall ({ // (f <|> g) <*> x = (f <*> x) <|> (g <*> x) distributivity: function(x, f, g) { - var lhs = ap(alt(f)(g))(x); - var rhs = alt(ap(f)(x))(ap(g)(x)); - return equals(lhs)(rhs); + var lhs = ap (alt (f) (g)) (x); + var rhs = alt (ap (f) (x)) (ap (g) (x)); + return equals (lhs) (rhs); }, // zero <*> x = zero annihilation: function(x) { - var lhs = ap(zero)(x); + var lhs = ap (zero) (x); var rhs = zero; - return equals(lhs)(rhs); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/Applicative.js b/test/internal/laws/Applicative.js index b077df58..be5928fb 100644 --- a/test/internal/laws/Applicative.js +++ b/test/internal/laws/Applicative.js @@ -1,35 +1,35 @@ 'use strict'; -var $ = require('../$'); -var ap = require('../ap'); -var forall = require('../forall'); -var id = require('../id'); -var of = require('../of'); +var $ = require ('../$'); +var ap = require ('../ap'); +var forall = require ('../forall'); +var id = require ('../id'); +var of = require ('../of'); module.exports = function(equals, A) { - var pure = of(A); - return forall({ + var pure = of (A); + return forall ({ // pure id <*> v = v identity: function(v) { - var lhs = ap(pure(id))(v); + var lhs = ap (pure (id)) (v); var rhs = v; - return equals(lhs)(rhs); + return equals (lhs) (rhs); }, // pure f <*> pure x = pure (f x) homomorphism: function(f, x) { - var lhs = ap(pure(f))(pure(x)); - var rhs = pure(f(x)); - return equals(lhs)(rhs); + var lhs = ap (pure (f)) (pure (x)); + var rhs = pure (f (x)); + return equals (lhs) (rhs); }, // u <*> pure y = pure ($ y) <*> u interchange: function(u, y) { - var lhs = ap(u)(pure(y)); - var rhs = ap(pure($(y)))(u); - return equals(lhs)(rhs); + var lhs = ap (u) (pure (y)); + var rhs = ap (pure ($ (y))) (u); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/Apply.js b/test/internal/laws/Apply.js index 42a0a199..37a51032 100644 --- a/test/internal/laws/Apply.js +++ b/test/internal/laws/Apply.js @@ -1,19 +1,19 @@ 'use strict'; -var ap = require('../ap'); -var compose = require('../compose_'); -var forall = require('../forall'); -var map = require('../map'); +var ap = require ('../ap'); +var compose = require ('../compose_'); +var forall = require ('../forall'); +var map = require ('../map'); module.exports = function(equals) { - return forall({ + return forall ({ // (.) <$> u <*> v <*> w = u <*> (v <*> w) composition: function(u, v, w) { - var lhs = ap(ap(map(compose)(u))(v))(w); - var rhs = ap(u)(ap(v)(w)); - return equals(lhs)(rhs); + var lhs = ap (ap (map (compose) (u)) (v)) (w); + var rhs = ap (u) (ap (v) (w)); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/Bifunctor.js b/test/internal/laws/Bifunctor.js index 182116e8..998ec7e3 100644 --- a/test/internal/laws/Bifunctor.js +++ b/test/internal/laws/Bifunctor.js @@ -1,26 +1,26 @@ 'use strict'; -var bimap = require('../bimap'); -var compose = require('../compose_'); -var forall = require('../forall'); -var id = require('../id'); +var bimap = require ('../bimap'); +var compose = require ('../compose_'); +var forall = require ('../forall'); +var id = require ('../id'); module.exports = function(equals) { - return forall({ + return forall ({ // bimap id id p = p identity: function(p) { - var lhs = bimap(id)(id)(p); + var lhs = bimap (id) (id) (p); var rhs = p; - return equals(lhs)(rhs); + return equals (lhs) (rhs); }, // bimap (f . g) (h . i) p = bimap f h (bimap g i p) composition: function(p, f, g, h, i) { - var lhs = bimap(compose(f)(g))(compose(h)(i))(p); - var rhs = bimap(f)(h)(bimap(g)(i)(p)); - return equals(lhs)(rhs); + var lhs = bimap (compose (f) (g)) (compose (h) (i)) (p); + var rhs = bimap (f) (h) (bimap (g) (i) (p)); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/Chain.js b/test/internal/laws/Chain.js index 1dfbdbf6..50980a41 100644 --- a/test/internal/laws/Chain.js +++ b/test/internal/laws/Chain.js @@ -1,18 +1,18 @@ 'use strict'; -var chain = require('../chain'); -var composeK = require('../composeK'); -var forall = require('../forall'); +var chain = require ('../chain'); +var composeK = require ('../composeK'); +var forall = require ('../forall'); module.exports = function(equals) { - return forall({ + return forall ({ // (m >>= f) >>= g = m >>= (f >=> g) associativity: function(m, f, g) { - var lhs = chain(g)(chain(f)(m)); - var rhs = chain(composeK(g)(f))(m); - return equals(lhs)(rhs); + var lhs = chain (g) (chain (f) (m)); + var rhs = chain (composeK (g) (f)) (m); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/Extend.js b/test/internal/laws/Extend.js index 7cb232f8..133a8ee1 100644 --- a/test/internal/laws/Extend.js +++ b/test/internal/laws/Extend.js @@ -1,18 +1,18 @@ 'use strict'; -var compose = require('../compose_'); -var extend = require('../extend'); -var forall = require('../forall'); +var compose = require ('../compose_'); +var extend = require ('../extend'); +var forall = require ('../forall'); module.exports = function(equals) { - return forall({ + return forall ({ // (extend f . extend g) w = extend (f . extend g) w associativity: function(w, f, g) { - var lhs = compose(extend(f))(extend(g))(w); - var rhs = extend(compose(f)(extend(g)))(w); - return equals(lhs)(rhs); + var lhs = compose (extend (f)) (extend (g)) (w); + var rhs = extend (compose (f) (extend (g))) (w); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/Foldable.js b/test/internal/laws/Foldable.js index c0c868df..5ee5bde2 100644 --- a/test/internal/laws/Foldable.js +++ b/test/internal/laws/Foldable.js @@ -1,17 +1,17 @@ 'use strict'; -var forall = require('../forall'); -var reduce = require('../reduce'); +var forall = require ('../forall'); +var reduce = require ('../reduce'); module.exports = function(equals) { - return forall({ + return forall ({ // reduce f x u = reduce f x (reduce (\xs x -> xs ++ [x]) [] u) associativity: function(f, x, u) { - var lhs = reduce(f)(x)(u); - var rhs = reduce(f)(x)(reduce(function(xs, x) { return xs.concat([x]); })([])(u)); - return equals(lhs)(rhs); + var lhs = reduce (f) (x) (u); + var rhs = reduce (f) (x) (reduce (function(xs, x) { return xs.concat ([x]); }) ([]) (u)); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/Functor.js b/test/internal/laws/Functor.js index f3ed2580..187e3a62 100644 --- a/test/internal/laws/Functor.js +++ b/test/internal/laws/Functor.js @@ -1,26 +1,26 @@ 'use strict'; -var compose = require('../compose_'); -var forall = require('../forall'); -var id = require('../id'); -var map = require('../map'); +var compose = require ('../compose_'); +var forall = require ('../forall'); +var id = require ('../id'); +var map = require ('../map'); module.exports = function(equals) { - return forall({ + return forall ({ // id <$> u = u identity: function(u) { - var lhs = map(id)(u); + var lhs = map (id) (u); var rhs = u; - return equals(lhs)(rhs); + return equals (lhs) (rhs); }, // (f . g) <$> u = f <$> g <$> u composition: function(u, f, g) { - var lhs = map(compose(f)(g))(u); - var rhs = compose(map(f))(map(g))(u); - return equals(lhs)(rhs); + var lhs = map (compose (f) (g)) (u); + var rhs = compose (map (f)) (map (g)) (u); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/Monad.js b/test/internal/laws/Monad.js index 53d3aec9..c679330b 100644 --- a/test/internal/laws/Monad.js +++ b/test/internal/laws/Monad.js @@ -1,26 +1,26 @@ 'use strict'; -var chain = require('../chain'); -var forall = require('../forall'); -var of = require('../of'); +var chain = require ('../chain'); +var forall = require ('../forall'); +var of = require ('../of'); module.exports = function(equals, M) { - var pure = of(M); - return forall({ + var pure = of (M); + return forall ({ // pure x >>= f = f x leftIdentity: function(f, x) { - var lhs = chain(f)(pure(x)); - var rhs = f(x); - return equals(lhs)(rhs); + var lhs = chain (f) (pure (x)); + var rhs = f (x); + return equals (lhs) (rhs); }, // m >>= pure = m rightIdentity: function(m) { - var lhs = chain(pure)(m); + var lhs = chain (pure) (m); var rhs = m; - return equals(lhs)(rhs); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/Monoid.js b/test/internal/laws/Monoid.js index 9d881716..e0f02b1c 100644 --- a/test/internal/laws/Monoid.js +++ b/test/internal/laws/Monoid.js @@ -1,27 +1,27 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var concat = require('../concat'); -var forall = require('../forall'); +var concat = require ('../concat'); +var forall = require ('../forall'); module.exports = function(equals, M) { - var empty = Z.empty(M); - return forall({ + var empty = Z.empty (M); + return forall ({ // empty `concat` m = m leftIdentity: function(m) { - var lhs = concat(empty)(m); + var lhs = concat (empty) (m); var rhs = m; - return equals(lhs)(rhs); + return equals (lhs) (rhs); }, // m `concat` empty = m rightIdentity: function(m) { - var lhs = concat(m)(empty); + var lhs = concat (m) (empty); var rhs = m; - return equals(lhs)(rhs); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/Plus.js b/test/internal/laws/Plus.js index 8a842d7e..7cab7beb 100644 --- a/test/internal/laws/Plus.js +++ b/test/internal/laws/Plus.js @@ -1,35 +1,35 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var alt = require('../alt'); -var forall = require('../forall'); -var map = require('../map'); +var alt = require ('../alt'); +var forall = require ('../forall'); +var map = require ('../map'); module.exports = function(equals, P) { - var zero = Z.zero(P); - return forall({ + var zero = Z.zero (P); + return forall ({ // zero <|> x = x leftIdentity: function(x) { - var lhs = alt(zero)(x); + var lhs = alt (zero) (x); var rhs = x; - return equals(lhs)(rhs); + return equals (lhs) (rhs); }, // x <|> zero = x rightIdentity: function(x) { - var lhs = alt(x)(zero); + var lhs = alt (x) (zero); var rhs = x; - return equals(lhs)(rhs); + return equals (lhs) (rhs); }, // f <$> zero = zero annihilation: function(f) { - var lhs = map(f)(zero); + var lhs = map (f) (zero); var rhs = zero; - return equals(lhs)(rhs); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/Semigroup.js b/test/internal/laws/Semigroup.js index f7279f14..efb30025 100644 --- a/test/internal/laws/Semigroup.js +++ b/test/internal/laws/Semigroup.js @@ -1,17 +1,17 @@ 'use strict'; -var concat = require('../concat'); -var forall = require('../forall'); +var concat = require ('../concat'); +var forall = require ('../forall'); module.exports = function(equals) { - return forall({ + return forall ({ // (x `concat` y) `concat` z = x `concat` (y `concat` z) associativity: function(x, y, z) { - var lhs = concat(concat(x)(y))(z); - var rhs = concat(x)(concat(y)(z)); - return equals(lhs)(rhs); + var lhs = concat (concat (x) (y)) (z); + var rhs = concat (x) (concat (y) (z)); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/Setoid.js b/test/internal/laws/Setoid.js index f547e283..358d8e80 100644 --- a/test/internal/laws/Setoid.js +++ b/test/internal/laws/Setoid.js @@ -1,24 +1,24 @@ 'use strict'; -var equals = require('../equals'); -var forall = require('../forall'); +var equals = require ('../equals'); +var forall = require ('../forall'); -module.exports = forall({ +module.exports = forall ({ // a `equals` a = true reflexivity: function(a) { - return equals(a)(a); + return equals (a) (a); }, // a `equals` b = b `equals` a symmetry: function(a, b) { - return equals(a)(b) === equals(b)(a); + return equals (a) (b) === equals (b) (a); }, // a `equals` b & b `equals` c => a `equals` c transitivity: function(a, b, c) { - return equals(a)(b) && equals(b)(c) ? equals(a)(c) : true; + return equals (a) (b) && equals (b) (c) ? equals (a) (c) : true; } }); diff --git a/test/internal/laws/Traversable.js b/test/internal/laws/Traversable.js index b3c9585e..71adbdb6 100644 --- a/test/internal/laws/Traversable.js +++ b/test/internal/laws/Traversable.js @@ -1,36 +1,36 @@ 'use strict'; -var Compose = require('../Compose'); -var forall = require('../forall'); -var id = require('../id'); -var map = require('../map'); -var of = require('../of'); -var traverse = require('../traverse'); +var Compose = require ('../Compose'); +var forall = require ('../forall'); +var id = require ('../id'); +var map = require ('../map'); +var of = require ('../of'); +var traverse = require ('../traverse'); module.exports = function(equals) { - return forall({ + return forall ({ // t (traverse F id u) = traverse G t u naturality: function(t, u, F, G) { - var lhs = t(traverse(F)(id)(u)); - var rhs = traverse(G)(t)(u); - return equals(lhs)(rhs); + var lhs = t (traverse (F) (id) (u)); + var rhs = traverse (G) (t) (u); + return equals (lhs) (rhs); }, // traverse F F u = of F u identity: function(u, F) { - var lhs = traverse(F)(F)(u); - var rhs = of(F)(u); - return equals(lhs)(rhs); + var lhs = traverse (F) (F) (u); + var rhs = of (F) (u); + return equals (lhs) (rhs); }, // traverse C C u = C (traverse G id <$> traverse F id u) composition: function(u, F, G) { - var C = Compose(F)(G); - var lhs = traverse(C)(C)(u); - var rhs = C(map(traverse(G)(id))(traverse(F)(id)(u))); - return equals(lhs)(rhs); + var C = Compose (F) (G); + var lhs = traverse (C) (C) (u); + var rhs = C (map (traverse (G) (id)) (traverse (F) (id) (u))); + return equals (lhs) (rhs); } }); diff --git a/test/internal/laws/index.js b/test/internal/laws/index.js index 6302f5e1..c438007c 100644 --- a/test/internal/laws/index.js +++ b/test/internal/laws/index.js @@ -1,19 +1,19 @@ 'use strict'; module.exports = { - Alt: require('./Alt'), - Alternative: require('./Alternative'), - Applicative: require('./Applicative'), - Apply: require('./Apply'), - Bifunctor: require('./Bifunctor'), - Chain: require('./Chain'), - Extend: require('./Extend'), - Foldable: require('./Foldable'), - Functor: require('./Functor'), - Monad: require('./Monad'), - Monoid: require('./Monoid'), - Plus: require('./Plus'), - Semigroup: require('./Semigroup'), - Setoid: require('./Setoid'), - Traversable: require('./Traversable') + Alt: require ('./Alt'), + Alternative: require ('./Alternative'), + Applicative: require ('./Applicative'), + Apply: require ('./Apply'), + Bifunctor: require ('./Bifunctor'), + Chain: require ('./Chain'), + Extend: require ('./Extend'), + Foldable: require ('./Foldable'), + Functor: require ('./Functor'), + Monad: require ('./Monad'), + Monoid: require ('./Monoid'), + Plus: require ('./Plus'), + Semigroup: require ('./Semigroup'), + Setoid: require ('./Setoid'), + Traversable: require ('./Traversable') }; diff --git a/test/internal/map.js b/test/internal/map.js index 64ba01ef..b7b6d582 100644 --- a/test/internal/map.js +++ b/test/internal/map.js @@ -1,8 +1,8 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var curry2 = require('./curry2'); +var curry2 = require ('./curry2'); // map :: Functor f => (a -> b) -> f a -> f b -module.exports = curry2(Z.map); +module.exports = curry2 (Z.map); diff --git a/test/internal/of.js b/test/internal/of.js index 2bd0087e..2ccd75b7 100644 --- a/test/internal/of.js +++ b/test/internal/of.js @@ -1,8 +1,8 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var curry2 = require('./curry2'); +var curry2 = require ('./curry2'); // of :: Applicative f => TypeRep f -> a -> f a -module.exports = curry2(Z.of); +module.exports = curry2 (Z.of); diff --git a/test/internal/reduce.js b/test/internal/reduce.js index efb799a0..166a614f 100644 --- a/test/internal/reduce.js +++ b/test/internal/reduce.js @@ -1,8 +1,8 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var curry3 = require('./curry3'); +var curry3 = require ('./curry3'); // reduce :: Foldable f => ((b, a) -> b) -> b -> f a -> b -module.exports = curry3(Z.reduce); +module.exports = curry3 (Z.reduce); diff --git a/test/internal/rem.js b/test/internal/rem.js index c6b0896d..74a28aee 100644 --- a/test/internal/rem.js +++ b/test/internal/rem.js @@ -4,7 +4,7 @@ module.exports = function rem(x) { return function(y) { if (y === 0) { - throw new Error('Cannot divide by zero'); + throw new Error ('Cannot divide by zero'); } else { return x % y; } diff --git a/test/internal/rem_.js b/test/internal/rem_.js index 1267c2d3..61bb64f3 100644 --- a/test/internal/rem_.js +++ b/test/internal/rem_.js @@ -1,6 +1,6 @@ 'use strict'; -var rem = require('./rem'); +var rem = require ('./rem'); // rem_ :: (Number, Number) -> Number ! -module.exports = function rem_(x, y) { return rem(x)(y); }; +module.exports = function rem_(x, y) { return rem (x) (y); }; diff --git a/test/internal/sanctuary.js b/test/internal/sanctuary.js index 221693fb..0c3197f3 100644 --- a/test/internal/sanctuary.js +++ b/test/internal/sanctuary.js @@ -1,38 +1,37 @@ 'use strict'; -var $ = require('sanctuary-def'); -var type = require('sanctuary-type-identifiers'); +var $ = require ('sanctuary-def'); +var type = require ('sanctuary-type-identifiers'); -var S = require('../..'); +var S = require ('../..'); -var List = require('./List'); -var Sum = require('./Sum'); +var List = require ('./List'); +var Sum = require ('./Sum'); // UnaryType :: String -> Type function UnaryType(typeIdent) { - return $.UnaryType( - typeIdent, - '', - function(x) { return type(x) === typeIdent; }, - function(v) { return [v.value]; } - )($.Unknown); + return $.UnaryType + (typeIdent) + ('') + (function(x) { return type (x) === typeIdent; }) + (function(v) { return [v.value]; }) + ($.Unknown); } // UselessType :: Type -var UselessType = $.NullaryType( - 'sanctuary/Useless', - '', - function(x) { return type(x) === 'sanctuary/Useless'; } -); +var UselessType = $.NullaryType + ('sanctuary/Useless') + ('') + (function(x) { return type (x) === 'sanctuary/Useless'; }); // env :: Array Type -var env = S.env.concat([ - UnaryType('sanctuary/Compose'), - UnaryType('sanctuary/Identity'), - List.Type($.Unknown), +var env = S.env.concat ([ + UnaryType ('sanctuary/Compose'), + UnaryType ('sanctuary/Identity'), + List.Type ($.Unknown), Sum.Type, UselessType ]); -module.exports = S.create({checkTypes: true, env: env}); +module.exports = S.create ({checkTypes: true, env: env}); diff --git a/test/internal/squareRoot.js b/test/internal/squareRoot.js index db696fed..03608d6c 100644 --- a/test/internal/squareRoot.js +++ b/test/internal/squareRoot.js @@ -1,9 +1,9 @@ 'use strict'; -var S = require('../..'); +var S = require ('../..'); // squareRoot :: Number -> Either String Number module.exports = function squareRoot(n) { - return n < 0 ? S.Left('Cannot represent square root of negative number') - : S.Right(Math.sqrt(n)); + return n < 0 ? S.Left ('Cannot represent square root of negative number') + : S.Right (Math.sqrt (n)); }; diff --git a/test/internal/throws.js b/test/internal/throws.js index 5468e021..fce02b6f 100644 --- a/test/internal/throws.js +++ b/test/internal/throws.js @@ -1,11 +1,14 @@ 'use strict'; -var assert = require('assert'); +var assert = require ('assert'); -// throws :: (Function, TypeRep a, String) -> Undefined -module.exports = function throws(f, type, message) { - assert.strictEqual(arguments.length, throws.length); - assert.throws(f, function(err) { - return err.constructor === type && err.message === message; - }); +var equals = require ('./equals'); + +// throws :: (() -> Undefined !) -> Error -> Undefined ! +module.exports = function throws(thunk) { + assert.strictEqual (arguments.length, throws.length); + return function throws$1(expected) { + assert.strictEqual (arguments.length, throws$1.length); + assert.throws (thunk, equals (expected)); + }; }; diff --git a/test/internal/toString.js b/test/internal/toString.js index 2071004a..63d0ce0e 100644 --- a/test/internal/toString.js +++ b/test/internal/toString.js @@ -1,6 +1,6 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); // toString :: a -> String module.exports = Z.toString; diff --git a/test/internal/traverse.js b/test/internal/traverse.js index 6d45e664..3e8d0b61 100644 --- a/test/internal/traverse.js +++ b/test/internal/traverse.js @@ -1,8 +1,8 @@ 'use strict'; -var Z = require('sanctuary-type-classes'); +var Z = require ('sanctuary-type-classes'); -var curry3 = require('./curry3'); +var curry3 = require ('./curry3'); // traverse :: (Applicative f, Traversable t) => TypeRep f -> (a -> f b) -> t a -> f (t b) -module.exports = curry3(Z.traverse); +module.exports = curry3 (Z.traverse); diff --git a/test/invert.js b/test/invert.js index 48f5c363..7075524d 100644 --- a/test/invert.js +++ b/test/invert.js @@ -1,18 +1,18 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var Sum = require('./internal/Sum'); -var eq = require('./internal/eq'); +var Sum = require ('./internal/Sum'); +var eq = require ('./internal/eq'); -test('invert', function() { +test ('invert', function() { - eq(typeof S.invert, 'function'); - eq(S.invert.length, 1); - eq(S.invert.toString(), 'invert :: Group g => g -> g'); + eq (typeof S.invert) ('function'); + eq (S.invert.length) (1); + eq (String (S.invert)) ('invert :: Group g => g -> g'); - eq(S.invert(Sum(5)), Sum(-5)); - eq(S.invert(Sum(-5)), Sum(5)); + eq (S.invert (Sum (5))) (Sum (-5)); + eq (S.invert (Sum (-5))) (Sum (5)); }); diff --git a/test/is.js b/test/is.js index 0db3225b..68b71c52 100644 --- a/test/is.js +++ b/test/is.js @@ -1,54 +1,54 @@ 'use strict'; -var $ = require('sanctuary-def'); +var $ = require ('sanctuary-def'); -var S = require('..'); +var S = require ('..'); -var Sum = require('./internal/Sum'); -var eq = require('./internal/eq'); +var Sum = require ('./internal/Sum'); +var eq = require ('./internal/eq'); -test('is', function() { +test ('is', function() { - eq(typeof S.is, 'function'); - eq(S.is.length, 2); - eq(S.is.toString(), 'is :: Type -> Any -> Boolean'); + eq (typeof S.is) ('function'); + eq (S.is.length) (1); + eq (String (S.is)) ('is :: Type -> Any -> Boolean'); - eq(S.is($.Boolean, true), true); - eq(S.is($.Boolean, false), true); - eq(S.is($.Boolean, new Boolean(true)), false); - eq(S.is($.Boolean, new Boolean(false)), false); + eq (S.is ($.Boolean) (true)) (true); + eq (S.is ($.Boolean) (false)) (true); + eq (S.is ($.Boolean) (new Boolean (true))) (false); + eq (S.is ($.Boolean) (new Boolean (false))) (false); - eq(S.is($.Array($.Integer), null), false); - eq(S.is($.Array($.Integer), undefined), false); - eq(S.is($.Array($.Integer), ['1', '2', '3']), false); - eq(S.is($.Array($.Integer), [1, 2, 3.14]), false); - eq(S.is($.Array($.Integer), [1, 2, 3]), true); - eq(S.is($.Array($.Integer), []), true); + eq (S.is ($.Array ($.Integer)) (null)) (false); + eq (S.is ($.Array ($.Integer)) (undefined)) (false); + eq (S.is ($.Array ($.Integer)) (['1', '2', '3'])) (false); + eq (S.is ($.Array ($.Integer)) ([1, 2, 3.14])) (false); + eq (S.is ($.Array ($.Integer)) ([1, 2, 3])) (true); + eq (S.is ($.Array ($.Integer)) ([])) (true); - eq(S.is(S.MaybeType($.Integer), S.Nothing), true); - eq(S.is(S.MaybeType($.Integer), S.Just(0)), true); - eq(S.is(S.MaybeType($.Integer), S.Left(0)), false); - eq(S.is(S.MaybeType($.Integer), S.Right(0)), false); + eq (S.is (S.MaybeType ($.Integer)) (S.Nothing)) (true); + eq (S.is (S.MaybeType ($.Integer)) (S.Just (0))) (true); + eq (S.is (S.MaybeType ($.Integer)) (S.Left (0))) (false); + eq (S.is (S.MaybeType ($.Integer)) (S.Right (0))) (false); - eq(S.is(S.EitherType($.String, $.Integer), S.Nothing), false); - eq(S.is(S.EitherType($.String, $.Integer), S.Just(0)), false); - eq(S.is(S.EitherType($.String, $.Integer), S.Left(0)), false); - eq(S.is(S.EitherType($.String, $.Integer), S.Right('')), false); - eq(S.is(S.EitherType($.String, $.Integer), S.Left('')), true); - eq(S.is(S.EitherType($.String, $.Integer), S.Right(0)), true); + eq (S.is (S.EitherType ($.String) ($.Integer)) (S.Nothing)) (false); + eq (S.is (S.EitherType ($.String) ($.Integer)) (S.Just (0))) (false); + eq (S.is (S.EitherType ($.String) ($.Integer)) (S.Left (0))) (false); + eq (S.is (S.EitherType ($.String) ($.Integer)) (S.Right (''))) (false); + eq (S.is (S.EitherType ($.String) ($.Integer)) (S.Left (''))) (true); + eq (S.is (S.EitherType ($.String) ($.Integer)) (S.Right (0))) (true); - var a = $.TypeVariable('a'); + var a = $.TypeVariable ('a'); - eq(S.is($.Array(a), []), true); - eq(S.is($.Array(a), [1, 2, 3]), true); - eq(S.is($.Array(a), ['foo', 'bar', 'baz']), true); - eq(S.is($.Array(a), ['foo', true, 42]), false); - eq(S.is($.Array(a), [Sum(1), Sum(2), Sum(3)]), false); + eq (S.is ($.Array (a)) ([])) (true); + eq (S.is ($.Array (a)) ([1, 2, 3])) (true); + eq (S.is ($.Array (a)) (['foo', 'bar', 'baz'])) (true); + eq (S.is ($.Array (a)) (['foo', true, 42])) (false); + eq (S.is ($.Array (a)) ([Sum (1), Sum (2), Sum (3)])) (false); - eq(S.create({checkTypes: true, env: []}).is($.Array(a), []), true); - eq(S.create({checkTypes: true, env: []}).is($.Array(a), [1, 2, 3]), false); - eq(S.create({checkTypes: true, env: [$.Number]}).is($.Array(a), [1, 2, 3]), true); - eq(S.create({checkTypes: true, env: [Sum.Type]}).is($.Array(a), [Sum(1), Sum(2), Sum(3)]), true); + eq ((S.create ({checkTypes: true, env: []})).is ($.Array (a)) ([])) (true); + eq ((S.create ({checkTypes: true, env: []})).is ($.Array (a)) ([1, 2, 3])) (false); + eq ((S.create ({checkTypes: true, env: [$.Number]})).is ($.Array (a)) ([1, 2, 3])) (true); + eq ((S.create ({checkTypes: true, env: [Sum.Type]})).is ($.Array (a)) ([Sum (1), Sum (2), Sum (3)])) (true); }); diff --git a/test/isJust.js b/test/isJust.js index 577c8319..3f076a0f 100644 --- a/test/isJust.js +++ b/test/isJust.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('isJust', function() { +test ('isJust', function() { - eq(typeof S.isJust, 'function'); - eq(S.isJust.length, 1); - eq(S.isJust.toString(), 'isJust :: Maybe a -> Boolean'); + eq (typeof S.isJust) ('function'); + eq (S.isJust.length) (1); + eq (String (S.isJust)) ('isJust :: Maybe a -> Boolean'); - eq(S.isJust(S.Nothing), false); - eq(S.isJust(S.Just(42)), true); + eq (S.isJust (S.Nothing)) (false); + eq (S.isJust (S.Just (42))) (true); }); diff --git a/test/isLeft.js b/test/isLeft.js index 90b5a504..b6ddcaa0 100644 --- a/test/isLeft.js +++ b/test/isLeft.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('isLeft', function() { +test ('isLeft', function() { - eq(typeof S.isLeft, 'function'); - eq(S.isLeft.length, 1); - eq(S.isLeft.toString(), 'isLeft :: Either a b -> Boolean'); + eq (typeof S.isLeft) ('function'); + eq (S.isLeft.length) (1); + eq (String (S.isLeft)) ('isLeft :: Either a b -> Boolean'); - eq(S.isLeft(S.Left(42)), true); - eq(S.isLeft(S.Right(42)), false); + eq (S.isLeft (S.Left (42))) (true); + eq (S.isLeft (S.Right (42))) (false); }); diff --git a/test/isNothing.js b/test/isNothing.js index ef702bfe..568a6202 100644 --- a/test/isNothing.js +++ b/test/isNothing.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('isNothing', function() { +test ('isNothing', function() { - eq(typeof S.isNothing, 'function'); - eq(S.isNothing.length, 1); - eq(S.isNothing.toString(), 'isNothing :: Maybe a -> Boolean'); + eq (typeof S.isNothing) ('function'); + eq (S.isNothing.length) (1); + eq (String (S.isNothing)) ('isNothing :: Maybe a -> Boolean'); - eq(S.isNothing(S.Nothing), true); - eq(S.isNothing(S.Just(42)), false); + eq (S.isNothing (S.Nothing)) (true); + eq (S.isNothing (S.Just (42))) (false); }); diff --git a/test/isRight.js b/test/isRight.js index c62d1d70..0c47024e 100644 --- a/test/isRight.js +++ b/test/isRight.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('isRight', function() { +test ('isRight', function() { - eq(typeof S.isRight, 'function'); - eq(S.isRight.length, 1); - eq(S.isRight.toString(), 'isRight :: Either a b -> Boolean'); + eq (typeof S.isRight) ('function'); + eq (S.isRight.length) (1); + eq (String (S.isRight)) ('isRight :: Either a b -> Boolean'); - eq(S.isRight(S.Left(42)), false); - eq(S.isRight(S.Right(42)), true); + eq (S.isRight (S.Left (42))) (false); + eq (S.isRight (S.Right (42))) (true); }); diff --git a/test/join.js b/test/join.js index 52e31c85..043aa74e 100644 --- a/test/join.js +++ b/test/join.js @@ -1,24 +1,24 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('join', function() { +test ('join', function() { - eq(typeof S.join, 'function'); - eq(S.join.length, 1); - eq(S.join.toString(), 'join :: Chain m => m (m a) -> m a'); + eq (typeof S.join) ('function'); + eq (S.join.length) (1); + eq (String (S.join)) ('join :: Chain m => m (m a) -> m a'); - eq(S.join([]), []); - eq(S.join([[]]), []); - eq(S.join([[[]]]), [[]]); - eq(S.join([[1], [2], [3]]), [1, 2, 3]); - eq(S.join([[[1, 2, 3]]]), [[1, 2, 3]]); - eq(S.join(S.Nothing), S.Nothing); - eq(S.join(S.Just(S.Nothing)), S.Nothing); - eq(S.join(S.Just(S.Just(1))), S.Just(1)); - eq(S.join(S.Just(S.Just(S.Just(1)))), S.Just(S.Just(1))); + eq (S.join ([])) ([]); + eq (S.join ([[]])) ([]); + eq (S.join ([[[]]])) ([[]]); + eq (S.join ([[1], [2], [3]])) ([1, 2, 3]); + eq (S.join ([[[1, 2, 3]]])) ([[1, 2, 3]]); + eq (S.join (S.Nothing)) (S.Nothing); + eq (S.join (S.Just (S.Nothing))) (S.Nothing); + eq (S.join (S.Just (S.Just (1)))) (S.Just (1)); + eq (S.join (S.Just (S.Just (S.Just (1))))) (S.Just (S.Just (1))); }); diff --git a/test/joinWith.js b/test/joinWith.js index 20c29a65..20306d9f 100644 --- a/test/joinWith.js +++ b/test/joinWith.js @@ -1,22 +1,22 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('joinWith', function() { +test ('joinWith', function() { - eq(typeof S.joinWith, 'function'); - eq(S.joinWith.length, 2); - eq(S.joinWith.toString(), 'joinWith :: String -> Array String -> String'); + eq (typeof S.joinWith) ('function'); + eq (S.joinWith.length) (1); + eq (String (S.joinWith)) ('joinWith :: String -> Array String -> String'); - eq(S.joinWith('', ['a', 'b', 'c']), 'abc'); - eq(S.joinWith(':', []), ''); - eq(S.joinWith(':', ['']), ''); - eq(S.joinWith(':', ['', '']), ':'); - eq(S.joinWith(':', ['', 'foo', '']), ':foo:'); - eq(S.joinWith(':', ['foo', 'bar', 'baz']), 'foo:bar:baz'); - eq(S.joinWith('::', ['foo', 'bar', 'baz']), 'foo::bar::baz'); + eq (S.joinWith ('') (['a', 'b', 'c'])) ('abc'); + eq (S.joinWith (':') ([])) (''); + eq (S.joinWith (':') ([''])) (''); + eq (S.joinWith (':') (['', ''])) (':'); + eq (S.joinWith (':') (['', 'foo', ''])) (':foo:'); + eq (S.joinWith (':') (['foo', 'bar', 'baz'])) ('foo:bar:baz'); + eq (S.joinWith ('::') (['foo', 'bar', 'baz'])) ('foo::bar::baz'); }); diff --git a/test/justs.js b/test/justs.js index b2280f52..2f4f2554 100644 --- a/test/justs.js +++ b/test/justs.js @@ -1,41 +1,41 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var List = require('./internal/List'); -var eq = require('./internal/eq'); +var List = require ('./internal/List'); +var eq = require ('./internal/eq'); var Cons = List.Cons; var Nil = List.Nil; -test('justs', function() { +test ('justs', function() { - eq(typeof S.justs, 'function'); - eq(S.justs.length, 1); - eq(S.justs.toString(), 'justs :: (Filterable f, Functor f) => f (Maybe a) -> f a'); + eq (typeof S.justs) ('function'); + eq (S.justs.length) (1); + eq (String (S.justs)) ('justs :: (Filterable f, Functor f) => f (Maybe a) -> f a'); - eq(S.justs([]), []); - eq(S.justs([S.Nothing, S.Nothing]), []); - eq(S.justs([S.Nothing, S.Just('b')]), ['b']); - eq(S.justs([S.Just('a'), S.Nothing]), ['a']); - eq(S.justs([S.Just('a'), S.Just('b')]), ['a', 'b']); + eq (S.justs ([])) ([]); + eq (S.justs ([S.Nothing, S.Nothing])) ([]); + eq (S.justs ([S.Nothing, S.Just ('b')])) (['b']); + eq (S.justs ([S.Just ('a'), S.Nothing])) (['a']); + eq (S.justs ([S.Just ('a'), S.Just ('b')])) (['a', 'b']); - eq(S.justs({}), {}); - eq(S.justs({x: S.Nothing, y: S.Nothing}), {}); - eq(S.justs({x: S.Nothing, y: S.Just(2)}), {y: 2}); - eq(S.justs({x: S.Just(1), y: S.Nothing}), {x: 1}); - eq(S.justs({x: S.Just(1), y: S.Just(2)}), {x: 1, y: 2}); + eq (S.justs ({})) ({}); + eq (S.justs ({x: S.Nothing, y: S.Nothing})) ({}); + eq (S.justs ({x: S.Nothing, y: S.Just (2)})) ({y: 2}); + eq (S.justs ({x: S.Just (1), y: S.Nothing})) ({x: 1}); + eq (S.justs ({x: S.Just (1), y: S.Just (2)})) ({x: 1, y: 2}); - eq(S.justs(S.Nothing), S.Nothing); - eq(S.justs(S.Just(S.Nothing)), S.Nothing); - eq(S.justs(S.Just(S.Just(1))), S.Just(1)); + eq (S.justs (S.Nothing)) (S.Nothing); + eq (S.justs (S.Just (S.Nothing))) (S.Nothing); + eq (S.justs (S.Just (S.Just (1)))) (S.Just (1)); - eq(S.justs(Nil), Nil); - eq(S.justs(Cons(S.Nothing, Cons(S.Nothing, Nil))), Nil); - eq(S.justs(Cons(S.Nothing, Cons(S.Just(2), Nil))), Cons(2, Nil)); - eq(S.justs(Cons(S.Just(1), Cons(S.Nothing, Nil))), Cons(1, Nil)); - eq(S.justs(Cons(S.Just(1), Cons(S.Just(2), Nil))), Cons(1, Cons(2, Nil))); + eq (S.justs (Nil)) (Nil); + eq (S.justs (Cons (S.Nothing) (Cons (S.Nothing) (Nil)))) (Nil); + eq (S.justs (Cons (S.Nothing) (Cons (S.Just (2)) (Nil)))) (Cons (2) (Nil)); + eq (S.justs (Cons (S.Just (1)) (Cons (S.Nothing) (Nil)))) (Cons (1) (Nil)); + eq (S.justs (Cons (S.Just (1)) (Cons (S.Just (2)) (Nil)))) (Cons (1) (Cons (2) (Nil))); }); diff --git a/test/keys.js b/test/keys.js index 58cfe241..76994045 100644 --- a/test/keys.js +++ b/test/keys.js @@ -1,24 +1,24 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('keys', function() { +test ('keys', function() { - eq(typeof S.keys, 'function'); - eq(S.keys.length, 1); - eq(S.keys.toString(), 'keys :: StrMap a -> Array String'); + eq (typeof S.keys) ('function'); + eq (S.keys.length) (1); + eq (String (S.keys)) ('keys :: StrMap a -> Array String'); - eq(S.sort(S.keys({})), []); - eq(S.sort(S.keys({a: 1, b: 2, c: 3})), ['a', 'b', 'c']); + eq (S.sort (S.keys ({}))) ([]); + eq (S.sort (S.keys ({a: 1, b: 2, c: 3}))) (['a', 'b', 'c']); var proto = {a: 1, b: 2}; - var obj = Object.create(proto); + var obj = Object.create (proto); obj.c = 3; obj.d = 4; - eq(S.sort(S.keys(obj)), ['c', 'd']); + eq (S.sort (S.keys (obj))) (['c', 'd']); }); diff --git a/test/last.js b/test/last.js index 3ba35df4..d50f3b92 100644 --- a/test/last.js +++ b/test/last.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('last', function() { +test ('last', function() { - eq(typeof S.last, 'function'); - eq(S.last.length, 1); - eq(S.last.toString(), 'last :: Array a -> Maybe a'); + eq (typeof S.last) ('function'); + eq (S.last.length) (1); + eq (String (S.last)) ('last :: Array a -> Maybe a'); - eq(S.last([]), S.Nothing); - eq(S.last(['foo']), S.Just('foo')); - eq(S.last(['foo', 'bar']), S.Just('bar')); - eq(S.last(['foo', 'bar', 'baz']), S.Just('baz')); + eq (S.last ([])) (S.Nothing); + eq (S.last (['foo'])) (S.Just ('foo')); + eq (S.last (['foo', 'bar'])) (S.Just ('bar')); + eq (S.last (['foo', 'bar', 'baz'])) (S.Just ('baz')); }); diff --git a/test/lefts.js b/test/lefts.js index 2736aeb9..a48057c6 100644 --- a/test/lefts.js +++ b/test/lefts.js @@ -1,41 +1,41 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var List = require('./internal/List'); -var eq = require('./internal/eq'); +var List = require ('./internal/List'); +var eq = require ('./internal/eq'); var Cons = List.Cons; var Nil = List.Nil; -test('lefts', function() { +test ('lefts', function() { - eq(typeof S.lefts, 'function'); - eq(S.lefts.length, 1); - eq(S.lefts.toString(), 'lefts :: (Filterable f, Functor f) => f (Either a b) -> f a'); + eq (typeof S.lefts) ('function'); + eq (S.lefts.length) (1); + eq (String (S.lefts)) ('lefts :: (Filterable f, Functor f) => f (Either a b) -> f a'); - eq(S.lefts([]), []); - eq(S.lefts([S.Right(2), S.Right(1)]), []); - eq(S.lefts([S.Right(2), S.Left('b')]), ['b']); - eq(S.lefts([S.Left('a'), S.Right(1)]), ['a']); - eq(S.lefts([S.Left('a'), S.Left('b')]), ['a', 'b']); + eq (S.lefts ([])) ([]); + eq (S.lefts ([S.Right (2), S.Right (1)])) ([]); + eq (S.lefts ([S.Right (2), S.Left ('b')])) (['b']); + eq (S.lefts ([S.Left ('a'), S.Right (1)])) (['a']); + eq (S.lefts ([S.Left ('a'), S.Left ('b')])) (['a', 'b']); - eq(S.lefts({}), {}); - eq(S.lefts({x: S.Right(2), y: S.Right(1)}), {}); - eq(S.lefts({x: S.Right(2), y: S.Left('b')}), {y: 'b'}); - eq(S.lefts({x: S.Left('a'), y: S.Right(1)}), {x: 'a'}); - eq(S.lefts({x: S.Left('a'), y: S.Left('b')}), {x: 'a', y: 'b'}); + eq (S.lefts ({})) ({}); + eq (S.lefts ({x: S.Right (2), y: S.Right (1)})) ({}); + eq (S.lefts ({x: S.Right (2), y: S.Left ('b')})) ({y: 'b'}); + eq (S.lefts ({x: S.Left ('a'), y: S.Right (1)})) ({x: 'a'}); + eq (S.lefts ({x: S.Left ('a'), y: S.Left ('b')})) ({x: 'a', y: 'b'}); - eq(S.lefts(S.Nothing), S.Nothing); - eq(S.lefts(S.Just(S.Right(1))), S.Nothing); - eq(S.lefts(S.Just(S.Left('a'))), S.Just('a')); + eq (S.lefts (S.Nothing)) (S.Nothing); + eq (S.lefts (S.Just (S.Right (1)))) (S.Nothing); + eq (S.lefts (S.Just (S.Left ('a')))) (S.Just ('a')); - eq(S.lefts(Nil), Nil); - eq(S.lefts(Cons(S.Right(2), Cons(S.Right(1), Nil))), Nil); - eq(S.lefts(Cons(S.Right(2), Cons(S.Left('b'), Nil))), Cons('b', Nil)); - eq(S.lefts(Cons(S.Left('a'), Cons(S.Right(1), Nil))), Cons('a', Nil)); - eq(S.lefts(Cons(S.Left('a'), Cons(S.Left('b'), Nil))), Cons('a', Cons('b', Nil))); + eq (S.lefts (Nil)) (Nil); + eq (S.lefts (Cons (S.Right (2)) (Cons (S.Right (1)) (Nil)))) (Nil); + eq (S.lefts (Cons (S.Right (2)) (Cons (S.Left ('b')) (Nil)))) (Cons ('b') (Nil)); + eq (S.lefts (Cons (S.Left ('a')) (Cons (S.Right (1)) (Nil)))) (Cons ('a') (Nil)); + eq (S.lefts (Cons (S.Left ('a')) (Cons (S.Left ('b')) (Nil)))) (Cons ('a') (Cons ('b') (Nil))); }); diff --git a/test/lift2.js b/test/lift2.js index d1ab4351..df12a9ab 100644 --- a/test/lift2.js +++ b/test/lift2.js @@ -1,31 +1,31 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('lift2', function() { +test ('lift2', function() { - eq(typeof S.lift2, 'function'); - eq(S.lift2.length, 3); - eq(S.lift2.toString(), 'lift2 :: Apply f => (a -> b -> c) -> f a -> f b -> f c'); + eq (typeof S.lift2) ('function'); + eq (S.lift2.length) (1); + eq (String (S.lift2)) ('lift2 :: Apply f => (a -> b -> c) -> f a -> f b -> f c'); // positive :: Number -> Boolean function positive(n) { return n > 0; } - eq(S.lift2(S.add, S.Just(3), S.Just(3)), S.Just(6)); - eq(S.lift2(S.add, S.Nothing, S.Just(3)), S.Nothing); + eq (S.lift2 (S.add) (S.Just (3)) (S.Just (3))) (S.Just (6)); + eq (S.lift2 (S.add) (S.Nothing) (S.Just (3))) (S.Nothing); - eq(S.lift2(S.add, S.Right(3), S.Left(4)), S.Left(4)); - eq(S.lift2(S.add, S.Right(3), S.Right(4)), S.Right(7)); + eq (S.lift2 (S.add) (S.Right (3)) (S.Left (4))) (S.Left (4)); + eq (S.lift2 (S.add) (S.Right (3)) (S.Right (4))) (S.Right (7)); - eq(S.lift2(S.add, [1, 2], [10, 20]), [11, 21, 12, 22]); - eq(S.lift2(S.add, [], [1, 2]), []); + eq (S.lift2 (S.add) ([1, 2]) ([10, 20])) ([11, 21, 12, 22]); + eq (S.lift2 (S.add) ([]) ([1, 2])) ([]); - eq(S.lift2(S.and, S.even, positive)(42), true); - eq(S.lift2(S.and, S.even, positive)(43), false); - eq(S.lift2(S.and, S.even, positive)(-42), false); - eq(S.lift2(S.and, S.even, positive)(-43), false); + eq (S.lift2 (S.and) (S.even) (positive) (42)) (true); + eq (S.lift2 (S.and) (S.even) (positive) (43)) (false); + eq (S.lift2 (S.and) (S.even) (positive) (-42)) (false); + eq (S.lift2 (S.and) (S.even) (positive) (-43)) (false); }); diff --git a/test/lift3.js b/test/lift3.js index 0eb4555b..d7d2a147 100644 --- a/test/lift3.js +++ b/test/lift3.js @@ -1,26 +1,26 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var area = require('./internal/area'); -var eq = require('./internal/eq'); +var area = require ('./internal/area'); +var eq = require ('./internal/eq'); -test('lift3', function() { +test ('lift3', function() { - eq(typeof S.lift3, 'function'); - eq(S.lift3.length, 4); - eq(S.lift3.toString(), 'lift3 :: Apply f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d'); + eq (typeof S.lift3) ('function'); + eq (S.lift3.length) (1); + eq (String (S.lift3)) ('lift3 :: Apply f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d'); - eq(S.lift3(S.reduce, S.Just(S.add), S.Just(0), S.Just([1, 2, 3])), S.Just(6)); - eq(S.lift3(S.reduce, S.Just(S.add), S.Just(0), S.Nothing), S.Nothing); + eq (S.lift3 (S.reduce) (S.Just (S.add)) (S.Just (0)) (S.Just ([1, 2, 3]))) (S.Just (6)); + eq (S.lift3 (S.reduce) (S.Just (S.add)) (S.Just (0)) (S.Nothing)) (S.Nothing); - eq(S.lift3(S.reduce, S.Right(S.add), S.Right(0), S.Right([1, 2, 3])), S.Right(6)); - eq(S.lift3(S.reduce, S.Right(S.add), S.Right(0), S.Left('WHOOPS')), S.Left('WHOOPS')); + eq (S.lift3 (S.reduce) (S.Right (S.add)) (S.Right (0)) (S.Right ([1, 2, 3]))) (S.Right (6)); + eq (S.lift3 (S.reduce) (S.Right (S.add)) (S.Right (0)) (S.Left ('WHOOPS'))) (S.Left ('WHOOPS')); - eq(S.lift3(S.reduce, [S.add], [0], [[1, 2, 3]]), [6]); - eq(S.lift3(S.reduce, [S.add], [0], []), []); + eq (S.lift3 (S.reduce) ([S.add]) ([0]) ([[1, 2, 3]])) ([6]); + eq (S.lift3 (S.reduce) ([S.add]) ([0]) ([])) ([]); - eq(S.lift3(area, S.sub(1), S.I, S.add(1))(4), 6); + eq (S.lift3 (area) (S.sub (1)) (S.I) (S.add (1)) (4)) (6); }); diff --git a/test/lines.js b/test/lines.js index ca060526..25093f2c 100644 --- a/test/lines.js +++ b/test/lines.js @@ -1,21 +1,21 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('lines', function() { +test ('lines', function() { - eq(typeof S.lines, 'function'); - eq(S.lines.length, 1); - eq(S.lines.toString(), 'lines :: String -> Array String'); + eq (typeof S.lines) ('function'); + eq (S.lines.length) (1); + eq (String (S.lines)) ('lines :: String -> Array String'); - eq(S.lines(''), []); - eq(S.lines('\n'), ['']); - eq(S.lines('\n\n'), ['', '']); - eq(S.lines('foo\nbar\nbaz'), ['foo', 'bar', 'baz']); - eq(S.lines('foo\nbar\nbaz\n'), ['foo', 'bar', 'baz']); - eq(S.lines('\tfoo\r\n\tbar\r\n\tbaz\r\n'), ['\tfoo', '\tbar', '\tbaz']); + eq (S.lines ('')) ([]); + eq (S.lines ('\n')) (['']); + eq (S.lines ('\n\n')) (['', '']); + eq (S.lines ('foo\nbar\nbaz')) (['foo', 'bar', 'baz']); + eq (S.lines ('foo\nbar\nbaz\n')) (['foo', 'bar', 'baz']); + eq (S.lines ('\tfoo\r\n\tbar\r\n\tbaz\r\n')) (['\tfoo', '\tbar', '\tbaz']); }); diff --git a/test/lt.js b/test/lt.js index 230be246..47ff34a5 100644 --- a/test/lt.js +++ b/test/lt.js @@ -1,16 +1,16 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('lt', function() { +test ('lt', function() { - eq(typeof S.lt, 'function'); - eq(S.lt.length, 1); - eq(S.lt.toString(), 'lt :: Ord a => a -> (a -> Boolean)'); + eq (typeof S.lt) ('function'); + eq (S.lt.length) (1); + eq (String (S.lt)) ('lt :: Ord a => a -> a -> Boolean'); - eq(S.filter(S.lt(3), [1, 2, 3, 4, 5]), [1, 2]); + eq (S.filter (S.lt (3)) ([1, 2, 3, 4, 5])) ([1, 2]); }); diff --git a/test/lte.js b/test/lte.js index 2533f382..f2549ad6 100644 --- a/test/lte.js +++ b/test/lte.js @@ -1,16 +1,16 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('lte', function() { +test ('lte', function() { - eq(typeof S.lte, 'function'); - eq(S.lte.length, 1); - eq(S.lte.toString(), 'lte :: Ord a => a -> (a -> Boolean)'); + eq (typeof S.lte) ('function'); + eq (S.lte.length) (1); + eq (String (S.lte)) ('lte :: Ord a => a -> a -> Boolean'); - eq(S.filter(S.lte(3), [1, 2, 3, 4, 5]), [1, 2, 3]); + eq (S.filter (S.lte (3)) ([1, 2, 3, 4, 5])) ([1, 2, 3]); }); diff --git a/test/map.js b/test/map.js index d3e8483a..6a1e0bd5 100644 --- a/test/map.js +++ b/test/map.js @@ -1,29 +1,29 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('map', function() { +test ('map', function() { - eq(typeof S.map, 'function'); - eq(S.map.length, 2); - eq(S.map.toString(), 'map :: Functor f => (a -> b) -> f a -> f b'); + eq (typeof S.map) ('function'); + eq (S.map.length) (1); + eq (String (S.map)) ('map :: Functor f => (a -> b) -> f a -> f b'); - eq(S.map(S.not, S.odd)(2), true); - eq(S.map(S.not, S.odd)(3), false); + eq (S.map (S.not) (S.odd) (2)) (true); + eq (S.map (S.not) (S.odd) (3)) (false); - eq(S.map(S.mult(4), S.Just(2)), S.Just(8)); - eq(S.map(S.mult(4), S.Nothing), S.Nothing); + eq (S.map (S.mult (4)) (S.Just (2))) (S.Just (8)); + eq (S.map (S.mult (4)) (S.Nothing)) (S.Nothing); - eq(S.map(S.mult(4), S.Left(3)), S.Left(3)); - eq(S.map(S.mult(4), S.Right(2)), S.Right(8)); + eq (S.map (S.mult (4)) (S.Left (3))) (S.Left (3)); + eq (S.map (S.mult (4)) (S.Right (2))) (S.Right (8)); - eq(S.map(S.mult(2), [1, 2, 3]), [2, 4, 6]); - eq(S.map(S.mult(2), []), []); + eq (S.map (S.mult (2)) ([1, 2, 3])) ([2, 4, 6]); + eq (S.map (S.mult (2)) ([])) ([]); - eq(S.map(S.mult(2), {a: 1, b: 2, c: 3}), {a: 2, b: 4, c: 6}); - eq(S.map(S.mult(2), {}), {}); + eq (S.map (S.mult (2)) ({a: 1, b: 2, c: 3})) ({a: 2, b: 4, c: 6}); + eq (S.map (S.mult (2)) ({})) ({}); }); diff --git a/test/mapLeft.js b/test/mapLeft.js index 6f4b2fcd..0f98fb7d 100644 --- a/test/mapLeft.js +++ b/test/mapLeft.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('mapLeft', function() { +test ('mapLeft', function() { - eq(typeof S.mapLeft, 'function'); - eq(S.mapLeft.length, 2); - eq(S.mapLeft.toString(), 'mapLeft :: Bifunctor p => (a -> b) -> p a c -> p b c'); + eq (typeof S.mapLeft) ('function'); + eq (S.mapLeft.length) (1); + eq (String (S.mapLeft)) ('mapLeft :: Bifunctor p => (a -> b) -> p a c -> p b c'); - eq(S.mapLeft(S.toUpper, S.Left('xxx')), S.Left('XXX')); - eq(S.mapLeft(S.toUpper, S.Right(1000)), S.Right(1000)); + eq (S.mapLeft (S.toUpper) (S.Left ('xxx'))) (S.Left ('XXX')); + eq (S.mapLeft (S.toUpper) (S.Right (1000))) (S.Right (1000)); }); diff --git a/test/mapMaybe.js b/test/mapMaybe.js index 8c958081..b5e55d29 100644 --- a/test/mapMaybe.js +++ b/test/mapMaybe.js @@ -1,38 +1,42 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var List = require('./internal/List'); -var eq = require('./internal/eq'); +var List = require ('./internal/List'); +var eq = require ('./internal/eq'); var Cons = List.Cons; var Nil = List.Nil; -test('mapMaybe', function() { +test ('mapMaybe', function() { - eq(typeof S.mapMaybe, 'function'); - eq(S.mapMaybe.length, 2); - eq(S.mapMaybe.toString(), 'mapMaybe :: (Filterable f, Functor f) => (a -> Maybe b) -> f a -> f b'); + eq (typeof S.mapMaybe) ('function'); + eq (S.mapMaybe.length) (1); + eq (String (S.mapMaybe)) ('mapMaybe :: (Filterable f, Functor f) => (a -> Maybe b) -> f a -> f b'); - eq(S.mapMaybe(S.head, []), []); - eq(S.mapMaybe(S.head, [[], [], []]), []); - eq(S.mapMaybe(S.head, [[1, 2], [3, 4], [5, 6]]), [1, 3, 5]); - eq(S.mapMaybe(S.head, [[1], [], [3], [], [5], []]), [1, 3, 5]); + eq (S.mapMaybe (S.head) ([])) ([]); + eq (S.mapMaybe (S.head) ([[], [], []])) ([]); + eq (S.mapMaybe (S.head) ([[1, 2], [3, 4], [5, 6]])) ([1, 3, 5]); + eq (S.mapMaybe (S.head) ([[1], [], [3], [], [5], []])) ([1, 3, 5]); - eq(S.mapMaybe(S.head, {}), {}); - eq(S.mapMaybe(S.head, {a: [], b: [], c: []}), {}); - eq(S.mapMaybe(S.head, {a: [1, 2], b: [3, 4], c: [5, 6]}), {a: 1, b: 3, c: 5}); - eq(S.mapMaybe(S.head, {a: [1], b: [], c: [3], d: [], e: [5], f: []}), {a: 1, c: 3, e: 5}); + eq (S.mapMaybe (S.head) ({})) ({}); + eq (S.mapMaybe (S.head) ({a: [], b: [], c: []})) ({}); + eq (S.mapMaybe (S.head) ({a: [1, 2], b: [3, 4], c: [5, 6]})) ({a: 1, b: 3, c: 5}); + eq (S.mapMaybe (S.head) ({a: [1], b: [], c: [3], d: [], e: [5], f: []})) ({a: 1, c: 3, e: 5}); - eq(S.mapMaybe(S.head, S.Nothing), S.Nothing); - eq(S.mapMaybe(S.head, S.Just([])), S.Nothing); - eq(S.mapMaybe(S.head, S.Just([1, 2])), S.Just(1)); + eq (S.mapMaybe (S.head) (S.Nothing)) (S.Nothing); + eq (S.mapMaybe (S.head) (S.Just ([]))) (S.Nothing); + eq (S.mapMaybe (S.head) (S.Just ([1, 2]))) (S.Just (1)); - eq(S.mapMaybe(S.head, Nil), Nil); - eq(S.mapMaybe(S.head, Cons([], Cons([], Cons([], Nil)))), Nil); - eq(S.mapMaybe(S.head, Cons([1, 2], Cons([3, 4], Cons([5, 6], Nil)))), Cons(1, Cons(3, Cons(5, Nil)))); - eq(S.mapMaybe(S.head, Cons([1], Cons([], Cons([3], Cons([], Cons([5], Cons([], Nil))))))), Cons(1, Cons(3, Cons(5, Nil)))); + eq (S.mapMaybe (S.head) (Nil)) + (Nil); + eq (S.mapMaybe (S.head) (Cons ([]) (Cons ([]) (Cons ([]) (Nil))))) + (Nil); + eq (S.mapMaybe (S.head) (Cons ([1, 2]) (Cons ([3, 4]) (Cons ([5, 6]) (Nil))))) + (Cons (1) (Cons (3) (Cons (5) (Nil)))); + eq (S.mapMaybe (S.head) (Cons ([1]) (Cons ([]) (Cons ([3]) (Cons ([]) (Cons ([5]) (Cons ([]) (Nil)))))))) + (Cons (1) (Cons (3) (Cons (5) (Nil)))); }); diff --git a/test/match.js b/test/match.js index 79a1cc47..791a54a1 100644 --- a/test/match.js +++ b/test/match.js @@ -1,41 +1,41 @@ 'use strict'; -var jsc = require('jsverify'); +var jsc = require ('jsverify'); -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var equals = require('./internal/equals'); +var eq = require ('./internal/eq'); +var equals = require ('./internal/equals'); -test('match', function() { +test ('match', function() { - eq(typeof S.match, 'function'); - eq(S.match.length, 2); - eq(S.match.toString(), 'match :: NonGlobalRegExp -> String -> Maybe { groups :: Array (Maybe String), match :: String }'); + eq (typeof S.match) ('function'); + eq (S.match.length) (1); + eq (String (S.match)) ('match :: NonGlobalRegExp -> String -> Maybe { groups :: Array (Maybe String), match :: String }'); var scheme = '([a-z][a-z0-9+.-]*)'; var authentication = '(.*?):(.*?)@'; var hostname = '(.*?)'; var port = ':([0-9]*)'; - var pattern = S.regex('', scheme + '://(?:' + authentication + ')?' + hostname + '(?:' + port + ')?(?!\\S)'); + var pattern = S.regex ('') (scheme + '://(?:' + authentication + ')?' + hostname + '(?:' + port + ')?(?!\\S)'); - eq(S.match(pattern, 'URL: N/A'), - S.Nothing); + eq (S.match (pattern) ('URL: N/A')) + (S.Nothing); - eq(S.match(pattern, 'URL: http://example.com'), - S.Just({match: 'http://example.com', - groups: [S.Just('http'), S.Nothing, S.Nothing, S.Just('example.com'), S.Nothing]})); + eq (S.match (pattern) ('URL: http://example.com')) + (S.Just ({match: 'http://example.com', + groups: [S.Just ('http'), S.Nothing, S.Nothing, S.Just ('example.com'), S.Nothing]})); - eq(S.match(pattern, 'URL: http://user:pass@example.com:80'), - S.Just({match: 'http://user:pass@example.com:80', - groups: [S.Just('http'), S.Just('user'), S.Just('pass'), S.Just('example.com'), S.Just('80')]})); + eq (S.match (pattern) ('URL: http://user:pass@example.com:80')) + (S.Just ({match: 'http://user:pass@example.com:80', + groups: [S.Just ('http'), S.Just ('user'), S.Just ('pass'), S.Just ('example.com'), S.Just ('80')]})); - jsc.assert(jsc.forall(jsc.string, function(s) { + jsc.assert (jsc.forall (jsc.string, function(s) { var p = '([A-Za-z]+)'; - var lhs = S.head(S.matchAll(S.regex('g', p), s)); - var rhs = S.match(S.regex('', p), s); - return equals(lhs)(rhs); + var lhs = S.head (S.matchAll (S.regex ('g') (p)) (s)); + var rhs = S.match (S.regex ('') (p)) (s); + return equals (lhs) (rhs); }), {tests: 1000}); }); diff --git a/test/matchAll.js b/test/matchAll.js index 233a37ce..760aecc5 100644 --- a/test/matchAll.js +++ b/test/matchAll.js @@ -1,25 +1,25 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('matchAll', function() { +test ('matchAll', function() { - eq(typeof S.matchAll, 'function'); - eq(S.matchAll.length, 2); - eq(S.matchAll.toString(), 'matchAll :: GlobalRegExp -> String -> Array { groups :: Array (Maybe String), match :: String }'); + eq (typeof S.matchAll) ('function'); + eq (S.matchAll.length) (1); + eq (String (S.matchAll)) ('matchAll :: GlobalRegExp -> String -> Array { groups :: Array (Maybe String), match :: String }'); - var pattern = S.regex('g', '<(h[1-6])(?: id="([^"]*)")?>([^<]*)'); + var pattern = S.regex ('g') ('<(h[1-6])(?: id="([^"]*)")?>([^<]*)'); - eq(S.matchAll(pattern, ''), []); + eq (S.matchAll (pattern) ('')) ([]); - eq(S.matchAll(pattern, '

Foo

\n

Bar

\n

Baz

\n'), - [{match: '

Foo

', groups: [S.Just('h1'), S.Nothing, S.Just('Foo')]}, - {match: '

Bar

', groups: [S.Just('h2'), S.Just('bar'), S.Just('Bar')]}, - {match: '

Baz

', groups: [S.Just('h2'), S.Just('baz'), S.Just('Baz')]}]); + eq (S.matchAll (pattern) ('

Foo

\n

Bar

\n

Baz

\n')) + ([{match: '

Foo

', groups: [S.Just ('h1'), S.Nothing, S.Just ('Foo')]}, + {match: '

Bar

', groups: [S.Just ('h2'), S.Just ('bar'), S.Just ('Bar')]}, + {match: '

Baz

', groups: [S.Just ('h2'), S.Just ('baz'), S.Just ('Baz')]}]); - eq(pattern.lastIndex, 0); + eq (pattern.lastIndex) (0); }); diff --git a/test/max.js b/test/max.js index a0e61375..2d6b1c37 100644 --- a/test/max.js +++ b/test/max.js @@ -1,31 +1,31 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('max', function() { +test ('max', function() { - eq(typeof S.max, 'function'); - eq(S.max.length, 2); - eq(S.max.toString(), 'max :: Ord a => a -> a -> a'); + eq (typeof S.max) ('function'); + eq (S.max.length) (1); + eq (String (S.max)) ('max :: Ord a => a -> a -> a'); - eq(S.max(10, 2), 10); - eq(S.max(2, 10), 10); - eq(S.max(0.1, 0.01), 0.1); - eq(S.max(0.01, 0.1), 0.1); - eq(S.max(Infinity, -Infinity), Infinity); - eq(S.max(-Infinity, Infinity), Infinity); + eq (S.max (10) (2)) (10); + eq (S.max (2) (10)) (10); + eq (S.max (0.1) (0.01)) (0.1); + eq (S.max (0.01) (0.1)) (0.1); + eq (S.max (Infinity) (-Infinity)) (Infinity); + eq (S.max (-Infinity) (Infinity)) (Infinity); - eq(S.max(new Date(10), new Date(2)), new Date(10)); - eq(S.max(new Date(2), new Date(10)), new Date(10)); + eq (S.max (new Date (10)) (new Date (2))) (new Date (10)); + eq (S.max (new Date (2)) (new Date (10))) (new Date (10)); - eq(S.max('abc', 'xyz'), 'xyz'); - eq(S.max('xyz', 'abc'), 'xyz'); - eq(S.max('10', '2'), '2'); - eq(S.max('2', '10'), '2'); - eq(S.max('A', 'a'), 'a'); - eq(S.max('a', 'A'), 'a'); + eq (S.max ('abc') ('xyz')) ('xyz'); + eq (S.max ('xyz') ('abc')) ('xyz'); + eq (S.max ('10') ('2')) ('2'); + eq (S.max ('2') ('10')) ('2'); + eq (S.max ('A') ('a')) ('a'); + eq (S.max ('a') ('A')) ('a'); }); diff --git a/test/maybe.js b/test/maybe.js index dcc9949d..daf970d6 100644 --- a/test/maybe.js +++ b/test/maybe.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('maybe', function() { +test ('maybe', function() { - eq(typeof S.maybe, 'function'); - eq(S.maybe.length, 3); - eq(S.maybe.toString(), 'maybe :: b -> (a -> b) -> Maybe a -> b'); + eq (typeof S.maybe) ('function'); + eq (S.maybe.length) (1); + eq (String (S.maybe)) ('maybe :: b -> (a -> b) -> Maybe a -> b'); - eq(S.maybe(0, Math.sqrt, S.Nothing), 0); - eq(S.maybe(0, Math.sqrt, S.Just(9)), 3); + eq (S.maybe (0) (Math.sqrt) (S.Nothing)) (0); + eq (S.maybe (0) (Math.sqrt) (S.Just (9))) (3); }); diff --git a/test/maybeToEither.js b/test/maybeToEither.js index d62c84cc..603655d6 100644 --- a/test/maybeToEither.js +++ b/test/maybeToEither.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('maybeToEither', function() { +test ('maybeToEither', function() { - eq(typeof S.maybeToEither, 'function'); - eq(S.maybeToEither.length, 2); - eq(S.maybeToEither.toString(), 'maybeToEither :: a -> Maybe b -> Either a b'); + eq (typeof S.maybeToEither) ('function'); + eq (S.maybeToEither.length) (1); + eq (String (S.maybeToEither)) ('maybeToEither :: a -> Maybe b -> Either a b'); - eq(S.maybeToEither('error msg', S.Nothing), S.Left('error msg')); - eq(S.maybeToEither('error msg', S.Just(42)), S.Right(42)); + eq (S.maybeToEither ('error msg') (S.Nothing)) (S.Left ('error msg')); + eq (S.maybeToEither ('error msg') (S.Just (42))) (S.Right (42)); }); diff --git a/test/maybeToNullable.js b/test/maybeToNullable.js index f81cf486..7a4d47c3 100644 --- a/test/maybeToNullable.js +++ b/test/maybeToNullable.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('maybeToNullable', function() { +test ('maybeToNullable', function() { - eq(typeof S.maybeToNullable, 'function'); - eq(S.maybeToNullable.length, 1); - eq(S.maybeToNullable.toString(), 'maybeToNullable :: Maybe a -> Nullable a'); + eq (typeof S.maybeToNullable) ('function'); + eq (S.maybeToNullable.length) (1); + eq (String (S.maybeToNullable)) ('maybeToNullable :: Maybe a -> Nullable a'); - eq(S.maybeToNullable(S.Nothing), null); - eq(S.maybeToNullable(S.Just(42)), 42); + eq (S.maybeToNullable (S.Nothing)) (null); + eq (S.maybeToNullable (S.Just (42))) (42); }); diff --git a/test/maybe_.js b/test/maybe_.js index ccaa66cd..6e900345 100644 --- a/test/maybe_.js +++ b/test/maybe_.js @@ -1,22 +1,22 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var factorial = require('./internal/factorial'); +var eq = require ('./internal/eq'); +var factorial = require ('./internal/factorial'); -test('maybe_', function() { +test ('maybe_', function() { - eq(typeof S.maybe_, 'function'); - eq(S.maybe_.length, 3); - eq(S.maybe_.toString(), 'maybe_ :: (() -> b) -> (a -> b) -> Maybe a -> b'); + eq (typeof S.maybe_) ('function'); + eq (S.maybe_.length) (1); + eq (String (S.maybe_)) ('maybe_ :: (() -> b) -> (a -> b) -> Maybe a -> b'); - eq(S.maybe_(function() { return factorial(10); }, Math.sqrt, S.Nothing), 3628800); - eq(S.maybe_(function() { return factorial(10); }, Math.sqrt, S.Just(9)), 3); + eq (S.maybe_ (function() { return factorial (10); }) (Math.sqrt) (S.Nothing)) (3628800); + eq (S.maybe_ (function() { return factorial (10); }) (Math.sqrt) (S.Just (9))) (3); var count = 0; - eq(S.maybe_(function() { return count += 1; }, Math.sqrt, S.Just(9)), 3); - eq(count, 0); + eq (S.maybe_ (function() { return count += 1; }) (Math.sqrt) (S.Just (9))) (3); + eq (count) (0); }); diff --git a/test/mean.js b/test/mean.js index 91ab6b63..2306abe9 100644 --- a/test/mean.js +++ b/test/mean.js @@ -1,24 +1,24 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('mean', function() { +test ('mean', function() { - eq(typeof S.mean, 'function'); - eq(S.mean.length, 1); - eq(S.mean.toString(), 'mean :: Foldable f => f FiniteNumber -> Maybe FiniteNumber'); + eq (typeof S.mean) ('function'); + eq (S.mean.length) (1); + eq (String (S.mean)) ('mean :: Foldable f => f FiniteNumber -> Maybe FiniteNumber'); - eq(S.mean([]), S.Nothing); - eq(S.mean([1, 2, 3]), S.Just(2)); - eq(S.mean([0.1, 0.3]), S.Just(0.2)); + eq (S.mean ([])) (S.Nothing); + eq (S.mean ([1, 2, 3])) (S.Just (2)); + eq (S.mean ([0.1, 0.3])) (S.Just (0.2)); - eq(S.mean(S.Nothing), S.Nothing); - eq(S.mean(S.Just(42)), S.Just(42)); + eq (S.mean (S.Nothing)) (S.Nothing); + eq (S.mean (S.Just (42))) (S.Just (42)); - eq(S.mean(S.Left('xxx')), S.Nothing); - eq(S.mean(S.Right(42)), S.Just(42)); + eq (S.mean (S.Left ('xxx'))) (S.Nothing); + eq (S.mean (S.Right (42))) (S.Just (42)); }); diff --git a/test/min.js b/test/min.js index 206b782b..a8c430ed 100644 --- a/test/min.js +++ b/test/min.js @@ -1,31 +1,31 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('min', function() { +test ('min', function() { - eq(typeof S.min, 'function'); - eq(S.min.length, 2); - eq(S.min.toString(), 'min :: Ord a => a -> a -> a'); + eq (typeof S.min) ('function'); + eq (S.min.length) (1); + eq (String (S.min)) ('min :: Ord a => a -> a -> a'); - eq(S.min(10, 2), 2); - eq(S.min(2, 10), 2); - eq(S.min(0.1, 0.01), 0.01); - eq(S.min(0.01, 0.1), 0.01); - eq(S.min(Infinity, -Infinity), -Infinity); - eq(S.min(-Infinity, Infinity), -Infinity); + eq (S.min (10) (2)) (2); + eq (S.min (2) (10)) (2); + eq (S.min (0.1) (0.01)) (0.01); + eq (S.min (0.01) (0.1)) (0.01); + eq (S.min (Infinity) (-Infinity)) (-Infinity); + eq (S.min (-Infinity) (Infinity)) (-Infinity); - eq(S.min(new Date(10), new Date(2)), new Date(2)); - eq(S.min(new Date(2), new Date(10)), new Date(2)); + eq (S.min (new Date (10)) (new Date (2))) (new Date (2)); + eq (S.min (new Date (2)) (new Date (10))) (new Date (2)); - eq(S.min('abc', 'xyz'), 'abc'); - eq(S.min('xyz', 'abc'), 'abc'); - eq(S.min('10', '2'), '10'); - eq(S.min('2', '10'), '10'); - eq(S.min('A', 'a'), 'A'); - eq(S.min('a', 'A'), 'A'); + eq (S.min ('abc') ('xyz')) ('abc'); + eq (S.min ('xyz') ('abc')) ('abc'); + eq (S.min ('10') ('2')) ('10'); + eq (S.min ('2') ('10')) ('10'); + eq (S.min ('A') ('a')) ('A'); + eq (S.min ('a') ('A')) ('A'); }); diff --git a/test/mult.js b/test/mult.js index d3379ca4..0ebba5b4 100644 --- a/test/mult.js +++ b/test/mult.js @@ -1,21 +1,21 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('mult', function() { +test ('mult', function() { - eq(typeof S.mult, 'function'); - eq(S.mult.length, 2); - eq(S.mult.toString(), 'mult :: FiniteNumber -> FiniteNumber -> FiniteNumber'); + eq (typeof S.mult) ('function'); + eq (S.mult.length) (1); + eq (String (S.mult)) ('mult :: FiniteNumber -> FiniteNumber -> FiniteNumber'); - eq(S.mult(4, 2), 8); - eq(S.mult(4, -2), -8); - eq(S.mult(-4, -2), 8); - eq(S.mult(1.5, 3), 4.5); - eq(S.mult(-1.5, 3), -4.5); - eq(S.mult(-1.5, -3), 4.5); + eq (S.mult (4) (2)) (8); + eq (S.mult (4) (-2)) (-8); + eq (S.mult (-4) (-2)) (8); + eq (S.mult (1.5) (3)) (4.5); + eq (S.mult (-1.5) (3)) (-4.5); + eq (S.mult (-1.5) (-3)) (4.5); }); diff --git a/test/negate.js b/test/negate.js index 79d821a6..006103c8 100644 --- a/test/negate.js +++ b/test/negate.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('negate', function() { +test ('negate', function() { - eq(typeof S.negate, 'function'); - eq(S.negate.length, 1); - eq(S.negate.toString(), 'negate :: ValidNumber -> ValidNumber'); + eq (typeof S.negate) ('function'); + eq (S.negate.length) (1); + eq (String (S.negate)) ('negate :: ValidNumber -> ValidNumber'); - eq(S.negate(0.5), -0.5); - eq(S.negate(-0.5), 0.5); + eq (S.negate (0.5)) (-0.5); + eq (S.negate (-0.5)) (0.5); }); diff --git a/test/not.js b/test/not.js index 11e7c399..f9cc23c8 100644 --- a/test/not.js +++ b/test/not.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('not', function() { +test ('not', function() { - eq(typeof S.not, 'function'); - eq(S.not.length, 1); - eq(S.not.toString(), 'not :: Boolean -> Boolean'); + eq (typeof S.not) ('function'); + eq (S.not.length) (1); + eq (String (S.not)) ('not :: Boolean -> Boolean'); - eq(S.not(false), true); - eq(S.not(true), false); + eq (S.not (false)) (true); + eq (S.not (true)) (false); }); diff --git a/test/odd.js b/test/odd.js index ba18903a..bf28c952 100644 --- a/test/odd.js +++ b/test/odd.js @@ -1,21 +1,21 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('odd', function() { +test ('odd', function() { - eq(typeof S.odd, 'function'); - eq(S.odd.length, 1); - eq(S.odd.toString(), 'odd :: Integer -> Boolean'); + eq (typeof S.odd) ('function'); + eq (S.odd.length) (1); + eq (String (S.odd)) ('odd :: Integer -> Boolean'); - eq(S.odd(1), true); - eq(S.odd(-1), true); + eq (S.odd (1)) (true); + eq (S.odd (-1)) (true); - eq(S.odd(0), false); - eq(S.odd(2), false); - eq(S.odd(-2), false); + eq (S.odd (0)) (false); + eq (S.odd (2)) (false); + eq (S.odd (-2)) (false); }); diff --git a/test/of.js b/test/of.js index 46671a0e..6d64ca51 100644 --- a/test/of.js +++ b/test/of.js @@ -1,21 +1,21 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var Identity = require('./internal/Identity'); -var eq = require('./internal/eq'); +var Identity = require ('./internal/Identity'); +var eq = require ('./internal/eq'); -test('of', function() { +test ('of', function() { - eq(typeof S.of, 'function'); - eq(S.of.length, 2); - eq(S.of.toString(), 'of :: Applicative f => TypeRep f -> a -> f a'); + eq (typeof S.of) ('function'); + eq (S.of.length) (1); + eq (String (S.of)) ('of :: Applicative f => TypeRep f -> a -> f a'); - eq(S.of(Array, 42), [42]); - eq(S.of(Function, 42)(null), 42); - eq(S.of(S.Maybe, 42), S.Just(42)); - eq(S.of(S.Either, 42), S.Right(42)); - eq(S.of(Identity, 42), Identity(42)); + eq (S.of (Array) (42)) ([42]); + eq (S.of (Function) (42) (null)) (42); + eq (S.of (S.Maybe) (42)) (S.Just (42)); + eq (S.of (S.Either) (42)) (S.Right (42)); + eq (S.of (Identity) (42)) (Identity (42)); }); diff --git a/test/on.js b/test/on.js index e15e1c2f..1c858159 100644 --- a/test/on.js +++ b/test/on.js @@ -1,18 +1,18 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var rem = require('./internal/rem'); +var eq = require ('./internal/eq'); +var rem = require ('./internal/rem'); -test('on', function() { +test ('on', function() { - eq(typeof S.on, 'function'); - eq(S.on.length, 4); - eq(S.on.toString(), 'on :: (b -> b -> c) -> (a -> b) -> a -> a -> c'); + eq (typeof S.on) ('function'); + eq (S.on.length) (1); + eq (String (S.on)) ('on :: (b -> b -> c) -> (a -> b) -> a -> a -> c'); - eq(S.on(rem, S.prop('x'), {x: 5, y: 5}, {x: 3, y: 3}), 2); - eq(S.on(S.concat, S.reverse)([1, 2, 3], [4, 5, 6]), [3, 2, 1, 6, 5, 4]); + eq (S.on (rem) (S.prop ('x')) ({x: 5, y: 5}) ({x: 3, y: 3})) (2); + eq (S.on (S.concat) (S.reverse) ([1, 2, 3]) ([4, 5, 6])) ([3, 2, 1, 6, 5, 4]); }); diff --git a/test/or.js b/test/or.js index 07d5cf9f..8b95c0d7 100644 --- a/test/or.js +++ b/test/or.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('or', function() { +test ('or', function() { - eq(typeof S.or, 'function'); - eq(S.or.length, 2); - eq(S.or.toString(), 'or :: Boolean -> Boolean -> Boolean'); + eq (typeof S.or) ('function'); + eq (S.or.length) (1); + eq (String (S.or)) ('or :: Boolean -> Boolean -> Boolean'); - eq(S.or(false, false), false); - eq(S.or(false, true), true); - eq(S.or(true, false), true); - eq(S.or(true, true), true); + eq (S.or (false) (false)) (false); + eq (S.or (false) (true)) (true); + eq (S.or (true) (false)) (true); + eq (S.or (true) (true)) (true); }); diff --git a/test/pairs.js b/test/pairs.js index 0481f188..74a192aa 100644 --- a/test/pairs.js +++ b/test/pairs.js @@ -1,24 +1,24 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('pairs', function() { +test ('pairs', function() { - eq(typeof S.pairs, 'function'); - eq(S.pairs.length, 1); - eq(S.pairs.toString(), 'pairs :: StrMap a -> Array (Pair String a)'); + eq (typeof S.pairs) ('function'); + eq (S.pairs.length) (1); + eq (String (S.pairs)) ('pairs :: StrMap a -> Array (Array2 String a)'); - eq(S.sort(S.pairs({})), []); - eq(S.sort(S.pairs({a: 1, b: 2, c: 3})), [['a', 1], ['b', 2], ['c', 3]]); + eq (S.sort (S.pairs ({}))) ([]); + eq (S.sort (S.pairs ({a: 1, b: 2, c: 3}))) ([['a', 1], ['b', 2], ['c', 3]]); var proto = {a: 1, b: 2}; - var obj = Object.create(proto); + var obj = Object.create (proto); obj.c = 3; obj.d = 4; - eq(S.sort(S.pairs(obj)), [['c', 3], ['d', 4]]); + eq (S.sort (S.pairs (obj))) ([['c', 3], ['d', 4]]); }); diff --git a/test/parseDate.js b/test/parseDate.js index ef1a81a3..411f6443 100644 --- a/test/parseDate.js +++ b/test/parseDate.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('parseDate', function() { +test ('parseDate', function() { - eq(typeof S.parseDate, 'function'); - eq(S.parseDate.length, 1); - eq(S.parseDate.toString(), 'parseDate :: String -> Maybe ValidDate'); + eq (typeof S.parseDate) ('function'); + eq (S.parseDate.length) (1); + eq (String (S.parseDate)) ('parseDate :: String -> Maybe ValidDate'); - eq(S.parseDate('2001-02-03T04:05:06Z'), S.Just(new Date('2001-02-03T04:05:06Z'))); - eq(S.parseDate('today'), S.Nothing); + eq (S.parseDate ('2001-02-03T04:05:06Z')) (S.Just (new Date ('2001-02-03T04:05:06Z'))); + eq (S.parseDate ('today')) (S.Nothing); }); diff --git a/test/parseFloat.js b/test/parseFloat.js index b75ba954..9f153e8d 100644 --- a/test/parseFloat.js +++ b/test/parseFloat.js @@ -1,45 +1,45 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('parseFloat', function() { +test ('parseFloat', function() { - eq(typeof S.parseFloat, 'function'); - eq(S.parseFloat.length, 1); - eq(S.parseFloat.toString(), 'parseFloat :: String -> Maybe Number'); + eq (typeof S.parseFloat) ('function'); + eq (S.parseFloat.length) (1); + eq (String (S.parseFloat)) ('parseFloat :: String -> Maybe Number'); - eq(S.parseFloat('12.34'), S.Just(12.34)); - eq(S.parseFloat('Infinity'), S.Just(Infinity)); - eq(S.parseFloat('-Infinity'), S.Just(-Infinity)); - eq(S.parseFloat('NaN'), S.Just(NaN)); - eq(S.parseFloat('-NaN'), S.Just(NaN)); // Haskell accepts "-NaN" - eq(S.parseFloat('0'), S.Just(0)); - eq(S.parseFloat('-0'), S.Just(-0)); - eq(S.parseFloat('42'), S.Just(42)); - eq(S.parseFloat('42.'), S.Just(42)); - eq(S.parseFloat('0.5'), S.Just(0.5)); - eq(S.parseFloat('.25'), S.Just(0.25)); - eq(S.parseFloat('+42'), S.Just(42)); - eq(S.parseFloat('+42.'), S.Just(42)); - eq(S.parseFloat('+0.5'), S.Just(0.5)); - eq(S.parseFloat('+.25'), S.Just(0.25)); - eq(S.parseFloat('-42'), S.Just(-42)); - eq(S.parseFloat('-42.'), S.Just(-42)); - eq(S.parseFloat('-0.5'), S.Just(-0.5)); - eq(S.parseFloat('-.25'), S.Just(-0.25)); - eq(S.parseFloat('0.5 '), S.Just(0.5)); - eq(S.parseFloat(' 0.5'), S.Just(0.5)); - eq(S.parseFloat('0.5x'), S.Nothing); // parseFloat('0.5x') == 0.25 - eq(S.parseFloat('x0.5'), S.Nothing); - eq(S.parseFloat('-1e3'), S.Just(-1000)); - eq(S.parseFloat('-1e03'), S.Just(-1000)); - eq(S.parseFloat('-1e+3'), S.Just(-1000)); - eq(S.parseFloat('-1e+03'), S.Just(-1000)); - eq(S.parseFloat('-1e-3'), S.Just(-0.001)); - eq(S.parseFloat('-1e-03'), S.Just(-0.001)); - eq(S.parseFloat('xxx'), S.Nothing); + eq (S.parseFloat ('12.34')) (S.Just (12.34)); + eq (S.parseFloat ('Infinity')) (S.Just (Infinity)); + eq (S.parseFloat ('-Infinity')) (S.Just (-Infinity)); + eq (S.parseFloat ('NaN')) (S.Just (NaN)); + eq (S.parseFloat ('-NaN')) (S.Just (NaN)); // Haskell accepts "-NaN" + eq (S.parseFloat ('0')) (S.Just (0)); + eq (S.parseFloat ('-0')) (S.Just (-0)); + eq (S.parseFloat ('42')) (S.Just (42)); + eq (S.parseFloat ('42.')) (S.Just (42)); + eq (S.parseFloat ('0.5')) (S.Just (0.5)); + eq (S.parseFloat ('.25')) (S.Just (0.25)); + eq (S.parseFloat ('+42')) (S.Just (42)); + eq (S.parseFloat ('+42.')) (S.Just (42)); + eq (S.parseFloat ('+0.5')) (S.Just (0.5)); + eq (S.parseFloat ('+.25')) (S.Just (0.25)); + eq (S.parseFloat ('-42')) (S.Just (-42)); + eq (S.parseFloat ('-42.')) (S.Just (-42)); + eq (S.parseFloat ('-0.5')) (S.Just (-0.5)); + eq (S.parseFloat ('-.25')) (S.Just (-0.25)); + eq (S.parseFloat ('0.5 ')) (S.Just (0.5)); + eq (S.parseFloat (' 0.5')) (S.Just (0.5)); + eq (S.parseFloat ('0.5x')) (S.Nothing); // parseFloat ('0.5x') == 0.5 + eq (S.parseFloat ('x0.5')) (S.Nothing); + eq (S.parseFloat ('-1e3')) (S.Just (-1000)); + eq (S.parseFloat ('-1e03')) (S.Just (-1000)); + eq (S.parseFloat ('-1e+3')) (S.Just (-1000)); + eq (S.parseFloat ('-1e+03')) (S.Just (-1000)); + eq (S.parseFloat ('-1e-3')) (S.Just (-0.001)); + eq (S.parseFloat ('-1e-03')) (S.Just (-0.001)); + eq (S.parseFloat ('xxx')) (S.Nothing); }); diff --git a/test/parseInt.js b/test/parseInt.js index e586f808..363ce2a9 100644 --- a/test/parseInt.js +++ b/test/parseInt.js @@ -1,151 +1,149 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var throws = require('./internal/throws'); +var eq = require ('./internal/eq'); +var throws = require ('./internal/throws'); -test('parseInt', function() { +test ('parseInt', function() { - eq(typeof S.parseInt, 'function'); - eq(S.parseInt.length, 2); - eq(S.parseInt.toString(), 'parseInt :: Radix -> String -> Maybe Integer'); + eq (typeof S.parseInt) ('function'); + eq (S.parseInt.length) (1); + eq (String (S.parseInt)) ('parseInt :: Radix -> String -> Maybe Integer'); - eq(S.parseInt(10, '42'), S.Just(42)); - eq(S.parseInt(16, '2A'), S.Just(42)); - eq(S.parseInt(10, 'NaN'), S.Nothing); - eq(S.parseInt(10, 'xxx'), S.Nothing); + eq (S.parseInt (10) ('42')) (S.Just (42)); + eq (S.parseInt (16) ('2A')) (S.Just (42)); + eq (S.parseInt (10) ('NaN')) (S.Nothing); + eq (S.parseInt (10) ('xxx')) (S.Nothing); // Accepts radix in [2 .. 36] - eq(S.parseInt(2, '1'), S.Just(1)); - eq(S.parseInt(2, '2'), S.Nothing); - eq(S.parseInt(3, '2'), S.Just(2)); - eq(S.parseInt(3, '3'), S.Nothing); - eq(S.parseInt(4, '3'), S.Just(3)); - eq(S.parseInt(4, '4'), S.Nothing); - eq(S.parseInt(5, '4'), S.Just(4)); - eq(S.parseInt(5, '5'), S.Nothing); - eq(S.parseInt(6, '5'), S.Just(5)); - eq(S.parseInt(6, '6'), S.Nothing); - eq(S.parseInt(7, '6'), S.Just(6)); - eq(S.parseInt(7, '7'), S.Nothing); - eq(S.parseInt(8, '7'), S.Just(7)); - eq(S.parseInt(8, '8'), S.Nothing); - eq(S.parseInt(9, '8'), S.Just(8)); - eq(S.parseInt(9, '9'), S.Nothing); - eq(S.parseInt(10, '9'), S.Just(9)); - eq(S.parseInt(10, 'A'), S.Nothing); - eq(S.parseInt(11, 'A'), S.Just(10)); - eq(S.parseInt(11, 'B'), S.Nothing); - eq(S.parseInt(12, 'B'), S.Just(11)); - eq(S.parseInt(12, 'C'), S.Nothing); - eq(S.parseInt(13, 'C'), S.Just(12)); - eq(S.parseInt(13, 'D'), S.Nothing); - eq(S.parseInt(14, 'D'), S.Just(13)); - eq(S.parseInt(14, 'E'), S.Nothing); - eq(S.parseInt(15, 'E'), S.Just(14)); - eq(S.parseInt(15, 'F'), S.Nothing); - eq(S.parseInt(16, 'F'), S.Just(15)); - eq(S.parseInt(16, 'G'), S.Nothing); - eq(S.parseInt(17, 'G'), S.Just(16)); - eq(S.parseInt(17, 'H'), S.Nothing); - eq(S.parseInt(18, 'H'), S.Just(17)); - eq(S.parseInt(18, 'I'), S.Nothing); - eq(S.parseInt(19, 'I'), S.Just(18)); - eq(S.parseInt(19, 'J'), S.Nothing); - eq(S.parseInt(20, 'J'), S.Just(19)); - eq(S.parseInt(20, 'K'), S.Nothing); - eq(S.parseInt(21, 'K'), S.Just(20)); - eq(S.parseInt(21, 'L'), S.Nothing); - eq(S.parseInt(22, 'L'), S.Just(21)); - eq(S.parseInt(22, 'M'), S.Nothing); - eq(S.parseInt(23, 'M'), S.Just(22)); - eq(S.parseInt(23, 'N'), S.Nothing); - eq(S.parseInt(24, 'N'), S.Just(23)); - eq(S.parseInt(24, 'O'), S.Nothing); - eq(S.parseInt(25, 'O'), S.Just(24)); - eq(S.parseInt(25, 'P'), S.Nothing); - eq(S.parseInt(26, 'P'), S.Just(25)); - eq(S.parseInt(26, 'Q'), S.Nothing); - eq(S.parseInt(27, 'Q'), S.Just(26)); - eq(S.parseInt(27, 'R'), S.Nothing); - eq(S.parseInt(28, 'R'), S.Just(27)); - eq(S.parseInt(28, 'S'), S.Nothing); - eq(S.parseInt(29, 'S'), S.Just(28)); - eq(S.parseInt(29, 'T'), S.Nothing); - eq(S.parseInt(30, 'T'), S.Just(29)); - eq(S.parseInt(30, 'U'), S.Nothing); - eq(S.parseInt(31, 'U'), S.Just(30)); - eq(S.parseInt(31, 'V'), S.Nothing); - eq(S.parseInt(32, 'V'), S.Just(31)); - eq(S.parseInt(32, 'W'), S.Nothing); - eq(S.parseInt(33, 'W'), S.Just(32)); - eq(S.parseInt(33, 'X'), S.Nothing); - eq(S.parseInt(34, 'X'), S.Just(33)); - eq(S.parseInt(34, 'Y'), S.Nothing); - eq(S.parseInt(35, 'Y'), S.Just(34)); - eq(S.parseInt(35, 'Z'), S.Nothing); - eq(S.parseInt(36, 'Z'), S.Just(35)); - eq(S.parseInt(36, '['), S.Nothing); + eq (S.parseInt (2) ('1')) (S.Just (1)); + eq (S.parseInt (2) ('2')) (S.Nothing); + eq (S.parseInt (3) ('2')) (S.Just (2)); + eq (S.parseInt (3) ('3')) (S.Nothing); + eq (S.parseInt (4) ('3')) (S.Just (3)); + eq (S.parseInt (4) ('4')) (S.Nothing); + eq (S.parseInt (5) ('4')) (S.Just (4)); + eq (S.parseInt (5) ('5')) (S.Nothing); + eq (S.parseInt (6) ('5')) (S.Just (5)); + eq (S.parseInt (6) ('6')) (S.Nothing); + eq (S.parseInt (7) ('6')) (S.Just (6)); + eq (S.parseInt (7) ('7')) (S.Nothing); + eq (S.parseInt (8) ('7')) (S.Just (7)); + eq (S.parseInt (8) ('8')) (S.Nothing); + eq (S.parseInt (9) ('8')) (S.Just (8)); + eq (S.parseInt (9) ('9')) (S.Nothing); + eq (S.parseInt (10) ('9')) (S.Just (9)); + eq (S.parseInt (10) ('A')) (S.Nothing); + eq (S.parseInt (11) ('A')) (S.Just (10)); + eq (S.parseInt (11) ('B')) (S.Nothing); + eq (S.parseInt (12) ('B')) (S.Just (11)); + eq (S.parseInt (12) ('C')) (S.Nothing); + eq (S.parseInt (13) ('C')) (S.Just (12)); + eq (S.parseInt (13) ('D')) (S.Nothing); + eq (S.parseInt (14) ('D')) (S.Just (13)); + eq (S.parseInt (14) ('E')) (S.Nothing); + eq (S.parseInt (15) ('E')) (S.Just (14)); + eq (S.parseInt (15) ('F')) (S.Nothing); + eq (S.parseInt (16) ('F')) (S.Just (15)); + eq (S.parseInt (16) ('G')) (S.Nothing); + eq (S.parseInt (17) ('G')) (S.Just (16)); + eq (S.parseInt (17) ('H')) (S.Nothing); + eq (S.parseInt (18) ('H')) (S.Just (17)); + eq (S.parseInt (18) ('I')) (S.Nothing); + eq (S.parseInt (19) ('I')) (S.Just (18)); + eq (S.parseInt (19) ('J')) (S.Nothing); + eq (S.parseInt (20) ('J')) (S.Just (19)); + eq (S.parseInt (20) ('K')) (S.Nothing); + eq (S.parseInt (21) ('K')) (S.Just (20)); + eq (S.parseInt (21) ('L')) (S.Nothing); + eq (S.parseInt (22) ('L')) (S.Just (21)); + eq (S.parseInt (22) ('M')) (S.Nothing); + eq (S.parseInt (23) ('M')) (S.Just (22)); + eq (S.parseInt (23) ('N')) (S.Nothing); + eq (S.parseInt (24) ('N')) (S.Just (23)); + eq (S.parseInt (24) ('O')) (S.Nothing); + eq (S.parseInt (25) ('O')) (S.Just (24)); + eq (S.parseInt (25) ('P')) (S.Nothing); + eq (S.parseInt (26) ('P')) (S.Just (25)); + eq (S.parseInt (26) ('Q')) (S.Nothing); + eq (S.parseInt (27) ('Q')) (S.Just (26)); + eq (S.parseInt (27) ('R')) (S.Nothing); + eq (S.parseInt (28) ('R')) (S.Just (27)); + eq (S.parseInt (28) ('S')) (S.Nothing); + eq (S.parseInt (29) ('S')) (S.Just (28)); + eq (S.parseInt (29) ('T')) (S.Nothing); + eq (S.parseInt (30) ('T')) (S.Just (29)); + eq (S.parseInt (30) ('U')) (S.Nothing); + eq (S.parseInt (31) ('U')) (S.Just (30)); + eq (S.parseInt (31) ('V')) (S.Nothing); + eq (S.parseInt (32) ('V')) (S.Just (31)); + eq (S.parseInt (32) ('W')) (S.Nothing); + eq (S.parseInt (33) ('W')) (S.Just (32)); + eq (S.parseInt (33) ('X')) (S.Nothing); + eq (S.parseInt (34) ('X')) (S.Just (33)); + eq (S.parseInt (34) ('Y')) (S.Nothing); + eq (S.parseInt (35) ('Y')) (S.Just (34)); + eq (S.parseInt (35) ('Z')) (S.Nothing); + eq (S.parseInt (36) ('Z')) (S.Just (35)); + eq (S.parseInt (36) ('[')) (S.Nothing); // Throws if radix is not in [2 .. 36] - throws(function() { S.parseInt(1, ''); }, - TypeError, - 'Invalid value\n' + - '\n' + - 'parseInt :: Radix -> String -> Maybe Integer\n' + - ' ^^^^^\n' + - ' 1\n' + - '\n' + - '1) 1 :: Number, FiniteNumber, NonZeroFiniteNumber, Integer, NonNegativeInteger, ValidNumber\n' + - '\n' + - 'The value at position 1 is not a member of ‘Radix’.\n'); + throws (function() { S.parseInt (1); }) + (new TypeError ('Invalid value\n' + + '\n' + + 'parseInt :: Radix -> String -> Maybe Integer\n' + + ' ^^^^^\n' + + ' 1\n' + + '\n' + + '1) 1 :: Number, FiniteNumber, NonZeroFiniteNumber, Integer, NonNegativeInteger, ValidNumber\n' + + '\n' + + 'The value at position 1 is not a member of ‘Radix’.\n')); - throws(function() { S.parseInt(37, ''); }, - TypeError, - 'Invalid value\n' + - '\n' + - 'parseInt :: Radix -> String -> Maybe Integer\n' + - ' ^^^^^\n' + - ' 1\n' + - '\n' + - '1) 37 :: Number, FiniteNumber, NonZeroFiniteNumber, Integer, NonNegativeInteger, ValidNumber\n' + - '\n' + - 'The value at position 1 is not a member of ‘Radix’.\n'); + throws (function() { S.parseInt (37); }) + (new TypeError ('Invalid value\n' + + '\n' + + 'parseInt :: Radix -> String -> Maybe Integer\n' + + ' ^^^^^\n' + + ' 1\n' + + '\n' + + '1) 37 :: Number, FiniteNumber, NonZeroFiniteNumber, Integer, NonNegativeInteger, ValidNumber\n' + + '\n' + + 'The value at position 1 is not a member of ‘Radix’.\n')); // Is not case-sensitive - eq(S.parseInt(16, 'FF'), S.Just(255)); - eq(S.parseInt(16, 'Ff'), S.Just(255)); - eq(S.parseInt(16, 'fF'), S.Just(255)); - eq(S.parseInt(16, 'ff'), S.Just(255)); + eq (S.parseInt (16) ('FF')) (S.Just (255)); + eq (S.parseInt (16) ('Ff')) (S.Just (255)); + eq (S.parseInt (16) ('fF')) (S.Just (255)); + eq (S.parseInt (16) ('ff')) (S.Just (255)); // Accepts optional "+" or "-" prefix - eq(S.parseInt(10, '+42'), S.Just(42)); - eq(S.parseInt(16, '+2A'), S.Just(42)); - eq(S.parseInt(10, '-42'), S.Just(-42)); - eq(S.parseInt(16, '-2A'), S.Just(-42)); + eq (S.parseInt (10) ('+42')) (S.Just (42)); + eq (S.parseInt (16) ('+2A')) (S.Just (42)); + eq (S.parseInt (10) ('-42')) (S.Just (-42)); + eq (S.parseInt (16) ('-2A')) (S.Just (-42)); // Accepts optional "0x" or "0X" prefix when radix is 16 - eq(S.parseInt(16, '0xFF'), S.Just(255)); - eq(S.parseInt(16, '0XFF'), S.Just(255)); - eq(S.parseInt(17, '0xFF'), S.Nothing); - eq(S.parseInt(17, '0XFF'), S.Nothing); - eq(S.parseInt(16, '+0xFF'), S.Just(255)); - eq(S.parseInt(16, '+0XFF'), S.Just(255)); - eq(S.parseInt(16, '-0xFF'), S.Just(-255)); - eq(S.parseInt(16, '-0XFF'), S.Just(-255)); + eq (S.parseInt (16) ('0xFF')) (S.Just (255)); + eq (S.parseInt (16) ('0XFF')) (S.Just (255)); + eq (S.parseInt (17) ('0xFF')) (S.Nothing); + eq (S.parseInt (17) ('0XFF')) (S.Nothing); + eq (S.parseInt (16) ('+0xFF')) (S.Just (255)); + eq (S.parseInt (16) ('+0XFF')) (S.Just (255)); + eq (S.parseInt (16) ('-0xFF')) (S.Just (-255)); + eq (S.parseInt (16) ('-0XFF')) (S.Just (-255)); // Returns Nothing if one or more characters are invalid - eq(S.parseInt(10, '12.34'), S.Nothing); // parseInt('12.34', 10) == 12 - eq(S.parseInt(16, 'alice'), S.Nothing); // parseInt('alice', 16) == 10 + eq (S.parseInt (10) ('12.34')) (S.Nothing); // parseInt ('12.34', 10) == 12 + eq (S.parseInt (16) ('alice')) (S.Nothing); // parseInt ('alice', 16) == 10 // Restricts to exactly representable range (-2^53 .. 2^53) - eq(S.parseInt(10, '9007199254740991'), S.Just(9007199254740991)); - eq(S.parseInt(10, '-9007199254740991'), S.Just(-9007199254740991)); - eq(S.parseInt(10, '9007199254740992'), S.Nothing); - eq(S.parseInt(10, '-9007199254740992'), S.Nothing); - eq(S.parseInt(10, 'Infinity'), S.Nothing); - eq(S.parseInt(10, '-Infinity'), S.Nothing); + eq (S.parseInt (10) ('9007199254740991')) (S.Just (9007199254740991)); + eq (S.parseInt (10) ('-9007199254740991')) (S.Just (-9007199254740991)); + eq (S.parseInt (10) ('9007199254740992')) (S.Nothing); + eq (S.parseInt (10) ('-9007199254740992')) (S.Nothing); + eq (S.parseInt (10) ('Infinity')) (S.Nothing); + eq (S.parseInt (10) ('-Infinity')) (S.Nothing); }); diff --git a/test/parseJson.js b/test/parseJson.js index 7bad5d9d..cfc6523d 100644 --- a/test/parseJson.js +++ b/test/parseJson.js @@ -1,22 +1,22 @@ 'use strict'; -var $ = require('sanctuary-def'); +var $ = require ('sanctuary-def'); -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('parseJson', function() { +test ('parseJson', function() { - eq(typeof S.parseJson, 'function'); - eq(S.parseJson.length, 2); - eq(S.parseJson.toString(), 'parseJson :: (Any -> Boolean) -> String -> Maybe a'); + eq (typeof S.parseJson) ('function'); + eq (S.parseJson.length) (1); + eq (String (S.parseJson)) ('parseJson :: (Any -> Boolean) -> String -> Maybe a'); - eq(S.parseJson(S.is($.Any), '[Invalid JSON]'), S.Nothing); - eq(S.parseJson(S.is($.Array($.Any)), '{"foo":"bar"}'), S.Nothing); - eq(S.parseJson(S.is($.Array($.Any)), '["foo","bar"]'), S.Just(['foo', 'bar'])); - eq(S.parseJson(S.is($.Array($.Number)), '[1,2]'), S.Just([1, 2])); - eq(S.parseJson(S.is($.Array($.Number)), '[1,2,null]'), S.Nothing); + eq (S.parseJson (S.is ($.Any)) ('[Invalid JSON]')) (S.Nothing); + eq (S.parseJson (S.is ($.Array ($.Any))) ('{"foo":"bar"}')) (S.Nothing); + eq (S.parseJson (S.is ($.Array ($.Any))) ('["foo","bar"]')) (S.Just (['foo', 'bar'])); + eq (S.parseJson (S.is ($.Array ($.Number))) ('[1,2]')) (S.Just ([1, 2])); + eq (S.parseJson (S.is ($.Array ($.Number))) ('[1,2,null]')) (S.Nothing); }); diff --git a/test/pipe.js b/test/pipe.js index 439dce6b..cdca3151 100644 --- a/test/pipe.js +++ b/test/pipe.js @@ -1,31 +1,31 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var List = require('./internal/List'); -var eq = require('./internal/eq'); +var List = require ('./internal/List'); +var eq = require ('./internal/eq'); var Cons = List.Cons; var Nil = List.Nil; -test('pipe', function() { +test ('pipe', function() { - eq(typeof S.pipe, 'function'); - eq(S.pipe.length, 2); - eq(S.pipe.toString(), 'pipe :: Foldable f => f (Any -> Any) -> a -> b'); + eq (typeof S.pipe) ('function'); + eq (S.pipe.length) (1); + eq (String (S.pipe)) ('pipe :: Foldable f => f (Any -> Any) -> a -> b'); - eq(S.pipe([], '99'), '99'); - eq(S.pipe([parseInt], '99'), 99); - eq(S.pipe([parseInt, S.add(1)], '99'), 100); - eq(S.pipe([parseInt, S.add(1), Math.sqrt], '99'), 10); - eq(S.pipe([parseInt, S.add(1), Math.sqrt, S.sub(1)], '99'), 9); + eq (S.pipe ([]) ('99')) ('99'); + eq (S.pipe ([parseInt]) ('99')) (99); + eq (S.pipe ([parseInt, S.add (1)]) ('99')) (100); + eq (S.pipe ([parseInt, S.add (1), Math.sqrt]) ('99')) (10); + eq (S.pipe ([parseInt, S.add (1), Math.sqrt, S.sub (1)]) ('99')) (9); - eq(S.pipe(Nil, '99'), '99'); - eq(S.pipe(Cons(parseInt, Nil), '99'), 99); - eq(S.pipe(Cons(parseInt, Cons(S.add(1), Nil)), '99'), 100); - eq(S.pipe(Cons(parseInt, Cons(S.add(1), Cons(Math.sqrt, Nil))), '99'), 10); - eq(S.pipe(Cons(parseInt, Cons(S.add(1), Cons(Math.sqrt, Cons(S.sub(1), Nil)))), '99'), 9); + eq (S.pipe (Nil) ('99')) ('99'); + eq (S.pipe (Cons (parseInt) (Nil)) ('99')) (99); + eq (S.pipe (Cons (parseInt) (Cons (S.add (1)) (Nil))) ('99')) (100); + eq (S.pipe (Cons (parseInt) (Cons (S.add (1)) (Cons (Math.sqrt) (Nil)))) ('99')) (10); + eq (S.pipe (Cons (parseInt) (Cons (S.add (1)) (Cons (Math.sqrt) (Cons (S.sub (1)) (Nil))))) ('99')) (9); }); diff --git a/test/pipeK.js b/test/pipeK.js index 469808d6..8ff83fa6 100644 --- a/test/pipeK.js +++ b/test/pipeK.js @@ -1,29 +1,29 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var List = require('./internal/List'); -var eq = require('./internal/eq'); +var List = require ('./internal/List'); +var eq = require ('./internal/eq'); var Cons = List.Cons; var Nil = List.Nil; -test('pipeK', function() { +test ('pipeK', function() { - eq(typeof S.pipeK, 'function'); - eq(S.pipeK.length, 2); - eq(S.pipeK.toString(), 'pipeK :: (Foldable f, Chain m) => f (Any -> m Any) -> m a -> m b'); + eq (typeof S.pipeK) ('function'); + eq (S.pipeK.length) (1); + eq (String (S.pipeK)) ('pipeK :: (Foldable f, Chain m) => f (Any -> m Any) -> m a -> m b'); - eq(S.pipeK([], S.Just([1, 2, 3])), S.Just([1, 2, 3])); - eq(S.pipeK([S.tail], S.Just([1, 2, 3])), S.Just([2, 3])); - eq(S.pipeK([S.tail, S.tail], S.Just([1, 2, 3])), S.Just([3])); - eq(S.pipeK([S.tail, S.tail, S.head], S.Just([1, 2, 3])), S.Just(3)); + eq (S.pipeK ([]) (S.Just ([1, 2, 3]))) (S.Just ([1, 2, 3])); + eq (S.pipeK ([S.tail]) (S.Just ([1, 2, 3]))) (S.Just ([2, 3])); + eq (S.pipeK ([S.tail, S.tail]) (S.Just ([1, 2, 3]))) (S.Just ([3])); + eq (S.pipeK ([S.tail, S.tail, S.head]) (S.Just ([1, 2, 3]))) (S.Just (3)); - eq(S.pipeK(Nil, S.Just([1, 2, 3])), S.Just([1, 2, 3])); - eq(S.pipeK(Cons(S.tail, Nil), S.Just([1, 2, 3])), S.Just([2, 3])); - eq(S.pipeK(Cons(S.tail, Cons(S.tail, Nil)), S.Just([1, 2, 3])), S.Just([3])); - eq(S.pipeK(Cons(S.tail, Cons(S.tail, Cons(S.head, Nil))), S.Just([1, 2, 3])), S.Just(3)); + eq (S.pipeK (Nil) (S.Just ([1, 2, 3]))) (S.Just ([1, 2, 3])); + eq (S.pipeK (Cons (S.tail) (Nil)) (S.Just ([1, 2, 3]))) (S.Just ([2, 3])); + eq (S.pipeK (Cons (S.tail) (Cons (S.tail) (Nil))) (S.Just ([1, 2, 3]))) (S.Just ([3])); + eq (S.pipeK (Cons (S.tail) (Cons (S.tail) (Cons (S.head) (Nil)))) (S.Just ([1, 2, 3]))) (S.Just (3)); }); diff --git a/test/pow.js b/test/pow.js index 29452480..076c66f1 100644 --- a/test/pow.js +++ b/test/pow.js @@ -1,18 +1,18 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('pow', function() { +test ('pow', function() { - eq(typeof S.pow, 'function'); - eq(S.pow.length, 1); - eq(S.pow.toString(), 'pow :: FiniteNumber -> (FiniteNumber -> FiniteNumber)'); + eq (typeof S.pow) ('function'); + eq (S.pow.length) (1); + eq (String (S.pow)) ('pow :: FiniteNumber -> FiniteNumber -> FiniteNumber'); - eq(S.pow(2)(8), 64); - eq(S.map(S.pow(2), [-3, -2, -1, 0, 1, 2, 3]), [9, 4, 1, 0, 1, 4, 9]); - eq(S.map(S.pow(0.5), [1, 4, 9, 16, 25]), [1, 2, 3, 4, 5]); + eq (S.pow (2) (8)) (64); + eq (S.map (S.pow (2)) ([-3, -2, -1, 0, 1, 2, 3])) ([9, 4, 1, 0, 1, 4, 9]); + eq (S.map (S.pow (0.5)) ([1, 4, 9, 16, 25])) ([1, 2, 3, 4, 5]); }); diff --git a/test/prepend.js b/test/prepend.js index 49fe52d4..19dc2c2a 100644 --- a/test/prepend.js +++ b/test/prepend.js @@ -1,24 +1,24 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('prepend', function() { +test ('prepend', function() { - eq(typeof S.prepend, 'function'); - eq(S.prepend.length, 2); - eq(S.prepend.toString(), 'prepend :: (Applicative f, Semigroup f) => a -> f a -> f a'); + eq (typeof S.prepend) ('function'); + eq (S.prepend.length) (1); + eq (String (S.prepend)) ('prepend :: (Applicative f, Semigroup f) => a -> f a -> f a'); - eq(S.prepend(1, []), [1]); - eq(S.prepend(1, [2, 3]), [1, 2, 3]); - eq(S.prepend([1, 2], [[3, 4], [5, 6]]), [[1, 2], [3, 4], [5, 6]]); + eq (S.prepend (1) ([])) ([1]); + eq (S.prepend (1) ([2, 3])) ([1, 2, 3]); + eq (S.prepend ([1, 2]) ([[3, 4], [5, 6]])) ([[1, 2], [3, 4], [5, 6]]); - eq(S.prepend([1], S.Nothing), S.Just([1])); - eq(S.prepend([1], S.Just([2])), S.Just([1, 2])); + eq (S.prepend ([1]) (S.Nothing)) (S.Just ([1])); + eq (S.prepend ([1]) (S.Just ([2]))) (S.Just ([1, 2])); - eq(S.prepend([1], S.Left('error')), S.Right([1])); - eq(S.prepend([1], S.Right([2])), S.Right([1, 2])); + eq (S.prepend ([1]) (S.Left ('error'))) (S.Right ([1])); + eq (S.prepend ([1]) (S.Right ([2]))) (S.Right ([1, 2])); }); diff --git a/test/product.js b/test/product.js index 2c004ae4..75b9b81a 100644 --- a/test/product.js +++ b/test/product.js @@ -1,25 +1,25 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('product', function() { +test ('product', function() { - eq(typeof S.product, 'function'); - eq(S.product.length, 1); - eq(S.product.toString(), 'product :: Foldable f => f FiniteNumber -> FiniteNumber'); + eq (typeof S.product) ('function'); + eq (S.product.length) (1); + eq (String (S.product)) ('product :: Foldable f => f FiniteNumber -> FiniteNumber'); - eq(S.product([]), 1); - eq(S.product([0, 1, 2, 3]), 0); - eq(S.product([1, 2, 3, 4, 5]), 120); - eq(S.product([1, 2, 3, 4, -5]), -120); + eq (S.product ([])) (1); + eq (S.product ([0, 1, 2, 3])) (0); + eq (S.product ([1, 2, 3, 4, 5])) (120); + eq (S.product ([1, 2, 3, 4, -5])) (-120); - eq(S.product(S.Nothing), 1); - eq(S.product(S.Just(42)), 42); + eq (S.product (S.Nothing)) (1); + eq (S.product (S.Just (42))) (42); - eq(S.product(S.Left('xxx')), 1); - eq(S.product(S.Right(42)), 42); + eq (S.product (S.Left ('xxx'))) (1); + eq (S.product (S.Right (42))) (42); }); diff --git a/test/promap.js b/test/promap.js index 9f6ea718..226b3165 100644 --- a/test/promap.js +++ b/test/promap.js @@ -1,20 +1,20 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('promap', function() { +test ('promap', function() { - eq(typeof S.promap, 'function'); - eq(S.promap.length, 3); - eq(S.promap.toString(), 'promap :: Profunctor p => (a -> b) -> (c -> d) -> p b c -> p a d'); + eq (typeof S.promap) ('function'); + eq (S.promap.length) (1); + eq (String (S.promap)) ('promap :: Profunctor p => (a -> b) -> (c -> d) -> p b c -> p a d'); - var before = S.map(S.prop('length')); - var after = S.join(S.mult); - eq(S.promap(before, after, S.sum)(['foo', 'bar', 'baz', 'quux']), 169); + var before = S.map (S.prop ('length')); + var after = S.join (S.mult); + eq (S.promap (before) (after) (S.sum) (['foo', 'bar', 'baz', 'quux'])) (169); - eq(S.promap(Math.abs, S.add(1), Math.sqrt)(-100), 11); + eq (S.promap (Math.abs) (S.add (1)) (Math.sqrt) (-100)) (11); }); diff --git a/test/prop.js b/test/prop.js index f4fa8f1d..735f2356 100644 --- a/test/prop.js +++ b/test/prop.js @@ -1,33 +1,30 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var throws = require('./internal/throws'); +var eq = require ('./internal/eq'); +var throws = require ('./internal/throws'); -test('prop', function() { +test ('prop', function() { - eq(typeof S.prop, 'function'); - eq(S.prop.length, 2); - eq(S.prop.toString(), 'prop :: String -> a -> b'); + eq (typeof S.prop) ('function'); + eq (S.prop.length) (1); + eq (String (S.prop)) ('prop :: String -> a -> b'); - throws(function() { S.prop('xxx', [1, 2, 3]); }, - TypeError, - '‘prop’ expected object to have a property named ‘xxx’; [1, 2, 3] does not'); + throws (function() { S.prop ('xxx') ([1, 2, 3]); }) + (new TypeError ('‘prop’ expected object to have a property named ‘xxx’; [1, 2, 3] does not')); - eq(S.prop('a', {a: 0, b: 1}), 0); - eq(S.prop('0', [1, 2, 3]), 1); - eq(S.prop('length', 'abc'), 3); - eq(S.prop('x', Object.create({x: 1, y: 2})), 1); - eq(S.prop('global', /x/g), true); + eq (S.prop ('a') ({a: 0, b: 1})) (0); + eq (S.prop ('0') ([1, 2, 3])) (1); + eq (S.prop ('length') ('abc')) (3); + eq (S.prop ('x') (Object.create ({x: 1, y: 2}))) (1); + eq (S.prop ('global') (/x/g)) (true); - throws(function() { S.prop('valueOf', null); }, - TypeError, - '‘prop’ expected object to have a property named ‘valueOf’; null does not'); + throws (function() { S.prop ('valueOf') (null); }) + (new TypeError ('‘prop’ expected object to have a property named ‘valueOf’; null does not')); - throws(function() { S.prop('valueOf', undefined); }, - TypeError, - '‘prop’ expected object to have a property named ‘valueOf’; undefined does not'); + throws (function() { S.prop ('valueOf') (undefined); }) + (new TypeError ('‘prop’ expected object to have a property named ‘valueOf’; undefined does not')); }); diff --git a/test/properties.js b/test/properties.js index 02ed30be..01591a04 100644 --- a/test/properties.js +++ b/test/properties.js @@ -1,22 +1,22 @@ 'use strict'; -var jsc = require('jsverify'); +var jsc = require ('jsverify'); -var equals = require('./internal/equals'); +var equals = require ('./internal/equals'); -var basic = jsc.sum([jsc.integer, jsc.string, jsc.bool, jsc.falsy]); +var basic = jsc.sum ([jsc.integer, jsc.string, jsc.bool, jsc.falsy]); -var useful = jsc.sum([basic, jsc.array(basic), jsc.dict(basic), jsc.fn(basic)]); +var useful = jsc.sum ([basic, jsc.array (basic), jsc.dict (basic), jsc.fn (basic)]); exports.idempotent = function(f) { - return jsc.checkForall(useful, function(x) { - return equals(f(f(x)))(f(x)); + return jsc.checkForall (useful, function(x) { + return equals (f (f (x))) (f (x)); }); }; exports.involution = function(f) { - return jsc.checkForall(useful, function(x) { - return equals(f(f(x)))(x); + return jsc.checkForall (useful, function(x) { + return equals (f (f (x))) (x); }); }; diff --git a/test/props.js b/test/props.js index 96e3893f..1a042e6f 100644 --- a/test/props.js +++ b/test/props.js @@ -1,31 +1,28 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var throws = require('./internal/throws'); +var eq = require ('./internal/eq'); +var throws = require ('./internal/throws'); -test('props', function() { +test ('props', function() { - eq(typeof S.props, 'function'); - eq(S.props.length, 2); - eq(S.props.toString(), 'props :: Array String -> a -> b'); + eq (typeof S.props) ('function'); + eq (S.props.length) (1); + eq (String (S.props)) ('props :: Array String -> a -> b'); - throws(function() { S.props(['a', 'b', 'c'], [1, 2, 3]); }, - TypeError, - '‘props’ expected object to have a property at ["a", "b", "c"]; [1, 2, 3] does not'); + throws (function() { S.props (['a', 'b', 'c']) ([1, 2, 3]); }) + (new TypeError ('‘props’ expected object to have a property at ["a", "b", "c"]; [1, 2, 3] does not')); - eq(S.props(['a', 'b', 'c'], {a: {b: {c: 1}}}), 1); - eq(S.props(['a', 'b', 'c', '0'], {a: {b: {c: [2, 4, 6]}}}), 2); - eq(S.props(['a', 'b', 'c'], Object.create({a: {b: {c: 1}}})), 1); + eq (S.props (['a', 'b', 'c']) ({a: {b: {c: 1}}})) (1); + eq (S.props (['a', 'b', 'c', '0']) ({a: {b: {c: [2, 4, 6]}}})) (2); + eq (S.props (['a', 'b', 'c']) (Object.create ({a: {b: {c: 1}}}))) (1); - throws(function() { S.props(['valueOf'], null); }, - TypeError, - '‘props’ expected object to have a property at ["valueOf"]; null does not'); + throws (function() { S.props (['valueOf']) (null); }) + (new TypeError ('‘props’ expected object to have a property at ["valueOf"]; null does not')); - throws(function() { S.props(['valueOf'], undefined); }, - TypeError, - '‘props’ expected object to have a property at ["valueOf"]; undefined does not'); + throws (function() { S.props (['valueOf']) (undefined); }) + (new TypeError ('‘props’ expected object to have a property at ["valueOf"]; undefined does not')); }); diff --git a/test/range.js b/test/range.js index b48c78cf..13517b7c 100644 --- a/test/range.js +++ b/test/range.js @@ -1,20 +1,20 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('range', function() { +test ('range', function() { - eq(typeof S.range, 'function'); - eq(S.range.length, 2); - eq(S.range.toString(), 'range :: Integer -> Integer -> Array Integer'); + eq (typeof S.range) ('function'); + eq (S.range.length) (1); + eq (String (S.range)) ('range :: Integer -> Integer -> Array Integer'); - eq(S.range(0, 0), []); - eq(S.range(0, 10), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); - eq(S.range(0, -10), []); - eq(S.range(-2, -1), [-2]); - eq(S.range(-2, 3), [-2, -1, 0, 1, 2]); + eq (S.range (0) (0)) ([]); + eq (S.range (0) (10)) ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + eq (S.range (0) (-10)) ([]); + eq (S.range (-2) (-1)) ([-2]); + eq (S.range (-2) (3)) ([-2, -1, 0, 1, 2]); }); diff --git a/test/reduce.js b/test/reduce.js index 233d76e2..d4c1c5a5 100644 --- a/test/reduce.js +++ b/test/reduce.js @@ -1,22 +1,22 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('reduce', function() { +test ('reduce', function() { - eq(typeof S.reduce, 'function'); - eq(S.reduce.length, 3); - eq(S.reduce.toString(), 'reduce :: Foldable f => (a -> b -> a) -> a -> f b -> a'); + eq (typeof S.reduce) ('function'); + eq (S.reduce.length) (1); + eq (String (S.reduce)) ('reduce :: Foldable f => (a -> b -> a) -> a -> f b -> a'); - eq(S.reduce(S.concat, 'x', []), 'x'); - eq(S.reduce(S.concat, 'x', ['A', 'B', 'C']), 'xABC'); - eq(S.reduce(S.concat, 'x', {}), 'x'); - eq(S.reduce(S.concat, 'x', {a: 'A', b: 'B', c: 'C'}), 'xABC'); - eq(S.reduce(S.concat, 'x', {c: 'C', b: 'B', a: 'A'}), 'xABC'); - eq(S.reduce(S.concat, 'x', S.Just('A')), 'xA'); - eq(S.reduce(S.lift2(S.concat), S.Just('x'), [S.Just('A'), S.Just('B'), S.Just('C')]), S.Just('xABC')); + eq (S.reduce (S.concat) ('x') ([])) ('x'); + eq (S.reduce (S.concat) ('x') (['A', 'B', 'C'])) ('xABC'); + eq (S.reduce (S.concat) ('x') ({})) ('x'); + eq (S.reduce (S.concat) ('x') ({a: 'A', b: 'B', c: 'C'})) ('xABC'); + eq (S.reduce (S.concat) ('x') ({c: 'C', b: 'B', a: 'A'})) ('xABC'); + eq (S.reduce (S.concat) ('x') (S.Just ('A'))) ('xA'); + eq (S.reduce (S.lift2 (S.concat)) (S.Just ('x')) ([S.Just ('A'), S.Just ('B'), S.Just ('C')])) (S.Just ('xABC')); }); diff --git a/test/regex.js b/test/regex.js index 54b9199a..4488db53 100644 --- a/test/regex.js +++ b/test/regex.js @@ -1,23 +1,23 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('regex', function() { +test ('regex', function() { - eq(typeof S.regex, 'function'); - eq(S.regex.length, 2); - eq(S.regex.toString(), 'regex :: RegexFlags -> String -> RegExp'); + eq (typeof S.regex) ('function'); + eq (S.regex.length) (1); + eq (String (S.regex)) ('regex :: RegexFlags -> String -> RegExp'); - eq(S.regex('', '\\d'), /\d/); - eq(S.regex('g', '\\d'), /\d/g); - eq(S.regex('i', '\\d'), /\d/i); - eq(S.regex('m', '\\d'), /\d/m); - eq(S.regex('gi', '\\d'), /\d/gi); - eq(S.regex('gm', '\\d'), /\d/gm); - eq(S.regex('im', '\\d'), /\d/im); - eq(S.regex('gim', '\\d'), /\d/gim); + eq (S.regex ('') ('\\d')) (/\d/); + eq (S.regex ('g') ('\\d')) (/\d/g); + eq (S.regex ('i') ('\\d')) (/\d/i); + eq (S.regex ('m') ('\\d')) (/\d/m); + eq (S.regex ('gi') ('\\d')) (/\d/gi); + eq (S.regex ('gm') ('\\d')) (/\d/gm); + eq (S.regex ('im') ('\\d')) (/\d/im); + eq (S.regex ('gim') ('\\d')) (/\d/gim); }); diff --git a/test/regexEscape.js b/test/regexEscape.js index 8afa1931..deda3220 100644 --- a/test/regexEscape.js +++ b/test/regexEscape.js @@ -1,26 +1,26 @@ 'use strict'; -var jsc = require('jsverify'); +var jsc = require ('jsverify'); -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('regexEscape', function() { +test ('regexEscape', function() { - eq(typeof S.regexEscape, 'function'); - eq(S.regexEscape.length, 1); - eq(S.regexEscape.toString(), 'regexEscape :: String -> String'); + eq (typeof S.regexEscape) ('function'); + eq (S.regexEscape.length) (1); + eq (String (S.regexEscape)) ('regexEscape :: String -> String'); - eq(S.regexEscape('-=*{XYZ}*=-'), '\\-=\\*\\{XYZ\\}\\*=\\-'); + eq (S.regexEscape ('-=*{XYZ}*=-')) ('\\-=\\*\\{XYZ\\}\\*=\\-'); - jsc.assert(jsc.forall(jsc.string, function(s) { - return S.test(S.regex('', S.regexEscape(s)), s); + jsc.assert (jsc.forall (jsc.string, function(s) { + return S.test (S.regex ('') (S.regexEscape (s))) (s); }), {tests: 1000}); - jsc.assert(jsc.forall(jsc.string, function(s) { - return S.test(S.regex('', '^' + S.regexEscape(s) + '$'), s); + jsc.assert (jsc.forall (jsc.string, function(s) { + return S.test (S.regex ('') ('^' + S.regexEscape (s) + '$')) (s); }), {tests: 1000}); }); diff --git a/test/reject.js b/test/reject.js index 43206e2d..5949f37e 100644 --- a/test/reject.js +++ b/test/reject.js @@ -1,38 +1,38 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var List = require('./internal/List'); -var eq = require('./internal/eq'); +var List = require ('./internal/List'); +var eq = require ('./internal/eq'); var Cons = List.Cons; var Nil = List.Nil; -test('reject', function() { +test ('reject', function() { - eq(typeof S.reject, 'function'); - eq(S.reject.length, 2); - eq(S.reject.toString(), 'reject :: Filterable f => (a -> Boolean) -> f a -> f a'); + eq (typeof S.reject) ('function'); + eq (S.reject.length) (1); + eq (String (S.reject)) ('reject :: Filterable f => (a -> Boolean) -> f a -> f a'); - eq(S.reject(S.odd, []), []); - eq(S.reject(S.odd, [0, 2, 4, 6, 8]), [0, 2, 4, 6, 8]); - eq(S.reject(S.odd, [1, 3, 5, 7, 9]), []); - eq(S.reject(S.odd, [1, 2, 3, 4, 5]), [2, 4]); + eq (S.reject (S.odd) ([])) ([]); + eq (S.reject (S.odd) ([0, 2, 4, 6, 8])) ([0, 2, 4, 6, 8]); + eq (S.reject (S.odd) ([1, 3, 5, 7, 9])) ([]); + eq (S.reject (S.odd) ([1, 2, 3, 4, 5])) ([2, 4]); - eq(S.reject(S.odd, {}), {}); - eq(S.reject(S.odd, {x: 1}), {}); - eq(S.reject(S.odd, {x: 1, y: 2}), {y: 2}); - eq(S.reject(S.odd, {x: 1, y: 2, z: 3}), {y: 2}); + eq (S.reject (S.odd) ({})) ({}); + eq (S.reject (S.odd) ({x: 1})) ({}); + eq (S.reject (S.odd) ({x: 1, y: 2})) ({y: 2}); + eq (S.reject (S.odd) ({x: 1, y: 2, z: 3})) ({y: 2}); - eq(S.reject(S.odd, S.Nothing), S.Nothing); - eq(S.reject(S.odd, S.Just(0)), S.Just(0)); - eq(S.reject(S.odd, S.Just(1)), S.Nothing); + eq (S.reject (S.odd) (S.Nothing)) (S.Nothing); + eq (S.reject (S.odd) (S.Just (0))) (S.Just (0)); + eq (S.reject (S.odd) (S.Just (1))) (S.Nothing); - eq(S.reject(S.odd, Nil), Nil); - eq(S.reject(S.odd, Cons(1, Nil)), Nil); - eq(S.reject(S.odd, Cons(1, Cons(2, Nil))), Cons(2, Nil)); - eq(S.reject(S.odd, Cons(1, Cons(2, Cons(3, Nil)))), Cons(2, Nil)); + eq (S.reject (S.odd) (Nil)) (Nil); + eq (S.reject (S.odd) (Cons (1) (Nil))) (Nil); + eq (S.reject (S.odd) (Cons (1) (Cons (2) (Nil)))) (Cons (2) (Nil)); + eq (S.reject (S.odd) (Cons (1) (Cons (2) (Cons (3) (Nil))))) (Cons (2) (Nil)); }); diff --git a/test/remove.js b/test/remove.js index ce6c7004..e5fa487f 100644 --- a/test/remove.js +++ b/test/remove.js @@ -1,28 +1,28 @@ 'use strict'; -var jsc = require('jsverify'); +var jsc = require ('jsverify'); -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var equals = require('./internal/equals'); +var eq = require ('./internal/eq'); +var equals = require ('./internal/equals'); -test('remove', function() { +test ('remove', function() { - eq(typeof S.remove, 'function'); - eq(S.remove.length, 2); - eq(S.remove.toString(), 'remove :: String -> StrMap a -> StrMap a'); + eq (typeof S.remove) ('function'); + eq (S.remove.length) (1); + eq (String (S.remove)) ('remove :: String -> StrMap a -> StrMap a'); - eq(S.remove('a', {}), {}); - eq(S.remove('b', {a: 1}), {a: 1}); - eq(S.remove('c', {a: 1, b: 2, c: 3}), {a: 1, b: 2}); + eq (S.remove ('a') ({})) ({}); + eq (S.remove ('b') ({a: 1})) ({a: 1}); + eq (S.remove ('c') ({a: 1, b: 2, c: 3})) ({a: 1, b: 2}); - jsc.assert(jsc.forall(jsc.string, jsc.dict(jsc.number), function(key, map) { - var remove = S.remove(key); - var lhs = remove(remove(map)); - var rhs = remove(map); - return equals(lhs)(rhs); + jsc.assert (jsc.forall (jsc.string, jsc.dict (jsc.number), function(key, map) { + var remove = S.remove (key); + var lhs = remove (remove (map)); + var rhs = remove (map); + return equals (lhs) (rhs); }), {tests: 1000}); }); diff --git a/test/reverse.js b/test/reverse.js index b8bb9b33..a4ec0e34 100644 --- a/test/reverse.js +++ b/test/reverse.js @@ -1,29 +1,29 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var List = require('./internal/List'); -var eq = require('./internal/eq'); +var List = require ('./internal/List'); +var eq = require ('./internal/eq'); var Cons = List.Cons; var Nil = List.Nil; -test('reverse', function() { +test ('reverse', function() { - eq(typeof S.reverse, 'function'); - eq(S.reverse.length, 1); - eq(S.reverse.toString(), 'reverse :: (Applicative f, Foldable f, Monoid f) => f a -> f a'); + eq (typeof S.reverse) ('function'); + eq (S.reverse.length) (1); + eq (String (S.reverse)) ('reverse :: (Applicative f, Foldable f, Monoid f) => f a -> f a'); - eq(S.reverse([]), []); - eq(S.reverse([1]), [1]); - eq(S.reverse([1, 2]), [2, 1]); - eq(S.reverse([1, 2, 3]), [3, 2, 1]); + eq (S.reverse ([])) ([]); + eq (S.reverse ([1])) ([1]); + eq (S.reverse ([1, 2])) ([2, 1]); + eq (S.reverse ([1, 2, 3])) ([3, 2, 1]); - eq(S.reverse(Nil), Nil); - eq(S.reverse(Cons(1, Nil)), Cons(1, Nil)); - eq(S.reverse(Cons(1, Cons(2, Nil))), Cons(2, Cons(1, Nil))); - eq(S.reverse(Cons(1, Cons(2, Cons(3, Nil)))), Cons(3, Cons(2, Cons(1, Nil)))); + eq (S.reverse (Nil)) (Nil); + eq (S.reverse (Cons (1) (Nil))) (Cons (1) (Nil)); + eq (S.reverse (Cons (1) (Cons (2) (Nil)))) (Cons (2) (Cons (1) (Nil))); + eq (S.reverse (Cons (1) (Cons (2) (Cons (3) (Nil))))) (Cons (3) (Cons (2) (Cons (1) (Nil)))); }); diff --git a/test/rights.js b/test/rights.js index 4a4695cc..b29ec0ca 100644 --- a/test/rights.js +++ b/test/rights.js @@ -1,41 +1,41 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var List = require('./internal/List'); -var eq = require('./internal/eq'); +var List = require ('./internal/List'); +var eq = require ('./internal/eq'); var Cons = List.Cons; var Nil = List.Nil; -test('rights', function() { +test ('rights', function() { - eq(typeof S.rights, 'function'); - eq(S.rights.length, 1); - eq(S.rights.toString(), 'rights :: (Filterable f, Functor f) => f (Either a b) -> f b'); + eq (typeof S.rights) ('function'); + eq (S.rights.length) (1); + eq (String (S.rights)) ('rights :: (Filterable f, Functor f) => f (Either a b) -> f b'); - eq(S.rights([]), []); - eq(S.rights([S.Left('a'), S.Left('b')]), []); - eq(S.rights([S.Left('a'), S.Right(1)]), [1]); - eq(S.rights([S.Right(2), S.Left('b')]), [2]); - eq(S.rights([S.Right(2), S.Right(1)]), [2, 1]); + eq (S.rights ([])) ([]); + eq (S.rights ([S.Left ('a'), S.Left ('b')])) ([]); + eq (S.rights ([S.Left ('a'), S.Right (1)])) ([1]); + eq (S.rights ([S.Right (2), S.Left ('b')])) ([2]); + eq (S.rights ([S.Right (2), S.Right (1)])) ([2, 1]); - eq(S.rights({}), {}); - eq(S.rights({x: S.Left('a'), y: S.Left('b')}), {}); - eq(S.rights({x: S.Left('a'), y: S.Right(1)}), {y: 1}); - eq(S.rights({x: S.Right(2), y: S.Left('b')}), {x: 2}); - eq(S.rights({x: S.Right(2), y: S.Right(1)}), {x: 2, y: 1}); + eq (S.rights ({})) ({}); + eq (S.rights ({x: S.Left ('a'), y: S.Left ('b')})) ({}); + eq (S.rights ({x: S.Left ('a'), y: S.Right (1)})) ({y: 1}); + eq (S.rights ({x: S.Right (2), y: S.Left ('b')})) ({x: 2}); + eq (S.rights ({x: S.Right (2), y: S.Right (1)})) ({x: 2, y: 1}); - eq(S.rights(S.Nothing), S.Nothing); - eq(S.rights(S.Just(S.Left('a'))), S.Nothing); - eq(S.rights(S.Just(S.Right(1))), S.Just(1)); + eq (S.rights (S.Nothing)) (S.Nothing); + eq (S.rights (S.Just (S.Left ('a')))) (S.Nothing); + eq (S.rights (S.Just (S.Right (1)))) (S.Just (1)); - eq(S.rights(Nil), Nil); - eq(S.rights(Cons(S.Left('a'), Cons(S.Left('b'), Nil))), Nil); - eq(S.rights(Cons(S.Left('a'), Cons(S.Right(1), Nil))), Cons(1, Nil)); - eq(S.rights(Cons(S.Right(2), Cons(S.Left('b'), Nil))), Cons(2, Nil)); - eq(S.rights(Cons(S.Right(2), Cons(S.Right(1), Nil))), Cons(2, Cons(1, Nil))); + eq (S.rights (Nil)) (Nil); + eq (S.rights (Cons (S.Left ('a')) (Cons (S.Left ('b')) (Nil)))) (Nil); + eq (S.rights (Cons (S.Left ('a')) (Cons (S.Right (1)) (Nil)))) (Cons (1) (Nil)); + eq (S.rights (Cons (S.Right (2)) (Cons (S.Left ('b')) (Nil)))) (Cons (2) (Nil)); + eq (S.rights (Cons (S.Right (2)) (Cons (S.Right (1)) (Nil)))) (Cons (2) (Cons (1) (Nil))); }); diff --git a/test/sequence.js b/test/sequence.js index 22e87a50..fae9ad0d 100644 --- a/test/sequence.js +++ b/test/sequence.js @@ -1,33 +1,33 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var Identity = require('./internal/Identity'); -var eq = require('./internal/eq'); +var Identity = require ('./internal/Identity'); +var eq = require ('./internal/eq'); -test('sequence', function() { +test ('sequence', function() { - eq(typeof S.sequence, 'function'); - eq(S.sequence.length, 2); - eq(S.sequence.toString(), 'sequence :: (Applicative f, Traversable t) => TypeRep f -> t (f a) -> f (t a)'); + eq (typeof S.sequence) ('function'); + eq (S.sequence.length) (1); + eq (String (S.sequence)) ('sequence :: (Applicative f, Traversable t) => TypeRep f -> t (f a) -> f (t a)'); - eq(S.sequence(Identity, []), Identity([])); - eq(S.sequence(Identity, [Identity(1), Identity(2), Identity(3)]), Identity([1, 2, 3])); - eq(S.sequence(Identity, {}), Identity({})); - eq(S.sequence(Identity, {a: Identity(1), b: Identity(2), c: Identity(3)}), Identity({a: 1, b: 2, c: 3})); - eq(S.sequence(Identity, S.Nothing), Identity(S.Nothing)); - eq(S.sequence(Identity, S.Just(Identity(0))), Identity(S.Just(0))); - eq(S.sequence(Identity, S.Left('A')), Identity(S.Left('A'))); - eq(S.sequence(Identity, S.Right(Identity(-1))), Identity(S.Right(-1))); + eq (S.sequence (Identity) ([])) (Identity ([])); + eq (S.sequence (Identity) ([Identity (1), Identity (2), Identity (3)])) (Identity ([1, 2, 3])); + eq (S.sequence (Identity) ({})) (Identity ({})); + eq (S.sequence (Identity) ({a: Identity (1), b: Identity (2), c: Identity (3)})) (Identity ({a: 1, b: 2, c: 3})); + eq (S.sequence (Identity) (S.Nothing)) (Identity (S.Nothing)); + eq (S.sequence (Identity) (S.Just (Identity (0)))) (Identity (S.Just (0))); + eq (S.sequence (Identity) (S.Left ('A'))) (Identity (S.Left ('A'))); + eq (S.sequence (Identity) (S.Right (Identity (-1)))) (Identity (S.Right (-1))); - eq(S.sequence(Array, Identity([])), []); - eq(S.sequence(Array, Identity([1, 2, 3])), [Identity(1), Identity(2), Identity(3)]); - eq(S.sequence(S.Maybe, Identity(S.Nothing)), S.Nothing); - eq(S.sequence(S.Maybe, Identity(S.Just(0))), S.Just(Identity(0))); - eq(S.sequence(S.Either, Identity(S.Left('A'))), S.Left('A')); - eq(S.sequence(S.Either, Identity(S.Right(-1))), S.Right(Identity(-1))); + eq (S.sequence (Array) (Identity ([]))) ([]); + eq (S.sequence (Array) (Identity ([1, 2, 3]))) ([Identity (1), Identity (2), Identity (3)]); + eq (S.sequence (S.Maybe) (Identity (S.Nothing))) (S.Nothing); + eq (S.sequence (S.Maybe) (Identity (S.Just (0)))) (S.Just (Identity (0))); + eq (S.sequence (S.Either) (Identity (S.Left ('A')))) (S.Left ('A')); + eq (S.sequence (S.Either) (Identity (S.Right (-1)))) (S.Right (Identity (-1))); - eq(S.sequence(Array, {a: [1, 2], b: [3, 4]}), [{a: 1, b: 3}, {a: 1, b: 4}, {a: 2, b: 3}, {a: 2, b: 4}]); + eq (S.sequence (Array) ({a: [1, 2], b: [3, 4]})) ([{a: 1, b: 3}, {a: 1, b: 4}, {a: 2, b: 3}, {a: 2, b: 4}]); }); diff --git a/test/singleton.js b/test/singleton.js index 7e765da4..f8f8cbb2 100644 --- a/test/singleton.js +++ b/test/singleton.js @@ -1,12 +1,16 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('singleton', function() { +test ('singleton', function() { - eq(S.singleton('foo', 42), {foo: 42}); + eq (typeof S.singleton) ('function'); + eq (S.singleton.length) (1); + eq (String (S.singleton)) ('singleton :: String -> a -> StrMap a'); + + eq (S.singleton ('foo') (42)) ({foo: 42}); }); diff --git a/test/size.js b/test/size.js index 27622956..4a77de8e 100644 --- a/test/size.js +++ b/test/size.js @@ -1,32 +1,32 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var List = require('./internal/List'); -var eq = require('./internal/eq'); +var List = require ('./internal/List'); +var eq = require ('./internal/eq'); var Cons = List.Cons; var Nil = List.Nil; -test('size', function() { +test ('size', function() { - eq(typeof S.size, 'function'); - eq(S.size.length, 1); - eq(S.size.toString(), 'size :: Foldable f => f a -> Integer'); + eq (typeof S.size) ('function'); + eq (S.size.length) (1); + eq (String (S.size)) ('size :: Foldable f => f a -> Integer'); - eq(S.size([]), 0); - eq(S.size(['foo']), 1); - eq(S.size(['foo', 'bar']), 2); - eq(S.size(['foo', 'bar', 'baz']), 3); + eq (S.size ([])) (0); + eq (S.size (['foo'])) (1); + eq (S.size (['foo', 'bar'])) (2); + eq (S.size (['foo', 'bar', 'baz'])) (3); - eq(S.size(Nil), 0); - eq(S.size(Cons('foo', Nil)), 1); - eq(S.size(Cons('foo', Cons('bar', Nil))), 2); - eq(S.size(Cons('foo', Cons('bar', Cons('baz', Nil)))), 3); + eq (S.size (Nil)) (0); + eq (S.size (Cons ('foo') (Nil))) (1); + eq (S.size (Cons ('foo') (Cons ('bar') (Nil)))) (2); + eq (S.size (Cons ('foo') (Cons ('bar') (Cons ('baz') (Nil))))) (3); - eq(S.size(S.Nothing), 0); - eq(S.size(S.Just(0)), 1); + eq (S.size (S.Nothing)) (0); + eq (S.size (S.Just (0))) (1); }); diff --git a/test/slice.js b/test/slice.js index 460b00ac..cbf5771c 100644 --- a/test/slice.js +++ b/test/slice.js @@ -1,31 +1,31 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('slice', function() { +test ('slice', function() { - eq(typeof S.slice, 'function'); - eq(S.slice.length, 3); - eq(S.slice.toString(), 'slice :: Integer -> Integer -> Array a -> Maybe (Array a)'); + eq (typeof S.slice) ('function'); + eq (S.slice.length) (1); + eq (String (S.slice)) ('slice :: Integer -> Integer -> Array a -> Maybe (Array a)'); - eq(S.slice(6, 1, [1, 2, 3, 4, 5]), S.Nothing); - eq(S.slice(1, 6, [1, 2, 3, 4, 5]), S.Nothing); - eq(S.slice(1, -6, [1, 2, 3, 4, 5]), S.Nothing); - eq(S.slice(-6, 1, [1, 2, 3, 4, 5]), S.Nothing); + eq (S.slice (6) (1) ([1, 2, 3, 4, 5])) (S.Nothing); + eq (S.slice (1) (6) ([1, 2, 3, 4, 5])) (S.Nothing); + eq (S.slice (1) (-6) ([1, 2, 3, 4, 5])) (S.Nothing); + eq (S.slice (-6) (1) ([1, 2, 3, 4, 5])) (S.Nothing); - eq(S.slice(1, 1, [1, 2, 3, 4, 5]), S.Just([])); - eq(S.slice(1, -4, [1, 2, 3, 4, 5]), S.Just([])); - eq(S.slice(-4, 1, [1, 2, 3, 4, 5]), S.Just([])); - eq(S.slice(-4, -4, [1, 2, 3, 4, 5]), S.Just([])); - eq(S.slice(0, 0, []), S.Just([])); + eq (S.slice (1) (1) ([1, 2, 3, 4, 5])) (S.Just ([])); + eq (S.slice (1) (-4) ([1, 2, 3, 4, 5])) (S.Just ([])); + eq (S.slice (-4) (1) ([1, 2, 3, 4, 5])) (S.Just ([])); + eq (S.slice (-4) (-4) ([1, 2, 3, 4, 5])) (S.Just ([])); + eq (S.slice (0) (0) ([])) (S.Just ([])); - eq(S.slice(1, 3, [1, 2, 3, 4, 5]), S.Just([2, 3])); - eq(S.slice(-3, 5, [1, 2, 3, 4, 5]), S.Just([3, 4, 5])); - eq(S.slice(1, -2, [1, 2, 3, 4, 5]), S.Just([2, 3])); + eq (S.slice (1) (3) ([1, 2, 3, 4, 5])) (S.Just ([2, 3])); + eq (S.slice (-3) (5) ([1, 2, 3, 4, 5])) (S.Just ([3, 4, 5])); + eq (S.slice (1) (-2) ([1, 2, 3, 4, 5])) (S.Just ([2, 3])); - eq(S.slice(0, 5, [1, 2, 3, 4, 5]), S.Just([1, 2, 3, 4, 5])); + eq (S.slice (0) (5) ([1, 2, 3, 4, 5])) (S.Just ([1, 2, 3, 4, 5])); }); diff --git a/test/sort.js b/test/sort.js index 4d78853d..2b436aee 100644 --- a/test/sort.js +++ b/test/sort.js @@ -1,21 +1,21 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('sort', function() { +test ('sort', function() { - eq(typeof S.sort, 'function'); - eq(S.sort.length, 1); - eq(S.sort.toString(), 'sort :: (Ord a, Applicative m, Foldable m, Monoid m) => m a -> m a'); + eq (typeof S.sort) ('function'); + eq (S.sort.length) (1); + eq (String (S.sort)) ('sort :: (Ord a, Applicative m, Foldable m, Monoid m) => m a -> m a'); - eq(S.sort([]), []); - eq(S.sort(['foo', 'bar', 'baz']), ['bar', 'baz', 'foo']); - eq(S.sort([S.Left(4), S.Right(3), S.Left(2), S.Right(1)]), [S.Left(2), S.Left(4), S.Right(1), S.Right(3)]); + eq (S.sort ([])) ([]); + eq (S.sort (['foo', 'bar', 'baz'])) (['bar', 'baz', 'foo']); + eq (S.sort ([S.Left (4), S.Right (3), S.Left (2), S.Right (1)])) ([S.Left (2), S.Left (4), S.Right (1), S.Right (3)]); - eq(S.sort(S.range(0, 100)), S.range(0, 100)); - eq(S.sort(S.reverse(S.range(0, 100))), S.range(0, 100)); + eq (S.sort (S.range (0) (100))) (S.range (0) (100)); + eq (S.sort (S.reverse (S.range (0) (100)))) (S.range (0) (100)); }); diff --git a/test/sortBy.js b/test/sortBy.js index f6358715..256b1302 100644 --- a/test/sortBy.js +++ b/test/sortBy.js @@ -1,29 +1,29 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('sortBy', function() { +test ('sortBy', function() { - eq(typeof S.sortBy, 'function'); - eq(S.sortBy.length, 2); - eq(S.sortBy.toString(), 'sortBy :: (Ord b, Applicative m, Foldable m, Monoid m) => (a -> b) -> m a -> m a'); + eq (typeof S.sortBy) ('function'); + eq (S.sortBy.length) (1); + eq (String (S.sortBy)) ('sortBy :: (Ord b, Applicative m, Foldable m, Monoid m) => (a -> b) -> m a -> m a'); - eq(S.sortBy(S.I, []), []); - eq(S.sortBy(S.I, ['five']), ['five']); - eq(S.sortBy(S.I, ['five', 'six']), ['five', 'six']); - eq(S.sortBy(S.I, ['five', 'six', 'seven']), ['five', 'seven', 'six']); - eq(S.sortBy(S.prop('length'), ['five', 'six', 'seven']), ['six', 'five', 'seven']); + eq (S.sortBy (S.I) ([])) ([]); + eq (S.sortBy (S.I) (['five'])) (['five']); + eq (S.sortBy (S.I) (['five', 'six'])) (['five', 'six']); + eq (S.sortBy (S.I) (['five', 'six', 'seven'])) (['five', 'seven', 'six']); + eq (S.sortBy (S.prop ('length')) (['five', 'six', 'seven'])) (['six', 'five', 'seven']); var _7s = {rank: 7, suit: 's'}; var _5h = {rank: 5, suit: 'h'}; var _2h = {rank: 2, suit: 'h'}; var _5s = {rank: 5, suit: 's'}; - eq(S.sortBy(S.prop('rank'), [_7s, _5h, _2h, _5s]), [_2h, _5h, _5s, _7s]); - eq(S.sortBy(S.prop('rank'), [_7s, _5s, _2h, _5h]), [_2h, _5s, _5h, _7s]); - eq(S.sortBy(S.prop('suit'), [_7s, _5h, _2h, _5s]), [_5h, _2h, _7s, _5s]); - eq(S.sortBy(S.prop('suit'), [_5s, _2h, _5h, _7s]), [_2h, _5h, _5s, _7s]); + eq (S.sortBy (S.prop ('rank')) ([_7s, _5h, _2h, _5s])) ([_2h, _5h, _5s, _7s]); + eq (S.sortBy (S.prop ('rank')) ([_7s, _5s, _2h, _5h])) ([_2h, _5s, _5h, _7s]); + eq (S.sortBy (S.prop ('suit')) ([_7s, _5h, _2h, _5s])) ([_5h, _2h, _7s, _5s]); + eq (S.sortBy (S.prop ('suit')) ([_5s, _2h, _5h, _7s])) ([_2h, _5h, _5s, _7s]); }); diff --git a/test/splitOn.js b/test/splitOn.js index 42565520..b3027b1d 100644 --- a/test/splitOn.js +++ b/test/splitOn.js @@ -1,35 +1,35 @@ 'use strict'; -var jsc = require('jsverify'); +var jsc = require ('jsverify'); -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var equals = require('./internal/equals'); +var eq = require ('./internal/eq'); +var equals = require ('./internal/equals'); -test('splitOn', function() { +test ('splitOn', function() { - eq(typeof S.splitOn, 'function'); - eq(S.splitOn.length, 2); - eq(S.splitOn.toString(), 'splitOn :: String -> String -> Array String'); + eq (typeof S.splitOn) ('function'); + eq (S.splitOn.length) (1); + eq (String (S.splitOn)) ('splitOn :: String -> String -> Array String'); - eq(S.splitOn('', 'abc'), ['a', 'b', 'c']); - eq(S.splitOn(':', ''), ['']); - eq(S.splitOn(':', ':'), ['', '']); - eq(S.splitOn(':', ':foo:'), ['', 'foo', '']); - eq(S.splitOn(':', 'foo:bar:baz'), ['foo', 'bar', 'baz']); - eq(S.splitOn('::', 'foo::bar::baz'), ['foo', 'bar', 'baz']); + eq (S.splitOn ('') ('abc')) (['a', 'b', 'c']); + eq (S.splitOn (':') ('')) (['']); + eq (S.splitOn (':') (':')) (['', '']); + eq (S.splitOn (':') (':foo:')) (['', 'foo', '']); + eq (S.splitOn (':') ('foo:bar:baz')) (['foo', 'bar', 'baz']); + eq (S.splitOn ('::') ('foo::bar::baz')) (['foo', 'bar', 'baz']); - jsc.assert(jsc.forall(jsc.asciistring, function(t) { + jsc.assert (jsc.forall (jsc.asciistring, function(t) { var min = 0; var max = t.length; - var i = jsc.random(min, max); - var j = jsc.random(min, max); - var s = t.slice(Math.min(i, j), Math.max(i, j)); - var lhs = S.joinWith(s, S.splitOn(s, t)); + var i = jsc.random (min, max); + var j = jsc.random (min, max); + var s = t.slice (Math.min (i, j), Math.max (i, j)); + var lhs = S.joinWith (s) (S.splitOn (s) (t)); var rhs = t; - return equals(lhs)(rhs); + return equals (lhs) (rhs); }), {tests: 1000}); }); diff --git a/test/splitOnRegex.js b/test/splitOnRegex.js index 4c3d368c..24c44d76 100644 --- a/test/splitOnRegex.js +++ b/test/splitOnRegex.js @@ -1,62 +1,62 @@ 'use strict'; -var jsc = require('jsverify'); +var jsc = require ('jsverify'); -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); -var equals = require('./internal/equals'); +var eq = require ('./internal/eq'); +var equals = require ('./internal/equals'); -test('splitOnRegex', function() { +test ('splitOnRegex', function() { - eq(typeof S.splitOnRegex, 'function'); - eq(S.splitOnRegex.length, 2); - eq(S.splitOnRegex.toString(), 'splitOnRegex :: GlobalRegExp -> String -> Array String'); + eq (typeof S.splitOnRegex) ('function'); + eq (S.splitOnRegex.length) (1); + eq (String (S.splitOnRegex)) ('splitOnRegex :: GlobalRegExp -> String -> Array String'); - eq(S.splitOnRegex(/b/g, 'abc'), ['a', 'c']); - eq(S.splitOnRegex(/d/g, 'abc'), ['abc']); - eq(S.splitOnRegex(/b(?=c)/g, 'abc abd'), ['a', 'c abd']); - eq(S.splitOnRegex(/b(?!c)/g, 'abc abd'), ['abc a', 'd']); + eq (S.splitOnRegex (/b/g) ('abc')) (['a', 'c']); + eq (S.splitOnRegex (/d/g) ('abc')) (['abc']); + eq (S.splitOnRegex (/b(?=c)/g) ('abc abd')) (['a', 'c abd']); + eq (S.splitOnRegex (/b(?!c)/g) ('abc abd')) (['abc a', 'd']); - eq(S.splitOnRegex(/\s+/g, 'foo bar baz qux'), ['foo', 'bar', 'baz', 'qux']); - eq(S.splitOnRegex(/\s+/g, 'foo bar baz\tqux\nquux'), ['foo', 'bar', 'baz', 'qux', 'quux']); - eq(S.splitOnRegex(/\s+/g, 'foobar'), ['foobar']); - eq(S.splitOnRegex(/([:;])\1/g, 'foo::bar:;baz;;quux'), ['foo', 'bar:;baz', 'quux']); + eq (S.splitOnRegex (/\s+/g) ('foo bar baz qux')) (['foo', 'bar', 'baz', 'qux']); + eq (S.splitOnRegex (/\s+/g) ('foo bar baz\tqux\nquux')) (['foo', 'bar', 'baz', 'qux', 'quux']); + eq (S.splitOnRegex (/\s+/g) ('foobar')) (['foobar']); + eq (S.splitOnRegex (/([:;])\1/g) ('foo::bar:;baz;;quux')) (['foo', 'bar:;baz', 'quux']); - eq(S.splitOnRegex(/./g, 'a\rb\nc'), ['', '\r', '\n', '']); - eq(S.splitOnRegex(/[^]/g, 'a\nb'), ['', '', '', '']); + eq (S.splitOnRegex (/./g) ('a\rb\nc')) (['', '\r', '\n', '']); + eq (S.splitOnRegex (/[^]/g) ('a\nb')) (['', '', '', '']); - eq(S.splitOnRegex(/^/g, 'foo\nbar\nbaz\n'), ['foo\nbar\nbaz\n']); - eq(S.splitOnRegex(/^/gm, 'foo\nbar\nbaz\n'), ['foo\n', 'bar\n', 'baz\n']); + eq (S.splitOnRegex (/^/g) ('foo\nbar\nbaz\n')) (['foo\nbar\nbaz\n']); + eq (S.splitOnRegex (/^/gm) ('foo\nbar\nbaz\n')) (['foo\n', 'bar\n', 'baz\n']); - eq(S.splitOnRegex(/foo/g, 'FOObar'), ['FOObar']); - eq(S.splitOnRegex(/foo/gi, 'FOObar'), ['', 'bar']); + eq (S.splitOnRegex (/foo/g) ('FOObar')) (['FOObar']); + eq (S.splitOnRegex (/foo/gi) ('FOObar')) (['', 'bar']); - eq(S.splitOnRegex(/(?:)/g, ''), []); - eq(S.splitOnRegex(/(?:)/g, 'a'), ['a']); - eq(S.splitOnRegex(/(?:)/g, 'ab'), ['a', 'b']); - eq(S.splitOnRegex(/(?:)/g, 'abc'), ['a', 'b', 'c']); + eq (S.splitOnRegex (/(?:)/g) ('')) ([]); + eq (S.splitOnRegex (/(?:)/g) ('a')) (['a']); + eq (S.splitOnRegex (/(?:)/g) ('ab')) (['a', 'b']); + eq (S.splitOnRegex (/(?:)/g) ('abc')) (['a', 'b', 'c']); - eq(S.splitOnRegex(/[^]/g, ''), ['']); - eq(S.splitOnRegex(/[^]/g, 'a'), ['', '']); - eq(S.splitOnRegex(/[^]/g, 'ab'), ['', '', '']); - eq(S.splitOnRegex(/[^]/g, 'abc'), ['', '', '', '']); + eq (S.splitOnRegex (/[^]/g) ('')) (['']); + eq (S.splitOnRegex (/[^]/g) ('a')) (['', '']); + eq (S.splitOnRegex (/[^]/g) ('ab')) (['', '', '']); + eq (S.splitOnRegex (/[^]/g) ('abc')) (['', '', '', '']); - eq(S.splitOnRegex(/.*/g, ''), []); - eq(S.splitOnRegex(/.*/g, 'hello'), ['']); - eq(S.splitOnRegex(/./g, ''), ['']); - eq(S.splitOnRegex(/./g, 'hello'), ['', '', '', '', '', '']); + eq (S.splitOnRegex (/.*/g) ('')) ([]); + eq (S.splitOnRegex (/.*/g) ('hello')) (['']); + eq (S.splitOnRegex (/./g) ('')) (['']); + eq (S.splitOnRegex (/./g) ('hello')) (['', '', '', '', '', '']); - jsc.assert(jsc.forall(jsc.asciistring, function(t) { + jsc.assert (jsc.forall (jsc.asciistring, function(t) { var min = 0; var max = t.length; - var i = jsc.random(min, max); - var j = jsc.random(min, max); - var s = t.slice(Math.min(i, j), Math.max(i, j)); - var lhs = S.joinWith(s, S.splitOnRegex(S.regex('g', S.regexEscape(s)), t)); + var i = jsc.random (min, max); + var j = jsc.random (min, max); + var s = t.slice (Math.min (i, j), Math.max (i, j)); + var lhs = S.joinWith (s) (S.splitOnRegex (S.regex ('g') (S.regexEscape (s))) (t)); var rhs = t; - return equals(lhs)(rhs); + return equals (lhs) (rhs); }), {tests: 1000}); }); diff --git a/test/stripPrefix.js b/test/stripPrefix.js index eccd1dc8..a80d308d 100644 --- a/test/stripPrefix.js +++ b/test/stripPrefix.js @@ -1,23 +1,23 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('stripPrefix', function() { +test ('stripPrefix', function() { - eq(typeof S.stripPrefix, 'function'); - eq(S.stripPrefix.length, 2); - eq(S.stripPrefix.toString(), 'stripPrefix :: String -> String -> Maybe String'); + eq (typeof S.stripPrefix) ('function'); + eq (S.stripPrefix.length) (1); + eq (String (S.stripPrefix)) ('stripPrefix :: String -> String -> Maybe String'); - eq(S.stripPrefix('', ''), S.Just('')); - eq(S.stripPrefix('', 'abc'), S.Just('abc')); - eq(S.stripPrefix('a', ''), S.Nothing); - eq(S.stripPrefix('a', 'abc'), S.Just('bc')); - eq(S.stripPrefix('a', '[abc]'), S.Nothing); - eq(S.stripPrefix('aaa', 'a'), S.Nothing); - eq(S.stripPrefix('https://', 'https://sanctuary.js.org'), S.Just('sanctuary.js.org')); - eq(S.stripPrefix('https://', 'http://sanctuary.js.org'), S.Nothing); + eq (S.stripPrefix ('') ('')) (S.Just ('')); + eq (S.stripPrefix ('') ('abc')) (S.Just ('abc')); + eq (S.stripPrefix ('a') ('')) (S.Nothing); + eq (S.stripPrefix ('a') ('abc')) (S.Just ('bc')); + eq (S.stripPrefix ('a') ('[abc]')) (S.Nothing); + eq (S.stripPrefix ('aaa') ('a')) (S.Nothing); + eq (S.stripPrefix ('https://') ('https://sanctuary.js.org')) (S.Just ('sanctuary.js.org')); + eq (S.stripPrefix ('https://') ('http://sanctuary.js.org')) (S.Nothing); }); diff --git a/test/stripSuffix.js b/test/stripSuffix.js index b3d1dbdf..ebd02203 100644 --- a/test/stripSuffix.js +++ b/test/stripSuffix.js @@ -1,23 +1,23 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('stripSuffix', function() { +test ('stripSuffix', function() { - eq(typeof S.stripSuffix, 'function'); - eq(S.stripSuffix.length, 2); - eq(S.stripSuffix.toString(), 'stripSuffix :: String -> String -> Maybe String'); + eq (typeof S.stripSuffix) ('function'); + eq (S.stripSuffix.length) (1); + eq (String (S.stripSuffix)) ('stripSuffix :: String -> String -> Maybe String'); - eq(S.stripSuffix('', ''), S.Just('')); - eq(S.stripSuffix('', 'xyz'), S.Just('xyz')); - eq(S.stripSuffix('z', ''), S.Nothing); - eq(S.stripSuffix('z', 'xyz'), S.Just('xy')); - eq(S.stripSuffix('z', '[xyz]'), S.Nothing); - eq(S.stripSuffix('zzz', 'z'), S.Nothing); - eq(S.stripSuffix('.md', 'README.md'), S.Just('README')); - eq(S.stripSuffix('.md', 'README'), S.Nothing); + eq (S.stripSuffix ('') ('')) (S.Just ('')); + eq (S.stripSuffix ('') ('xyz')) (S.Just ('xyz')); + eq (S.stripSuffix ('z') ('')) (S.Nothing); + eq (S.stripSuffix ('z') ('xyz')) (S.Just ('xy')); + eq (S.stripSuffix ('z') ('[xyz]')) (S.Nothing); + eq (S.stripSuffix ('zzz') ('z')) (S.Nothing); + eq (S.stripSuffix ('.md') ('README.md')) (S.Just ('README')); + eq (S.stripSuffix ('.md') ('README')) (S.Nothing); }); diff --git a/test/sub.js b/test/sub.js index bf296a47..164ccbc2 100644 --- a/test/sub.js +++ b/test/sub.js @@ -1,16 +1,16 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('sub', function() { +test ('sub', function() { - eq(typeof S.sub, 'function'); - eq(S.sub.length, 1); - eq(S.sub.toString(), 'sub :: FiniteNumber -> (FiniteNumber -> FiniteNumber)'); + eq (typeof S.sub) ('function'); + eq (S.sub.length) (1); + eq (String (S.sub)) ('sub :: FiniteNumber -> FiniteNumber -> FiniteNumber'); - eq(S.map(S.sub(1), [1, 2, 3]), [0, 1, 2]); + eq (S.map (S.sub (1)) ([1, 2, 3])) ([0, 1, 2]); }); diff --git a/test/sum.js b/test/sum.js index 17c13c5d..028b5ba1 100644 --- a/test/sum.js +++ b/test/sum.js @@ -1,25 +1,25 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('sum', function() { +test ('sum', function() { - eq(typeof S.sum, 'function'); - eq(S.sum.length, 1); - eq(S.sum.toString(), 'sum :: Foldable f => f FiniteNumber -> FiniteNumber'); + eq (typeof S.sum) ('function'); + eq (S.sum.length) (1); + eq (String (S.sum)) ('sum :: Foldable f => f FiniteNumber -> FiniteNumber'); - eq(S.sum([]), 0); - eq(S.sum([0, 1, 2, 3]), 6); - eq(S.sum([1, 2, 3, 4, 5]), 15); - eq(S.sum([1, 2, 3, 4, -5]), 5); + eq (S.sum ([])) (0); + eq (S.sum ([0, 1, 2, 3])) (6); + eq (S.sum ([1, 2, 3, 4, 5])) (15); + eq (S.sum ([1, 2, 3, 4, -5])) (5); - eq(S.sum(S.Nothing), 0); - eq(S.sum(S.Just(42)), 42); + eq (S.sum (S.Nothing)) (0); + eq (S.sum (S.Just (42))) (42); - eq(S.sum(S.Left('xxx')), 0); - eq(S.sum(S.Right(42)), 42); + eq (S.sum (S.Left ('xxx'))) (0); + eq (S.sum (S.Right (42))) (42); }); diff --git a/test/tagBy.js b/test/tagBy.js index 80f9f503..18799bc6 100644 --- a/test/tagBy.js +++ b/test/tagBy.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('tagBy', function() { +test ('tagBy', function() { - eq(typeof S.tagBy, 'function'); - eq(S.tagBy.length, 2); - eq(S.tagBy.toString(), 'tagBy :: (a -> Boolean) -> a -> Either a a'); + eq (typeof S.tagBy) ('function'); + eq (S.tagBy.length) (1); + eq (String (S.tagBy)) ('tagBy :: (a -> Boolean) -> a -> Either a a'); - eq(S.tagBy(S.odd, 5), S.Right(5)); - eq(S.tagBy(S.odd, 6), S.Left(6)); + eq (S.tagBy (S.odd) (5)) (S.Right (5)); + eq (S.tagBy (S.odd) (6)) (S.Left (6)); }); diff --git a/test/tail.js b/test/tail.js index 04f040b2..938234ab 100644 --- a/test/tail.js +++ b/test/tail.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('tail', function() { +test ('tail', function() { - eq(typeof S.tail, 'function'); - eq(S.tail.length, 1); - eq(S.tail.toString(), 'tail :: Array a -> Maybe (Array a)'); + eq (typeof S.tail) ('function'); + eq (S.tail.length) (1); + eq (String (S.tail)) ('tail :: Array a -> Maybe (Array a)'); - eq(S.tail([]), S.Nothing); - eq(S.tail(['foo']), S.Just([])); - eq(S.tail(['foo', 'bar']), S.Just(['bar'])); - eq(S.tail(['foo', 'bar', 'baz']), S.Just(['bar', 'baz'])); + eq (S.tail ([])) (S.Nothing); + eq (S.tail (['foo'])) (S.Just ([])); + eq (S.tail (['foo', 'bar'])) (S.Just (['bar'])); + eq (S.tail (['foo', 'bar', 'baz'])) (S.Just (['bar', 'baz'])); }); diff --git a/test/take.js b/test/take.js index d371d4ea..c14ba4e1 100644 --- a/test/take.js +++ b/test/take.js @@ -1,24 +1,24 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('take', function() { +test ('take', function() { - eq(typeof S.take, 'function'); - eq(S.take.length, 2); - eq(S.take.toString(), 'take :: Integer -> Array a -> Maybe (Array a)'); + eq (typeof S.take) ('function'); + eq (S.take.length) (1); + eq (String (S.take)) ('take :: Integer -> Array a -> Maybe (Array a)'); - eq(S.take(0, [1, 2, 3, 4, 5]), S.Just([])); - eq(S.take(1, [1, 2, 3, 4, 5]), S.Just([1])); - eq(S.take(2, [1, 2, 3, 4, 5]), S.Just([1, 2])); - eq(S.take(3, [1, 2, 3, 4, 5]), S.Just([1, 2, 3])); - eq(S.take(4, [1, 2, 3, 4, 5]), S.Just([1, 2, 3, 4])); - eq(S.take(5, [1, 2, 3, 4, 5]), S.Just([1, 2, 3, 4, 5])); - eq(S.take(6, [1, 2, 3, 4, 5]), S.Nothing); + eq (S.take (0) ([1, 2, 3, 4, 5])) (S.Just ([])); + eq (S.take (1) ([1, 2, 3, 4, 5])) (S.Just ([1])); + eq (S.take (2) ([1, 2, 3, 4, 5])) (S.Just ([1, 2])); + eq (S.take (3) ([1, 2, 3, 4, 5])) (S.Just ([1, 2, 3])); + eq (S.take (4) ([1, 2, 3, 4, 5])) (S.Just ([1, 2, 3, 4])); + eq (S.take (5) ([1, 2, 3, 4, 5])) (S.Just ([1, 2, 3, 4, 5])); + eq (S.take (6) ([1, 2, 3, 4, 5])) (S.Nothing); - eq(S.take(-1, [1, 2, 3, 4, 5]), S.Nothing); + eq (S.take (-1) ([1, 2, 3, 4, 5])) (S.Nothing); }); diff --git a/test/takeLast.js b/test/takeLast.js index 8dc7163f..9f3a0e58 100644 --- a/test/takeLast.js +++ b/test/takeLast.js @@ -1,24 +1,24 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('takeLast', function() { +test ('takeLast', function() { - eq(typeof S.takeLast, 'function'); - eq(S.takeLast.length, 2); - eq(S.takeLast.toString(), 'takeLast :: Integer -> Array a -> Maybe (Array a)'); + eq (typeof S.takeLast) ('function'); + eq (S.takeLast.length) (1); + eq (String (S.takeLast)) ('takeLast :: Integer -> Array a -> Maybe (Array a)'); - eq(S.takeLast(0, [1, 2, 3, 4, 5]), S.Just([])); - eq(S.takeLast(1, [1, 2, 3, 4, 5]), S.Just([5])); - eq(S.takeLast(2, [1, 2, 3, 4, 5]), S.Just([4, 5])); - eq(S.takeLast(3, [1, 2, 3, 4, 5]), S.Just([3, 4, 5])); - eq(S.takeLast(4, [1, 2, 3, 4, 5]), S.Just([2, 3, 4, 5])); - eq(S.takeLast(5, [1, 2, 3, 4, 5]), S.Just([1, 2, 3, 4, 5])); - eq(S.takeLast(6, [1, 2, 3, 4, 5]), S.Nothing); + eq (S.takeLast (0) ([1, 2, 3, 4, 5])) (S.Just ([])); + eq (S.takeLast (1) ([1, 2, 3, 4, 5])) (S.Just ([5])); + eq (S.takeLast (2) ([1, 2, 3, 4, 5])) (S.Just ([4, 5])); + eq (S.takeLast (3) ([1, 2, 3, 4, 5])) (S.Just ([3, 4, 5])); + eq (S.takeLast (4) ([1, 2, 3, 4, 5])) (S.Just ([2, 3, 4, 5])); + eq (S.takeLast (5) ([1, 2, 3, 4, 5])) (S.Just ([1, 2, 3, 4, 5])); + eq (S.takeLast (6) ([1, 2, 3, 4, 5])) (S.Nothing); - eq(S.takeLast(-1, [1, 2, 3, 4, 5]), S.Nothing); + eq (S.takeLast (-1) ([1, 2, 3, 4, 5])) (S.Nothing); }); diff --git a/test/takeWhile.js b/test/takeWhile.js index d4b62569..20215d8a 100644 --- a/test/takeWhile.js +++ b/test/takeWhile.js @@ -1,22 +1,22 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('takeWhile', function() { +test ('takeWhile', function() { - eq(typeof S.takeWhile, 'function'); - eq(S.takeWhile.length, 2); - eq(S.takeWhile.toString(), 'takeWhile :: Filterable f => (a -> Boolean) -> f a -> f a'); + eq (typeof S.takeWhile) ('function'); + eq (S.takeWhile.length) (1); + eq (String (S.takeWhile)) ('takeWhile :: Filterable f => (a -> Boolean) -> f a -> f a'); - eq(S.takeWhile(S.odd, [3, 3, 3, 7, 6, 3, 5, 4]), [3, 3, 3, 7]); - eq(S.takeWhile(S.even, [3, 3, 3, 7, 6, 3, 5, 4]), []); - eq(S.takeWhile(S.odd, []), []); + eq (S.takeWhile (S.odd) ([3, 3, 3, 7, 6, 3, 5, 4])) ([3, 3, 3, 7]); + eq (S.takeWhile (S.even) ([3, 3, 3, 7, 6, 3, 5, 4])) ([]); + eq (S.takeWhile (S.odd) ([])) ([]); - eq(S.takeWhile(S.odd, S.Just(1)), S.Just(1)); - eq(S.takeWhile(S.even, S.Just(1)), S.Nothing); - eq(S.takeWhile(S.odd, S.Nothing), S.Nothing); + eq (S.takeWhile (S.odd) (S.Just (1))) (S.Just (1)); + eq (S.takeWhile (S.even) (S.Just (1))) (S.Nothing); + eq (S.takeWhile (S.odd) (S.Nothing)) (S.Nothing); }); diff --git a/test/test.js b/test/test.js index 93091017..681cbd18 100644 --- a/test/test.js +++ b/test/test.js @@ -1,23 +1,23 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('test', function() { +test ('test', function() { - eq(typeof S.test, 'function'); - eq(S.test.length, 2); - eq(S.test.toString(), 'test :: RegExp -> String -> Boolean'); + eq (typeof S.test) ('function'); + eq (S.test.length) (1); + eq (String (S.test)) ('test :: RegExp -> String -> Boolean'); - eq(S.test(/^a/, 'abacus'), true); - eq(S.test(/^a/, 'banana'), false); + eq (S.test (/^a/) ('abacus')) (true); + eq (S.test (/^a/) ('banana')) (false); var pattern = /x/g; - eq(pattern.lastIndex, 0); - eq(S.test(pattern, 'xyz'), true); - eq(pattern.lastIndex, 0); - eq(S.test(pattern, 'xyz'), true); + eq (pattern.lastIndex) (0); + eq (S.test (pattern) ('xyz')) (true); + eq (pattern.lastIndex) (0); + eq (S.test (pattern) ('xyz')) (true); }); diff --git a/test/toEither.js b/test/toEither.js index 77831b72..6a239f71 100644 --- a/test/toEither.js +++ b/test/toEither.js @@ -1,18 +1,18 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('toEither', function() { +test ('toEither', function() { - eq(typeof S.toEither, 'function'); - eq(S.toEither.length, 2); - eq(S.toEither.toString(), 'toEither :: a -> b -> Either a b'); + eq (typeof S.toEither) ('function'); + eq (S.toEither.length) (1); + eq (String (S.toEither)) ('toEither :: a -> b -> Either a b'); - eq(S.toEither('a', null), S.Left('a')); - eq(S.toEither('a', undefined), S.Left('a')); - eq(S.toEither('a', 42), S.Right(42)); + eq (S.toEither ('a') (null)) (S.Left ('a')); + eq (S.toEither ('a') (undefined)) (S.Left ('a')); + eq (S.toEither ('a') (42)) (S.Right (42)); }); diff --git a/test/toLower.js b/test/toLower.js index 1186ad6d..5112d91f 100644 --- a/test/toLower.js +++ b/test/toLower.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('toLower', function() { +test ('toLower', function() { - eq(typeof S.toLower, 'function'); - eq(S.toLower.length, 1); - eq(S.toLower.toString(), 'toLower :: String -> String'); + eq (typeof S.toLower) ('function'); + eq (S.toLower.length) (1); + eq (String (S.toLower)) ('toLower :: String -> String'); - eq(S.toLower(''), ''); - eq(S.toLower('ABC def 123'), 'abc def 123'); + eq (S.toLower ('')) (''); + eq (S.toLower ('ABC def 123')) ('abc def 123'); }); diff --git a/test/toMaybe.js b/test/toMaybe.js index 770f1e72..8e32b858 100644 --- a/test/toMaybe.js +++ b/test/toMaybe.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('toMaybe', function() { +test ('toMaybe', function() { - eq(typeof S.toMaybe, 'function'); - eq(S.toMaybe.length, 1); - eq(S.toMaybe.toString(), 'toMaybe :: a -> Maybe a'); + eq (typeof S.toMaybe) ('function'); + eq (S.toMaybe.length) (1); + eq (String (S.toMaybe)) ('toMaybe :: a -> Maybe a'); - eq(S.toMaybe(null), S.Nothing); - eq(S.toMaybe(undefined), S.Nothing); - eq(S.toMaybe(0), S.Just(0)); - eq(S.toMaybe(false), S.Just(false)); + eq (S.toMaybe (null)) (S.Nothing); + eq (S.toMaybe (undefined)) (S.Nothing); + eq (S.toMaybe (0)) (S.Just (0)); + eq (S.toMaybe (false)) (S.Just (false)); }); diff --git a/test/toString.js b/test/toString.js index 110bbaca..8bae86c6 100644 --- a/test/toString.js +++ b/test/toString.js @@ -1,57 +1,57 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('toString', function() { +test ('toString', function() { - eq(typeof S.toString, 'function'); - eq(S.toString.length, 1); - eq(S.toString.toString(), 'toString :: Any -> String'); + eq (typeof S.toString) ('function'); + eq (S.toString.length) (1); + eq (String (S.toString)) ('toString :: Any -> String'); - eq(S.toString(null), 'null'); - eq(S.toString(undefined), 'undefined'); - eq(S.toString(false), 'false'); - eq(S.toString(true), 'true'); - eq(S.toString(new Boolean(false)), 'new Boolean(false)'); - eq(S.toString(new Boolean(true)), 'new Boolean(true)'); - eq(S.toString(0), '0'); - eq(S.toString(-0), '-0'); - eq(S.toString(NaN), 'NaN'); - eq(S.toString(Math.PI), '3.141592653589793'); - eq(S.toString(-Math.PI), '-3.141592653589793'); - eq(S.toString(Infinity), 'Infinity'); - eq(S.toString(-Infinity), '-Infinity'); - eq(S.toString(new Number(0)), 'new Number(0)'); - eq(S.toString(new Number(-0)), 'new Number(-0)'); - eq(S.toString(new Number(NaN)), 'new Number(NaN)'); - eq(S.toString(new Number(Math.PI)), 'new Number(3.141592653589793)'); - eq(S.toString(new Number(-Math.PI)), 'new Number(-3.141592653589793)'); - eq(S.toString(new Number(Infinity)), 'new Number(Infinity)'); - eq(S.toString(new Number(-Infinity)), 'new Number(-Infinity)'); - eq(S.toString(''), '""'); - eq(S.toString('foo'), '"foo"'); - eq(S.toString('foo "bar" baz'), '"foo \\"bar\\" baz"'); - eq(S.toString(new String('')), 'new String("")'); - eq(S.toString(new String('foo')), 'new String("foo")'); - eq(S.toString(new String('foo "bar" baz')), 'new String("foo \\"bar\\" baz")'); - eq(S.toString(new Date(0)), 'new Date("1970-01-01T00:00:00.000Z")'); - eq(S.toString(new Date(42)), 'new Date("1970-01-01T00:00:00.042Z")'); - eq(S.toString(new Date(NaN)), 'new Date(NaN)'); - eq(S.toString(new Date('2001-02-03')), 'new Date("2001-02-03T00:00:00.000Z")'); - eq(S.toString([]), '[]'); - eq(S.toString(['foo']), '["foo"]'); - eq(S.toString(['foo', 'bar', 'baz']), '["foo", "bar", "baz"]'); - eq(S.toString(['foo "bar" baz']), '["foo \\"bar\\" baz"]'); - eq(S.toString({}), '{}'); - eq(S.toString({x: 1}), '{"x": 1}'); - eq(S.toString({x: 1, y: 2, z: 3}), '{"x": 1, "y": 2, "z": 3}'); - eq(S.toString({'foo "bar" baz': '"quux"'}), '{"foo \\"bar\\" baz": "\\"quux\\""}'); - eq(S.toString(S.Nothing), 'Nothing'); - eq(S.toString(S.Just(9)), 'Just(9)'); - eq(S.toString(S.Left(false)), 'Left(false)'); - eq(S.toString(S.Right(true)), 'Right(true)'); + eq (S.toString (null)) ('null'); + eq (S.toString (undefined)) ('undefined'); + eq (S.toString (false)) ('false'); + eq (S.toString (true)) ('true'); + eq (S.toString (new Boolean (false))) ('new Boolean(false)'); + eq (S.toString (new Boolean (true))) ('new Boolean(true)'); + eq (S.toString (0)) ('0'); + eq (S.toString (-0)) ('-0'); + eq (S.toString (NaN)) ('NaN'); + eq (S.toString (Math.PI)) ('3.141592653589793'); + eq (S.toString (-Math.PI)) ('-3.141592653589793'); + eq (S.toString (Infinity)) ('Infinity'); + eq (S.toString (-Infinity)) ('-Infinity'); + eq (S.toString (new Number (0))) ('new Number(0)'); + eq (S.toString (new Number (-0))) ('new Number(-0)'); + eq (S.toString (new Number (NaN))) ('new Number(NaN)'); + eq (S.toString (new Number (Math.PI))) ('new Number(3.141592653589793)'); + eq (S.toString (new Number (-Math.PI))) ('new Number(-3.141592653589793)'); + eq (S.toString (new Number (Infinity))) ('new Number(Infinity)'); + eq (S.toString (new Number (-Infinity))) ('new Number(-Infinity)'); + eq (S.toString ('')) ('""'); + eq (S.toString ('foo')) ('"foo"'); + eq (S.toString ('foo "bar" baz')) ('"foo \\"bar\\" baz"'); + eq (S.toString (new String (''))) ('new String("")'); + eq (S.toString (new String ('foo'))) ('new String("foo")'); + eq (S.toString (new String ('foo "bar" baz'))) ('new String("foo \\"bar\\" baz")'); + eq (S.toString (new Date (0))) ('new Date("1970-01-01T00:00:00.000Z")'); + eq (S.toString (new Date (42))) ('new Date("1970-01-01T00:00:00.042Z")'); + eq (S.toString (new Date (NaN))) ('new Date(NaN)'); + eq (S.toString (new Date ('2001-02-03'))) ('new Date("2001-02-03T00:00:00.000Z")'); + eq (S.toString ([])) ('[]'); + eq (S.toString (['foo'])) ('["foo"]'); + eq (S.toString (['foo', 'bar', 'baz'])) ('["foo", "bar", "baz"]'); + eq (S.toString (['foo "bar" baz'])) ('["foo \\"bar\\" baz"]'); + eq (S.toString ({})) ('{}'); + eq (S.toString ({x: 1})) ('{"x": 1}'); + eq (S.toString ({x: 1, y: 2, z: 3})) ('{"x": 1, "y": 2, "z": 3}'); + eq (S.toString ({'foo "bar" baz': '"quux"'})) ('{"foo \\"bar\\" baz": "\\"quux\\""}'); + eq (S.toString (S.Nothing)) ('Nothing'); + eq (S.toString (S.Just (9))) ('Just(9)'); + eq (S.toString (S.Left (false))) ('Left(false)'); + eq (S.toString (S.Right (true))) ('Right(true)'); }); diff --git a/test/toUpper.js b/test/toUpper.js index 13069c96..c4ad4562 100644 --- a/test/toUpper.js +++ b/test/toUpper.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('toUpper', function() { +test ('toUpper', function() { - eq(typeof S.toUpper, 'function'); - eq(S.toUpper.length, 1); - eq(S.toUpper.toString(), 'toUpper :: String -> String'); + eq (typeof S.toUpper) ('function'); + eq (S.toUpper.length) (1); + eq (String (S.toUpper)) ('toUpper :: String -> String'); - eq(S.toUpper(''), ''); - eq(S.toUpper('ABC def 123'), 'ABC DEF 123'); + eq (S.toUpper ('')) (''); + eq (S.toUpper ('ABC def 123')) ('ABC DEF 123'); }); diff --git a/test/traverse.js b/test/traverse.js index 5dc9ee6c..9d0b5ac8 100644 --- a/test/traverse.js +++ b/test/traverse.js @@ -1,37 +1,37 @@ 'use strict'; -var S = require('./internal/sanctuary'); +var S = require ('./internal/sanctuary'); -var Identity = require('./internal/Identity'); -var eq = require('./internal/eq'); +var Identity = require ('./internal/Identity'); +var eq = require ('./internal/eq'); -test('traverse', function() { +test ('traverse', function() { - eq(typeof S.traverse, 'function'); - eq(S.traverse.length, 3); - eq(S.traverse.toString(), 'traverse :: (Applicative f, Traversable t) => TypeRep f -> (a -> f b) -> t a -> f (t b)'); + eq (typeof S.traverse) ('function'); + eq (S.traverse.length) (1); + eq (String (S.traverse)) ('traverse :: (Applicative f, Traversable t) => TypeRep f -> (a -> f b) -> t a -> f (t b)'); - eq(S.traverse(S.Maybe, S.parseInt(16), ['A', 'B', 'C']), S.Just([10, 11, 12])); - eq(S.traverse(S.Maybe, S.parseInt(16), ['A', 'B', 'C', 'X']), S.Nothing); - eq(S.traverse(S.Maybe, S.parseInt(16), {a: 'A', b: 'B', c: 'C'}), S.Just({a: 10, b: 11, c: 12})); - eq(S.traverse(S.Maybe, S.parseInt(16), {a: 'A', b: 'B', c: 'C', x: 'X'}), S.Nothing); + eq (S.traverse (S.Maybe) (S.parseInt (16)) (['A', 'B', 'C'])) (S.Just ([10, 11, 12])); + eq (S.traverse (S.Maybe) (S.parseInt (16)) (['A', 'B', 'C', 'X'])) (S.Nothing); + eq (S.traverse (S.Maybe) (S.parseInt (16)) ({a: 'A', b: 'B', c: 'C'})) (S.Just ({a: 10, b: 11, c: 12})); + eq (S.traverse (S.Maybe) (S.parseInt (16)) ({a: 'A', b: 'B', c: 'C', x: 'X'})) (S.Nothing); - eq(S.traverse(Array, S.I, []), [[]]); - eq(S.traverse(Array, S.I, [['A', 'a']]), [['A'], ['a']]); - eq(S.traverse(Array, S.I, [['A', 'a'], ['B']]), [['A', 'B'], ['a', 'B']]); - eq(S.traverse(Array, S.I, [['A', 'a'], ['B', 'b']]), [['A', 'B'], ['A', 'b'], ['a', 'B'], ['a', 'b']]); + eq (S.traverse (Array) (S.I) ([])) ([[]]); + eq (S.traverse (Array) (S.I) ([['A', 'a']])) ([['A'], ['a']]); + eq (S.traverse (Array) (S.I) ([['A', 'a'], ['B']])) ([['A', 'B'], ['a', 'B']]); + eq (S.traverse (Array) (S.I) ([['A', 'a'], ['B', 'b']])) ([['A', 'B'], ['A', 'b'], ['a', 'B'], ['a', 'b']]); - eq(S.traverse(Array, S.words, Identity('')), []); - eq(S.traverse(Array, S.words, Identity('foo')), [Identity('foo')]); - eq(S.traverse(Array, S.words, Identity('foo bar')), [Identity('foo'), Identity('bar')]); - eq(S.traverse(Array, S.words, Identity('foo bar baz')), [Identity('foo'), Identity('bar'), Identity('baz')]); + eq (S.traverse (Array) (S.words) (Identity (''))) ([]); + eq (S.traverse (Array) (S.words) (Identity ('foo'))) ([Identity ('foo')]); + eq (S.traverse (Array) (S.words) (Identity ('foo bar'))) ([Identity ('foo'), Identity ('bar')]); + eq (S.traverse (Array) (S.words) (Identity ('foo bar baz'))) ([Identity ('foo'), Identity ('bar'), Identity ('baz')]); - eq(S.traverse(Identity, S.I, []), Identity([])); - eq(S.traverse(Identity, S.I, [Identity(1)]), Identity([1])); - eq(S.traverse(Identity, S.I, [Identity(1), Identity(2)]), Identity([1, 2])); - eq(S.traverse(Identity, S.I, [Identity(1), Identity(2), Identity(3)]), Identity([1, 2, 3])); + eq (S.traverse (Identity) (S.I) ([])) (Identity ([])); + eq (S.traverse (Identity) (S.I) ([Identity (1)])) (Identity ([1])); + eq (S.traverse (Identity) (S.I) ([Identity (1), Identity (2)])) (Identity ([1, 2])); + eq (S.traverse (Identity) (S.I) ([Identity (1), Identity (2), Identity (3)])) (Identity ([1, 2, 3])); - eq(S.traverse(Array, S.I, {a: [1, 2], b: [3, 4]}), [{a: 1, b: 3}, {a: 1, b: 4}, {a: 2, b: 3}, {a: 2, b: 4}]); + eq (S.traverse (Array) (S.I) ({a: [1, 2], b: [3, 4]})) ([{a: 1, b: 3}, {a: 1, b: 4}, {a: 2, b: 3}, {a: 2, b: 4}]); }); diff --git a/test/trim.js b/test/trim.js index fef56bbf..910f357d 100644 --- a/test/trim.js +++ b/test/trim.js @@ -1,22 +1,22 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('trim', function() { +test ('trim', function() { - eq(typeof S.trim, 'function'); - eq(S.trim.length, 1); - eq(S.trim.toString(), 'trim :: String -> String'); + eq (typeof S.trim) ('function'); + eq (S.trim.length) (1); + eq (String (S.trim)) ('trim :: String -> String'); - eq(S.trim(''), ''); - eq(S.trim(' '), ''); - eq(S.trim('x'), 'x'); - eq(S.trim(' x'), 'x'); - eq(S.trim('x '), 'x'); - eq(S.trim(' x '), 'x'); - eq(S.trim('\n\r\t x \n\r\t x \n\r\t'), 'x \n\r\t x'); + eq (S.trim ('')) (''); + eq (S.trim (' ')) (''); + eq (S.trim ('x')) ('x'); + eq (S.trim (' x')) ('x'); + eq (S.trim ('x ')) ('x'); + eq (S.trim (' x ')) ('x'); + eq (S.trim ('\n\r\t x \n\r\t x \n\r\t')) ('x \n\r\t x'); }); diff --git a/test/type.js b/test/type.js index d77300cc..8af47d0f 100644 --- a/test/type.js +++ b/test/type.js @@ -1,46 +1,67 @@ 'use strict'; -var vm = require('vm'); +var vm = require ('vm'); -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('type', function() { +test ('type', function() { - eq(typeof S.type, 'function'); - eq(S.type.length, 1); - eq(S.type.toString(), 'type :: Any -> { name :: String, namespace :: Maybe String, version :: NonNegativeInteger }'); + eq (typeof S.type) ('function'); + eq (S.type.length) (1); + eq (String (S.type)) ('type :: Any -> { name :: String, namespace :: Maybe String, version :: NonNegativeInteger }'); - var args = (function() { return arguments; }()); - eq(S.type(args), {namespace: S.Nothing, name: 'Arguments', version: 0}); - eq(S.type([]), {namespace: S.Nothing, name: 'Array', version: 0}); - eq(S.type(false), {namespace: S.Nothing, name: 'Boolean', version: 0}); - eq(S.type(new Date(0)), {namespace: S.Nothing, name: 'Date', version: 0}); - eq(S.type(new TypeError()), {namespace: S.Nothing, name: 'Error', version: 0}); - eq(S.type(function() {}), {namespace: S.Nothing, name: 'Function', version: 0}); - eq(S.type(null), {namespace: S.Nothing, name: 'Null', version: 0}); - eq(S.type(0), {namespace: S.Nothing, name: 'Number', version: 0}); - eq(S.type(/(?:)/), {namespace: S.Nothing, name: 'RegExp', version: 0}); - eq(S.type(''), {namespace: S.Nothing, name: 'String', version: 0}); - eq(S.type(undefined), {namespace: S.Nothing, name: 'Undefined', version: 0}); - eq(S.type(new Boolean(false)), {namespace: S.Nothing, name: 'Boolean', version: 0}); - eq(S.type(new Number(0)), {namespace: S.Nothing, name: 'Number', version: 0}); - eq(S.type(new String('')), {namespace: S.Nothing, name: 'String', version: 0}); + eq (S.type (function() { return arguments; } ())) + ({namespace: S.Nothing, name: 'Arguments', version: 0}); + eq (S.type ([])) + ({namespace: S.Nothing, name: 'Array', version: 0}); + eq (S.type (false)) + ({namespace: S.Nothing, name: 'Boolean', version: 0}); + eq (S.type (new Date (0))) + ({namespace: S.Nothing, name: 'Date', version: 0}); + eq (S.type (new TypeError ())) + ({namespace: S.Nothing, name: 'Error', version: 0}); + eq (S.type (function() {})) + ({namespace: S.Nothing, name: 'Function', version: 0}); + eq (S.type (null)) + ({namespace: S.Nothing, name: 'Null', version: 0}); + eq (S.type (0)) + ({namespace: S.Nothing, name: 'Number', version: 0}); + eq (S.type (/(?:)/)) + ({namespace: S.Nothing, name: 'RegExp', version: 0}); + eq (S.type ('')) + ({namespace: S.Nothing, name: 'String', version: 0}); + eq (S.type (undefined)) + ({namespace: S.Nothing, name: 'Undefined', version: 0}); + eq (S.type (new Boolean (false))) + ({namespace: S.Nothing, name: 'Boolean', version: 0}); + eq (S.type (new Number (0))) + ({namespace: S.Nothing, name: 'Number', version: 0}); + eq (S.type (new String (''))) + ({namespace: S.Nothing, name: 'String', version: 0}); - eq(S.type(S.Left(42)), {namespace: S.Just('sanctuary'), name: 'Either', version: 0}); - eq(S.type(S.Right(42)), {namespace: S.Just('sanctuary'), name: 'Either', version: 0}); - eq(S.type(S.Nothing), {namespace: S.Just('sanctuary'), name: 'Maybe', version: 0}); - eq(S.type(S.Just(42)), {namespace: S.Just('sanctuary'), name: 'Maybe', version: 0}); + eq (S.type (S.Left (42))) + ({namespace: S.Just ('sanctuary'), name: 'Either', version: 0}); + eq (S.type (S.Right (42))) + ({namespace: S.Just ('sanctuary'), name: 'Either', version: 0}); + eq (S.type (S.Nothing)) + ({namespace: S.Just ('sanctuary'), name: 'Maybe', version: 0}); + eq (S.type (S.Just (42))) + ({namespace: S.Just ('sanctuary'), name: 'Maybe', version: 0}); function Gizmo() {} Gizmo['@@type'] = 'gadgets/Gizmo@42'; - eq(S.type(new Gizmo()), {namespace: S.Just('gadgets'), name: 'Gizmo', version: 42}); - eq(S.type(Gizmo), {namespace: S.Nothing, name: 'Function', version: 0}); - eq(S.type(Gizmo.prototype), {namespace: S.Nothing, name: 'Object', version: 0}); + eq (S.type (new Gizmo ())) + ({namespace: S.Just ('gadgets'), name: 'Gizmo', version: 42}); + eq (S.type (Gizmo)) + ({namespace: S.Nothing, name: 'Function', version: 0}); + eq (S.type (Gizmo.prototype)) + ({namespace: S.Nothing, name: 'Object', version: 0}); - eq(S.type(vm.runInNewContext('[1, 2, 3]')), {namespace: S.Nothing, name: 'Array', version: 0}); + eq (S.type (vm.runInNewContext ('[1, 2, 3]'))) + ({namespace: S.Nothing, name: 'Array', version: 0}); }); diff --git a/test/unfoldr.js b/test/unfoldr.js index 5858c531..9a605424 100644 --- a/test/unfoldr.js +++ b/test/unfoldr.js @@ -1,21 +1,21 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('unfoldr', function() { +test ('unfoldr', function() { - eq(typeof S.unfoldr, 'function'); - eq(S.unfoldr.length, 2); - eq(S.unfoldr.toString(), 'unfoldr :: (b -> Maybe (Pair a b)) -> b -> Array a'); + eq (typeof S.unfoldr) ('function'); + eq (S.unfoldr.length) (1); + eq (String (S.unfoldr)) ('unfoldr :: (b -> Maybe (Array2 a b)) -> b -> Array a'); function f(n) { - return n >= 5 ? S.Nothing : S.Just([n, n + 1]); + return n >= 5 ? S.Nothing : S.Just ([n, n + 1]); } - eq(S.unfoldr(f, 5), []); - eq(S.unfoldr(f, 4), [4]); - eq(S.unfoldr(f, 1), [1, 2, 3, 4]); + eq (S.unfoldr (f) (5)) ([]); + eq (S.unfoldr (f) (4)) ([4]); + eq (S.unfoldr (f) (1)) ([1, 2, 3, 4]); }); diff --git a/test/unless.js b/test/unless.js index 93f5ba49..a81b23f5 100644 --- a/test/unless.js +++ b/test/unless.js @@ -1,19 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('unless', function() { +test ('unless', function() { - eq(typeof S.unless, 'function'); - eq(S.unless.length, 3); - eq(S.unless.toString(), 'unless :: (a -> Boolean) -> (a -> a) -> a -> a'); + eq (typeof S.unless) ('function'); + eq (S.unless.length) (1); + eq (String (S.unless)) ('unless :: (a -> Boolean) -> (a -> a) -> a -> a'); - function lt0(x) { return x < 0; } - - eq(S.unless(lt0, Math.sqrt, 16), 4); - eq(S.unless(lt0, Math.sqrt, -1), -1); + eq (S.unless (S.lt (0)) (Math.sqrt) (16)) (4); + eq (S.unless (S.lt (0)) (Math.sqrt) (-1)) (-1); }); diff --git a/test/unlines.js b/test/unlines.js index 04c68b75..b62457e0 100644 --- a/test/unlines.js +++ b/test/unlines.js @@ -1,21 +1,21 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('unlines', function() { +test ('unlines', function() { - eq(typeof S.unlines, 'function'); - eq(S.unlines.length, 1); - eq(S.unlines.toString(), 'unlines :: Array String -> String'); + eq (typeof S.unlines) ('function'); + eq (S.unlines.length) (1); + eq (String (S.unlines)) ('unlines :: Array String -> String'); - eq(S.unlines([]), ''); - eq(S.unlines(['']), '\n'); - eq(S.unlines(['', '']), '\n\n'); - eq(S.unlines(['\n']), '\n\n'); - eq(S.unlines(['\n', '\n']), '\n\n\n\n'); - eq(S.unlines(['foo', 'bar', 'baz']), 'foo\nbar\nbaz\n'); + eq (S.unlines ([])) (''); + eq (S.unlines ([''])) ('\n'); + eq (S.unlines (['', ''])) ('\n\n'); + eq (S.unlines (['\n'])) ('\n\n'); + eq (S.unlines (['\n', '\n'])) ('\n\n\n\n'); + eq (S.unlines (['foo', 'bar', 'baz'])) ('foo\nbar\nbaz\n'); }); diff --git a/test/unwords.js b/test/unwords.js index 5b70800b..44583274 100644 --- a/test/unwords.js +++ b/test/unwords.js @@ -1,22 +1,22 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('unwords', function() { +test ('unwords', function() { - eq(typeof S.unwords, 'function'); - eq(S.unwords.length, 1); - eq(S.unwords.toString(), 'unwords :: Array String -> String'); + eq (typeof S.unwords) ('function'); + eq (S.unwords.length) (1); + eq (String (S.unwords)) ('unwords :: Array String -> String'); - eq(S.unwords([]), ''); - eq(S.unwords(['']), ''); - eq(S.unwords(['', '']), ' '); - eq(S.unwords([' ']), ' '); - eq(S.unwords([' ', ' ']), ' '); - eq(S.unwords(['foo', 'bar', 'baz']), 'foo bar baz'); - eq(S.unwords([' foo ', ' bar ', ' baz ']), ' foo bar baz '); + eq (S.unwords ([])) (''); + eq (S.unwords ([''])) (''); + eq (S.unwords (['', ''])) (' '); + eq (S.unwords ([' '])) (' '); + eq (S.unwords ([' ', ' '])) (' '); + eq (S.unwords (['foo', 'bar', 'baz'])) ('foo bar baz'); + eq (S.unwords ([' foo ', ' bar ', ' baz '])) (' foo bar baz '); }); diff --git a/test/values.js b/test/values.js index bcab6414..7f66db92 100644 --- a/test/values.js +++ b/test/values.js @@ -1,24 +1,24 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('values', function() { +test ('values', function() { - eq(typeof S.values, 'function'); - eq(S.values.length, 1); - eq(S.values.toString(), 'values :: StrMap a -> Array a'); + eq (typeof S.values) ('function'); + eq (S.values.length) (1); + eq (String (S.values)) ('values :: StrMap a -> Array a'); - eq(S.sort(S.values({})), []); - eq(S.sort(S.values({a: 1, b: 2, c: 3})), [1, 2, 3]); + eq (S.sort (S.values ({}))) ([]); + eq (S.sort (S.values ({a: 1, b: 2, c: 3}))) ([1, 2, 3]); var proto = {a: 1, b: 2}; - var obj = Object.create(proto); + var obj = Object.create (proto); obj.c = 3; obj.d = 4; - eq(S.sort(S.values(obj)), [3, 4]); + eq (S.sort (S.values (obj))) ([3, 4]); }); diff --git a/test/when.js b/test/when.js index ee594190..95fe48cb 100644 --- a/test/when.js +++ b/test/when.js @@ -1,19 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('when', function() { +test ('when', function() { - eq(typeof S.when, 'function'); - eq(S.when.length, 3); - eq(S.when.toString(), 'when :: (a -> Boolean) -> (a -> a) -> a -> a'); + eq (typeof S.when) ('function'); + eq (S.when.length) (1); + eq (String (S.when)) ('when :: (a -> Boolean) -> (a -> a) -> a -> a'); - function gte0(x) { return x >= 0; } - - eq(S.when(gte0, Math.sqrt, 16), 4); - eq(S.when(gte0, Math.sqrt, -1), -1); + eq (S.when (S.gte (0)) (Math.sqrt) (16)) (4); + eq (S.when (S.gte (0)) (Math.sqrt) (-1)) (-1); }); diff --git a/test/words.js b/test/words.js index 1ff4ef17..b167fd38 100644 --- a/test/words.js +++ b/test/words.js @@ -1,21 +1,21 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('words', function() { +test ('words', function() { - eq(typeof S.words, 'function'); - eq(S.words.length, 1); - eq(S.words.toString(), 'words :: String -> Array String'); + eq (typeof S.words) ('function'); + eq (S.words.length) (1); + eq (String (S.words)) ('words :: String -> Array String'); - eq(S.words(''), []); - eq(S.words(' '), []); - eq(S.words(' \t\r\n'), []); - eq(S.words('foo bar baz'), ['foo', 'bar', 'baz']); - eq(S.words(' foo bar baz '), ['foo', 'bar', 'baz']); - eq(S.words('\tfoo\r\n\tbar\r\n\tbaz\r\n'), ['foo', 'bar', 'baz']); + eq (S.words ('')) ([]); + eq (S.words (' ')) ([]); + eq (S.words (' \t\r\n')) ([]); + eq (S.words ('foo bar baz')) (['foo', 'bar', 'baz']); + eq (S.words (' foo bar baz ')) (['foo', 'bar', 'baz']); + eq (S.words ('\tfoo\r\n\tbar\r\n\tbaz\r\n')) (['foo', 'bar', 'baz']); }); diff --git a/test/zero.js b/test/zero.js index b0407c47..a206448a 100644 --- a/test/zero.js +++ b/test/zero.js @@ -1,18 +1,18 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('zero', function() { +test ('zero', function() { - eq(typeof S.zero, 'function'); - eq(S.zero.length, 1); - eq(S.zero.toString(), 'zero :: Plus f => TypeRep f -> f a'); + eq (typeof S.zero) ('function'); + eq (S.zero.length) (1); + eq (String (S.zero)) ('zero :: Plus f => TypeRep f -> f a'); - eq(S.zero(Array), []); - eq(S.zero(Object), {}); - eq(S.zero(S.Maybe), S.Nothing); + eq (S.zero (Array)) ([]); + eq (S.zero (Object)) ({}); + eq (S.zero (S.Maybe)) (S.Nothing); }); diff --git a/test/zip.js b/test/zip.js index 71af435b..1ba2127b 100644 --- a/test/zip.js +++ b/test/zip.js @@ -1,17 +1,17 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var eq = require('./internal/eq'); +var eq = require ('./internal/eq'); -test('zip', function() { +test ('zip', function() { - eq(typeof S.zip, 'function'); - eq(S.zip.length, 2); - eq(S.zip.toString(), 'zip :: Array a -> Array b -> Array (Pair a b)'); + eq (typeof S.zip) ('function'); + eq (S.zip.length) (1); + eq (String (S.zip)) ('zip :: Array a -> Array b -> Array (Array2 a b)'); - eq(S.zip(['a', 'b'], ['x', 'y', 'z']), [['a', 'x'], ['b', 'y']]); - eq(S.zip([1, 3, 5], [2, 4]), [[1, 2], [3, 4]]); + eq (S.zip (['a', 'b']) (['x', 'y', 'z'])) ([['a', 'x'], ['b', 'y']]); + eq (S.zip ([1, 3, 5]) ([2, 4])) ([[1, 2], [3, 4]]); }); diff --git a/test/zipWith.js b/test/zipWith.js index eb5cd0b4..c6620c1e 100644 --- a/test/zipWith.js +++ b/test/zipWith.js @@ -1,19 +1,19 @@ 'use strict'; -var S = require('..'); +var S = require ('..'); -var concat = require('./internal/concat'); -var eq = require('./internal/eq'); -var pair = require('./internal/pair'); +var concat = require ('./internal/concat'); +var eq = require ('./internal/eq'); +var pair = require ('./internal/pair'); -test('zipWith', function() { +test ('zipWith', function() { - eq(typeof S.zipWith, 'function'); - eq(S.zipWith.length, 3); - eq(S.zipWith.toString(), 'zipWith :: (a -> b -> c) -> Array a -> Array b -> Array c'); + eq (typeof S.zipWith) ('function'); + eq (S.zipWith.length) (1); + eq (String (S.zipWith)) ('zipWith :: (a -> b -> c) -> Array a -> Array b -> Array c'); - eq(S.zipWith(concat, ['a', 'b'], ['x', 'y', 'z']), ['ax', 'by']); - eq(S.zipWith(pair, [1, 3, 5], [2, 4]), [[1, 2], [3, 4]]); + eq (S.zipWith (concat) (['a', 'b']) (['x', 'y', 'z'])) (['ax', 'by']); + eq (S.zipWith (pair) ([1, 3, 5]) ([2, 4])) ([[1, 2], [3, 4]]); });