Skip to content

Commit

Permalink
add better linting options and cleanup the code a bit (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsoft authored Mar 20, 2017
1 parent 73a0f4f commit 0cd2770
Show file tree
Hide file tree
Showing 41 changed files with 58 additions and 87 deletions.
12 changes: 11 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"asi": true,
"curly": true,
"eqeqeq": true,
"esversion": 6,
"laxbreak": true
"freeze": true,
"funcscope": true,
"globals": {
"require": true,
"module": true
},
"laxbreak": true,
"undef": true,
"unused": true
}
2 changes: 1 addition & 1 deletion combinators/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ const curry = require('../helpers/curry')

// Constant (Kestrel)
// constant :: a -> b -> a
const constant = x => _ => x
const constant = x => () => x

module.exports = curry(constant)
1 change: 0 additions & 1 deletion combinators/substitution.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const test = require('tape')
const sinon = require('sinon')
const helpers = require('../test/helpers')

const bindFunc = helpers.bindFunc
Expand Down
4 changes: 2 additions & 2 deletions crocks/Async.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const _of =
x => Async((_, resolve) => resolve(x))

const Rejected =
x => Async((reject, _) => reject(x))
x => Async((reject) => reject(x))

function all(asyncs) {
if(!(isFoldable(asyncs) && allAsyncs(asyncs))) {
Expand Down Expand Up @@ -163,7 +163,7 @@ function Async(fn) {

return Async((rej, res) => {
fork(
_ => m.fork(rej, res),
() => m.fork(rej, res),
res
)
})
Expand Down
32 changes: 17 additions & 15 deletions crocks/Async.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ test('Async Resolved', t => {
})

test('Async fromPromise', t => {
const resProm = x => new Promise((res, _) => res(x))
const resProm = x => new Promise((res) => res(x))

t.ok(isFunction(Async.fromPromise), 'is a function')
t.ok(isFunction(Async.fromPromise(resProm)), 'returns a function')

const fn = bindFunc(Async.fromPromise)
const fork = bindFunc(x => Async.fromPromise(_ => x)().fork(noop, noop))
const fork = bindFunc(x => Async.fromPromise(() => x)().fork(noop, noop))

t.throws(fn(undefined), TypeError, 'throws with undefined')
t.throws(fn(null), TypeError, 'throws with null')
Expand Down Expand Up @@ -116,7 +116,7 @@ test('Async fromPromise resolution', t => {
const val = 'super fun'

const rejProm = x => new Promise((_, rej) => rej(x))
const resProm = x => new Promise((res, _) => res(x))
const resProm = x => new Promise((res) => res(x))

const rej = y => x => t.equal(x, y, 'rejects a rejected Promise')
const res = y => x => t.equal(x, y, 'resolves a resolved Promise')
Expand Down Expand Up @@ -228,7 +228,7 @@ test('Async type', t => {

test('Async fork', t => {
const resolved = Async((_, res) => res('resolved'))
const rejected = Async((rej, _) => rej('rejected'))
const rejected = Async((rej) => rej('rejected'))

const res = sinon.spy(identity)
const rej = sinon.spy(identity)
Expand Down Expand Up @@ -305,7 +305,7 @@ test('Async swap', t => {
t.throws(fn(noop, {}), TypeError, 'throws with object in right')
t.throws(fn(noop, []), TypeError, 'throws with array in right')

const rejected = Async((rej, _) => rej('silly')).swap(constant('was rejected'), identity)
const rejected = Async((rej) => rej('silly')).swap(constant('was rejected'), identity)
const resolved = Async((_, res) => res('silly')).swap(identity, constant('was resolved'))

const rej = sinon.spy()
Expand Down Expand Up @@ -346,7 +346,7 @@ test('Async coalesce', t => {
t.throws(fn(noop, {}), TypeError, 'throws with object in right')
t.throws(fn(noop, []), TypeError, 'throws with array in right')

const rejected = Async((rej, _) => rej()).coalesce(constant('was rejected'), identity)
const rejected = Async((rej) => rej()).coalesce(constant('was rejected'), identity)
const resolved = Async((_, res) => res()).coalesce(identity, constant('was resolved'))

const rej = sinon.spy()
Expand Down Expand Up @@ -384,8 +384,8 @@ test('Async map errors', t => {
test('Async map functionality', t => {
const mapFn = sinon.spy()

const rejected = Async((rej, _) => rej('rejected')).map(mapFn).fork(noop, noop)
const resolved = Async((_, res) => res('resolved')).map(mapFn).fork(noop, noop)
Async((rej) => rej('rejected')).map(mapFn).fork(noop, noop)
Async((_, res) => res('resolved')).map(mapFn).fork(noop, noop)

t.equal(Async(noop).map(noop).type(), 'Async', 'returns an Async')
t.ok(mapFn.calledWith('resolved'), 'calls map function on resolved')
Expand Down Expand Up @@ -455,7 +455,7 @@ test('Async bimap functionality', t => {
const rej = sinon.spy()
const res = sinon.spy()

Async((rej, _) => rej('rejected')).bimap(left, right).fork(rej, res)
Async((rej) => rej('rejected')).bimap(left, right).fork(rej, res)
Async((_, res) => res('resolved')).bimap(left, right).fork(rej, res)

t.equal(Async(noop).bimap(noop, noop).type(), 'Async', 'returns an Async')
Expand Down Expand Up @@ -714,8 +714,10 @@ test('Async chain properties (Chain)', t => {
const f = x => Async((_, res) => res(x + 2))
const g = x => Async((_, res) => res(x + 10))

const a = x => Async((_, res) => res(x)).chain(f).chain(g).fork(noop, aRes)
const b = x => Async((_, res) => res(x)).chain(y => f(y).chain(g)).fork(noop, bRes)
const x = 12

Async((_, res) => res(x)).chain(f).chain(g).fork(noop, aRes)
Async((_, res) => res(x)).chain(y => f(y).chain(g)).fork(noop, bRes)

t.same(aRes.args[0], bRes.args[0], 'assosiativity')

Expand All @@ -728,16 +730,16 @@ test('Async chain properties (Monad)', t => {

const f = x => Async((_, res) => res(x))

aLeft = sinon.spy()
bLeft = sinon.spy()
const aLeft = sinon.spy()
const bLeft = sinon.spy()

Async.of(3).chain(f).fork(noop, aLeft)
f(3).fork(noop, bLeft)

t.same(aLeft.args[0], bLeft.args[0], 'left identity')

aRight = sinon.spy()
bRight = sinon.spy()
const aRight = sinon.spy()
const bRight = sinon.spy()

f(3).chain(Async.of).fork(noop, aRight)
f(3).fork(noop, bRight)
Expand Down
1 change: 0 additions & 1 deletion crocks/Either.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ test('Either concat errors', t => {
const m = { type: () => 'Either...Not' }

const good = Either.Right([])
const bad = Either.Left([])

const f = bindFunc(Either.Right([]).concat)
const nonEitherErr = /Either.concat: Either of Semigroup required/
Expand Down
4 changes: 2 additions & 2 deletions crocks/IO.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ test('IO chain properties (Chain)', t => {
t.ok(isFunction(IO(noop).chain), 'provides a chain function')
t.ok(isFunction(IO(noop).ap), 'implements the Apply spec')

const f = x => IO(_ => x + 2)
const g = x => IO(_ => x + 10)
const f = x => IO(() => x + 2)
const g = x => IO(() => x + 10)

const a = x => IO(constant(x)).chain(f).chain(g)
const b = x => IO(constant(x)).chain(y => f(y).chain(g))
Expand Down
2 changes: 0 additions & 2 deletions crocks/Identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ const isSameType = require('../predicates/isSameType')
const _inspect = require('../internal/inspect')
const innerConcat = require('../internal/innerConcat')

const composeB = require('../combinators/composeB')
const constant = require('../combinators/constant')
const identity = require('../combinators/identity')

const _type =
constant('Identity')
Expand Down
3 changes: 0 additions & 3 deletions crocks/List.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const Pred = require('./Pred')
const List = require('./List')

test('List', t => {
const m = bindFunc(List)
const f = x => List(x).toArray()

t.ok(isFunction(List), 'is a function')
Expand Down Expand Up @@ -505,8 +504,6 @@ test('List chain errors', t => {
const chain = bindFunc(List([ 0 ]).chain)
const bad = bindFunc(x => List.of(x).chain(identity))

const f = x => List.of(x)

const noFunc = /List.chain: Function required/
t.throws(chain(undefined), noFunc, 'throws with undefined')
t.throws(chain(null), noFunc, 'throws with null')
Expand Down
3 changes: 0 additions & 3 deletions crocks/Maybe.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,7 @@ test('Maybe of', t => {

test('Maybe of properties (Applicative)', t => {
const m = Maybe.Just(identity)

const j = Maybe.Just(3)
const n = Maybe.Nothing()

t.ok(isFunction(j.of), 'Just provides an of function')
t.ok(isFunction(j.ap), 'Just implements the Apply spec')
Expand All @@ -487,7 +485,6 @@ test('Maybe of properties (Applicative)', t => {

test('Maybe chain errors', t => {
const chain = bindFunc(Maybe(0).chain)
const nChain = bindFunc(Maybe(undefined).chain)

t.throws(chain(undefined), TypeError, 'throws with undefined')
t.throws(chain(null), TypeError, 'throws with null')
Expand Down
4 changes: 2 additions & 2 deletions crocks/Pair.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ test('Pair chain errors', t => {
const badChain = bindFunc(Pair(0, 0).chain)
const chain = bindFunc(Pair([], 0).chain)

const badFn = x => Pair(0, 0)
const fn = x => Pair([], 0)
const badFn = () => Pair(0, 0)
const fn = () => Pair([], 0)

t.throws(badChain(noop), TypeError, 'throws if wrapped first value is not a Semigroup')
t.throws(chain(badFn), TypeError, 'throws if monadic function returns a Pair with a non-Semigroup as first value')
Expand Down
4 changes: 2 additions & 2 deletions crocks/Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const _type =
const concatErr =
m => x => m.either(
y => and(isSemigroup, isSameType(y), x) ? x.concat(y) : x,
_ => x
() => x
)

function runSequence(x) {
Expand Down Expand Up @@ -158,7 +158,7 @@ function Result(u) {
throw new TypeError('Result.ap: Wrapped value must be a function')
}

return m.either(Result.Err, _ => m.map(fn))
return m.either(Result.Err, () => m.map(fn))
}
)
}
Expand Down
3 changes: 1 addition & 2 deletions crocks/Result.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ test('Result concat errors', t => {
const m = { type: () => 'Result...Not' }

const good = Result.Ok([])
const bad = Result.Err([])

const f = bindFunc(Result.Ok([]).concat)

Expand Down Expand Up @@ -575,7 +574,7 @@ test('Result ap errors', t => {

test('Result Err ap functionality', t => {
const Err = Result.Err
const m = Result.Ok(x => y => z => x)
const m = Result.Ok(x => () => () => x)

const extract = either(identity, constant('Ok'))

Expand Down
1 change: 0 additions & 1 deletion crocks/Star.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const _inspect = require('../internal/inspect')

const compose = require('../helpers/compose')
const constant = require('../combinators/constant')
const identity = require('../combinators/identity')

const merge = require('../pointfree/merge')
const sequence = require('../pointfree/sequence')
Expand Down
10 changes: 5 additions & 5 deletions crocks/Star.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ test('Star contramap functionality', t => {
t.equal(m.type(), 'Star', 'returns a Star')
t.notOk(spy.called, 'does not call mapping function initially')

const result = m.runWith(x)
m.runWith(x)

t.ok(spy.called, 'calls mapping function when ran')
t.equal(m.runWith(x).value(), x, 'returns the result of the resulting composition')
Expand Down Expand Up @@ -320,7 +320,7 @@ test('Star promap functionality', t => {
t.notOk(spyLeft.called, 'does not call left mapping function initially')
t.notOk(spyRight.called, 'does not call right mapping function initially')

const result = m.runWith(x)
m.runWith(x)

t.ok(spyLeft.called, 'calls left mapping function when ran')
t.ok(spyRight.called, 'calls right mapping function when ran')
Expand Down Expand Up @@ -375,7 +375,7 @@ test('Star first', t => {

t.doesNotThrow(runWith(Pair(1, 2)), 'does not throw when inner value is a Pair')

const notValid = bindFunc(x => Star(_ => x).first().runWith(Pair(2, 3)))
const notValid = bindFunc(x => Star(() => x).first().runWith(Pair(2, 3)))

t.throws(notValid(undefined), TypeError, 'throws with undefined input')
t.throws(notValid(null), TypeError, 'throws with null as input')
Expand Down Expand Up @@ -416,7 +416,7 @@ test('Star second', t => {

t.doesNotThrow(runWith(Pair(1, 2)), 'does not throw when inner value is a Pair')

const notValid = bindFunc(x => Star(_ => x).second().runWith(Pair(2, 3)))
const notValid = bindFunc(x => Star(() => x).second().runWith(Pair(2, 3)))

t.throws(notValid(undefined), TypeError, 'throws when computation returns undefined')
t.throws(notValid(null), TypeError, 'throws when computation returns null')
Expand Down Expand Up @@ -459,7 +459,7 @@ test('Star both', t => {

t.doesNotThrow(runWith(Pair(1, 2)), 'does not throw when inner value is a Pair')

const notValid = bindFunc(x => Star(_ => x).both().runWith(Pair(2, 3)))
const notValid = bindFunc(x => Star(() => x).both().runWith(Pair(2, 3)))

t.throws(notValid(undefined), TypeError, 'throws when computation returns undefined')
t.throws(notValid(null), TypeError, 'throws when computation returns null')
Expand Down
2 changes: 1 addition & 1 deletion crocks/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ State.type =
_type

State.get =
_ => State(s => Pair(s, s))
() => State(s => Pair(s, s))

State.gets =
gets
Expand Down
3 changes: 1 addition & 2 deletions crocks/State.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const isObject = require('../predicates/isObject')
const isFunction = require('../predicates/isFunction')

const composeB = require('../combinators/composeB')
const constant = require('../combinators/constant')
const identity = require('../combinators/identity')

const Pair = require('./Pair')
Expand Down Expand Up @@ -400,7 +399,7 @@ test('State chain errors', t => {
t.throws(noPair({}), TypeError, 'throws when inner function returns an object')
t.throws(noPair(noop), TypeError, 'throws when inner function returns a function')

const noState = bindFunc(State(x => Pair(0, 0)).chain(identity).runWith)
const noState = bindFunc(State(() => Pair(0, 0)).chain(identity).runWith)

t.throws(noState(undefined), TypeError, 'throws when chain function returns undefined')
t.throws(noState(null), TypeError, 'throws when chain function returns null')
Expand Down
5 changes: 1 addition & 4 deletions crocks/Unit.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/** @license ISC License (c) copyright 2016 original and current authors */
/** @author Ian Hofmann-Hicks (evil) */

const constant = require('../combinators/constant')
const isFunction = require('../predicates/isFunction')

const _inspect = require('../internal/inspect')
const isSameType = require('../predicates/isSameType')

const constant = require('../combinators/constant')

const _type =
constant('Unit')

Expand Down
2 changes: 1 addition & 1 deletion helpers/composeP.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const isPromise = require('../predicates/isPromise')

function applyCompose(f, g) {
return function() {
p = f.apply(null, arguments)
const p = f.apply(null, arguments)

if(!isPromise(p)) {
throw new TypeError('composeP: Only accepts Promise returning functions')
Expand Down
5 changes: 1 addition & 4 deletions helpers/composeP.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
const test = require('tape')
const sinon = require('sinon')
const helpers = require('../test/helpers')

const bindFunc = helpers.bindFunc
const noop = helpers.noop

const isFunction = require('../predicates/isFunction')

const compose = require('./compose')
const identity = require('../combinators/identity')
const isFunction = require('../predicates/isFunction')

const composeP = require('./composeP')

Expand Down
2 changes: 1 addition & 1 deletion helpers/pipeP.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const isPromise = require('../predicates/isPromise')

function applyPipe(f, g) {
return function() {
p = f.apply(null, arguments)
const p = f.apply(null, arguments)

if(!isPromise(p)) {
throw new TypeError('pipeP: Only accepts Promise returning functions')
Expand Down
Loading

0 comments on commit 0cd2770

Please sign in to comment.