Skip to content

Commit

Permalink
add constructor to instances to comply (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsoft authored Dec 23, 2017
1 parent a6672b5 commit 7ba53ad
Show file tree
Hide file tree
Showing 54 changed files with 145 additions and 39 deletions.
4 changes: 3 additions & 1 deletion src/All/All.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ test('All', t => {
const m = bindFunc(All)

t.ok(isFunction(All), 'is a function')
t.ok(isObject(All(0)), 'returns an object')
t.ok(isObject(All(false)), 'returns an object')

t.equals(All(true).constructor, All, 'provides TypeRep on constructor')

t.ok(isFunction(All.empty), 'provides an empty function')
t.ok(isFunction(All.type), 'provides a type function')
Expand Down
6 changes: 5 additions & 1 deletion src/All/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ function All(b) {
return All(m.valueOf() && valueOf())
}

return { inspect, valueOf, type, concat, empty }
return {
inspect, valueOf,
type, concat, empty,
constructor: All
}
}

All['@@implements'] = _implements(
Expand Down
4 changes: 3 additions & 1 deletion src/Any/Any.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ test('Any', t => {
const a = bindFunc(Any)

t.ok(isFunction(Any), 'is a function')
t.ok(isObject(Any(0)), 'returns an object')
t.ok(isObject(Any(false)), 'returns an object')

t.equals(Any(true).constructor, Any, 'provides TypeRep on constructor')

t.ok(isFunction(Any.empty), 'provides an empty function')
t.ok(isFunction(Any.type), 'provides a type function')
Expand Down
6 changes: 5 additions & 1 deletion src/Any/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ function Any(b) {
return Any(m.valueOf() || valueOf())
}

return { inspect, valueOf, type, concat, empty }
return {
inspect, valueOf, type,
concat, empty,
constructor: Any
}
}

Any['@@implements'] = _implements(
Expand Down
2 changes: 2 additions & 0 deletions src/Arrow/Arrow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ test('Arrow', t => {

t.ok(isObject(Arrow(unit)), 'returns an object')

t.equals(Arrow(unit).constructor, Arrow, 'provides TypeRep on constructor')

const err = /Arrow: Function required/
t.throws(Arrow, err, 'throws with nothing')
t.throws(a(undefined), err, 'throws with undefined')
Expand Down
3 changes: 2 additions & 1 deletion src/Arrow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ function Arrow(runWith) {
return {
inspect, type, runWith,
id, compose, map, contramap,
promap, first, second, both
promap, first, second, both,
constructor: Arrow
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Assign/Assign.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ test('Assign', t => {
t.ok(isFunction(Assign), 'is a function')
t.ok(isObject(Assign({})), 'returns an object')

t.equals(Assign({}).constructor, Assign, 'provides TypeRep on constructor')

t.ok(isFunction(Assign.empty), 'provides an empty function')
t.ok(isFunction(Assign.type), 'provides a type function')

Expand Down
6 changes: 5 additions & 1 deletion src/Assign/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ function Assign(o) {
return Assign(_object.assign(m.valueOf(), x))
}

return { inspect, valueOf, type, concat, empty }
return {
inspect, valueOf,
type, concat, empty,
constructor: Assign
}
}

Assign['@@implements'] = _implements(
Expand Down
3 changes: 3 additions & 0 deletions src/Async/Async.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ test('Async', t => {
t.ok(isFunction(Async.of), 'provides an of function')
t.ok(isFunction(Async.type), 'provides a type function')

t.equals(Async.Resolved(3).constructor, Async, 'provides TypeRep on constructor on Resolved')
t.equals(Async.Rejected(3).constructor, Async, 'provides TypeRep on constructor on Rejected')

t.ok(isFunction(Async.Resolved), 'provides a Resolved function')
t.ok(isFunction(Async.Rejected), 'provides a Rejected function')

Expand Down
3 changes: 2 additions & 1 deletion src/Async/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ function Async(fn, parentCancel) {
return {
fork, toPromise, inspect, type,
swap, coalesce, map, bimap, alt,
ap, chain, of
ap, chain, of,
constructor: Async
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Const/Const.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ test('Const', t => {

t.ok(isFunction(Const.type), 'provides a type function')

t.equals(Const(true).constructor, Const, 'provides TypeRep on constructor')

t.throws(Const, TypeError, 'throws with no parameters')

t.end()
Expand Down
4 changes: 3 additions & 1 deletion src/Const/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ function Const(x) {

return {
inspect, valueOf, type, equals,
concat, map, ap, chain
concat, map, ap, chain,
constructor: Const
}
}

Const.type =
type

Expand Down
3 changes: 3 additions & 0 deletions src/Either/Either.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ test('Either', t => {
t.ok(isFunction(Either), 'is a function')
t.ok(isObject(m), 'returns an object')

t.equals(Either.Right(0).constructor, Either, 'provides TypeRep on constructor for Right')
t.equals(Either.Left(0).constructor, Either, 'provides TypeRep on constructor for Left')

t.ok(isFunction(Either.of), 'provides an of function')
t.ok(isFunction(Either.type), 'provides a type function')
t.ok(isFunction(Either.Left), 'provides a Left function')
Expand Down
3 changes: 2 additions & 1 deletion src/Either/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ function Either(u) {
return {
inspect, either, type, concat,
swap, coalesce, equals, map, bimap,
alt, ap, of, chain, sequence, traverse
alt, ap, of, chain, sequence, traverse,
constructor: Either
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Endo/Endo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ test('Endo', t => {
t.ok(isFunction(Endo), 'is a function')
t.ok(isObject(Endo(identity)), 'returns an object')

t.equals(Endo(identity).constructor, Endo, 'provides TypeRep on constructor')

t.ok(isFunction(Endo.empty), 'provides an empty function')
t.ok(isFunction(Endo.type), 'provides a type function')

Expand Down
6 changes: 5 additions & 1 deletion src/Endo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ function Endo(runWith) {
return Endo(compose(m.valueOf(), valueOf()))
}

return { inspect, valueOf, type, concat, empty, runWith }
return {
inspect, valueOf, type,
concat, empty, runWith,
constructor: Endo
}
}

Endo['@@implements'] = _implements(
Expand Down
2 changes: 2 additions & 0 deletions src/Equiv/Equiv.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ test('Equiv', t => {

t.ok(isObject(Equiv(isSame)), 'returns an object')

t.equals(Equiv(isSame).constructor, Equiv, 'provides TypeRep on constructor')

const err = /Equiv: Comparison function required/
t.throws(Equiv, err, 'throws with nothing')
t.throws(e(undefined), err, 'throws with undefined')
Expand Down
3 changes: 2 additions & 1 deletion src/Equiv/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ function Equiv(compare) {

return {
inspect, type, compareWith, valueOf,
contramap, concat, empty
contramap, concat, empty,
constructor: Equiv
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/First/First.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ test('First', t => {
t.ok(isFunction(First), 'is a function')
t.ok(isObject(First(0)), 'returns an object')

t.equals(First(0).constructor, First, 'provides TypeRep on constructor')

t.ok(isFunction(First.empty), 'provides an empty function')
t.ok(isFunction(First.type), 'provides a type function')

Expand Down
3 changes: 2 additions & 1 deletion src/First/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function First(x) {

return {
concat, empty, inspect,
option, type, valueOf
option, type, valueOf,
constructor: First
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/IO/IO.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ test('IO', t => {
t.ok(isFunction(IO), 'is a function')
t.ok(isObject(m), 'returns an object')

t.equals(IO(unit).constructor, IO, 'provides TypeRep on constructor')

t.ok(isFunction(IO.of), 'provides an of function')
t.ok(isFunction(IO.type), 'provides a type function')

Expand Down
3 changes: 2 additions & 1 deletion src/IO/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function IO(run) {

return {
inspect, run, type,
map, ap, of, chain
map, ap, of, chain,
constructor: IO
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Identity/Identity.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ test('Identity', t => {
t.ok(isFunction(Identity), 'is a function')
t.ok(isObject(m), 'returns an object')

t.equals(Identity(true).constructor, Identity, 'provides TypeRep on constructor')

t.ok(isFunction(Identity.of), 'provides an of function')
t.ok(isFunction(Identity.type), 'provides a type function')

Expand Down
3 changes: 2 additions & 1 deletion src/Identity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ function Identity(x) {
return {
inspect, valueOf, type, equals,
concat, map, ap, of, chain,
sequence, traverse
sequence, traverse,
constructor: Identity
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Last/Last.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ test('Last', t => {
t.ok(isFunction(Last), 'is a function')
t.ok(isObject(Last(0)), 'returns an object')

t.equals(Last(0).constructor, Last, 'provides TypeRep on constructor')

t.ok(isFunction(Last.empty), 'provides an empty function')
t.ok(isFunction(Last.type), 'provides a type function')

Expand Down
4 changes: 3 additions & 1 deletion src/Last/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ function Last(x) {
}

return {
concat, empty, inspect, option, type, valueOf
concat, empty, inspect,
option, type, valueOf,
constructor: Last
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Max/Max.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ test('Max', t => {
t.ok(isFunction(Max.type), 'provides a type function')
t.ok(isObject(Max(0)), 'returns an object')

t.equals(Max(0).constructor, Max, 'provides TypeRep on constructor')

t.throws(Max, TypeError, 'throws with nothing')
t.throws(m(identity), TypeError, 'throws with a function')
t.throws(m(''), TypeError, 'throws with falsey string')
Expand Down
6 changes: 5 additions & 1 deletion src/Max/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ function Max(n) {
return Max(Math.max(x, m.valueOf()))
}

return { inspect, valueOf, type, concat, empty }
return {
inspect, valueOf, type,
concat, empty,
constructor: Max
}
}

Max['@@implements'] = _implements(
Expand Down
2 changes: 2 additions & 0 deletions src/Min/Min.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ test('Min', t => {
t.ok(isFunction(Min.type), 'provides a type function')
t.ok(isObject(Min(0)), 'returns an object')

t.equals(Min(0).constructor, Min, 'provides TypeRep on constructor')

t.throws(Min, TypeError, 'throws with nothing')
t.throws(m(identity), TypeError, 'throws with a function')
t.throws(m(''), TypeError, 'throws with falsey string')
Expand Down
6 changes: 5 additions & 1 deletion src/Min/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ function Min(n) {
return Min(Math.min(x, m.valueOf()))
}

return { inspect, valueOf, type, concat, empty }
return {
inspect, valueOf, type,
concat, empty,
constructor: Min
}
}

Min['@@implements'] = _implements(
Expand Down
2 changes: 2 additions & 0 deletions src/Pred/Pred.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ test('Pred', t => {

t.ok(isObject(Pred(unit)), 'returns an object')

t.equals(Pred(unit).constructor, Pred, 'provides TypeRep on constructor')

const err = /Pred: Predicate function required/
t.throws(Pred, err, 'throws with nothing')
t.throws(p(undefined), err, 'throws with undefined')
Expand Down
6 changes: 3 additions & 3 deletions src/Pred/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ function Pred(pred) {
}

return {
runWith, inspect, type,
valueOf, empty, concat,
contramap
runWith, inspect, type, valueOf,
empty, concat, contramap,
constructor: Pred
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Prod/Prod.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ test('Prod', t => {
t.ok(isFunction(Prod), 'is a function')
t.ok(isObject(Prod(0)), 'returns an object')

t.equals(Prod(0).constructor, Prod, 'provides TypeRep on constructor')

t.ok(isFunction(Prod.empty), 'provides an empty function')
t.ok(isFunction(Prod.type), 'provides a type function')

Expand Down
6 changes: 5 additions & 1 deletion src/Prod/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ function Prod(n) {
return Prod(x * m.valueOf())
}

return { inspect, valueOf, type, concat, empty }
return {
inspect, valueOf, type,
concat, empty,
constructor: Prod
}
}

Prod['@@implements'] = _implements(
Expand Down
2 changes: 2 additions & 0 deletions src/Reader/Reader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ test('Reader', t => {
t.ok(isFunction(Reader), 'is a function')
t.ok(isObject(m), 'returns an object')

t.equals(Reader(unit).constructor, Reader, 'provides TypeRep on constructor')

t.ok(isFunction(Reader.of), 'provides an of function')
t.ok(isFunction(Reader.type), 'provides a type function')
t.ok(isFunction(Reader.ask), 'provides an ask function')
Expand Down
5 changes: 3 additions & 2 deletions src/Reader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ function Reader(runWith) {
}

return {
inspect, runWith, type,
map, ap, chain, of
inspect, runWith, type, map,
ap, chain, of,
constructor: Reader
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Result/Result.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ test('Result', t => {
t.ok(isFunction(Result), 'is a function')
t.ok(isObject(m), 'returns an object')

t.equals(Result.Ok(true).constructor, Result, 'provides TypeRep on constructor for Ok')
t.equals(Result.Err(true).constructor, Result, 'provides TypeRep on constructor for Err')

t.ok(isFunction(Result.of), 'provides an of function')
t.ok(isFunction(Result.type), 'provides a type function')
t.ok(isFunction(Result.Err), 'provides an Err function')
Expand Down
3 changes: 2 additions & 1 deletion src/Result/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ function Result(u) {
return {
inspect, equals, type, either, concat,
swap, coalesce, map, bimap, alt, ap,
chain, of, sequence, traverse
chain, of, sequence, traverse,
constructor: Result
}
}

Expand Down
Loading

0 comments on commit 7ba53ad

Please sign in to comment.