Skip to content

Commit

Permalink
add fantasy-land api for eveything but ap and traverse
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Hofmann-Hicks committed Feb 7, 2018
1 parent e48badc commit d4ae85a
Show file tree
Hide file tree
Showing 32 changed files with 300 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/All/All.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ test('All', t => {
t.end()
})

test('All fantasy-land api', t => {
const m = All(true)

t.equals(All['fantasy-land/empty'], All.empty, 'is same function as public constructor empty')

t.equals(m['fantasy-land/empty'], m.empty, 'is same function as public instance empty')
t.equals(m['fantasy-land/concat'], m.concat, 'is same function as public instance concat')

t.end()
})

test('All @@implements', t => {
const f = All['@@implements']

Expand Down
4 changes: 4 additions & 0 deletions src/All/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function All(b) {
inspect, toString: inspect,
valueOf, type, concat, empty,
'@@type': _type,
'fantasy-land/concat': concat,
'fantasy-land/empty': empty,
constructor: All
}
}
Expand All @@ -53,6 +55,8 @@ All['@@implements'] = _implements(

All.empty = _empty
All.type = type

All['fantasy-land/empty'] = _empty
All['@@type'] = _type

module.exports = All
11 changes: 11 additions & 0 deletions src/Any/Any.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ test('Any', t => {
t.end()
})

test('Any fantasy-land api', t => {
const m = Any(true)

t.equals(Any['fantasy-land/empty'], Any.empty, 'is same function as public constructor empty')

t.equals(m['fantasy-land/empty'], m.empty, 'is same function as public instance empty')
t.equals(m['fantasy-land/concat'], m.concat, 'is same function as public instance concat')

t.end()
})

test('Any @@implements', t => {
const f = Any['@@implements']

Expand Down
4 changes: 4 additions & 0 deletions src/Any/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function Any(b) {
inspect, toString: inspect,
valueOf, type, concat, empty,
'@@type': _type,
'fantasy-land/concat': concat,
'fantasy-land/empty': empty,
constructor: Any
}
}
Expand All @@ -53,6 +55,8 @@ Any['@@implements'] = _implements(

Any.empty = _empty
Any.type = type

Any['fantasy-land/empty'] = _empty
Any['@@type'] = _type

module.exports = Any
14 changes: 14 additions & 0 deletions src/Arrow/Arrow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ test('Arrow', t => {
t.end()
})

test('Arrow fantasy-land api', t => {
const m = Arrow(identity)

t.equals(Arrow['fantasy-land/id'], Arrow.id, 'is same function as public constructor id')

t.equals(m['fantasy-land/id'], m.id, 'is same function as public instance id')
t.equals(m['fantasy-land/compose'], m.compose, 'is same function as public instance compose')
t.equals(m['fantasy-land/contramap'], m.contramap, 'is same function as public instance contramap')
t.equals(m['fantasy-land/map'], m.map, 'is same function as public instance map')
t.equals(m['fantasy-land/promap'], m.promap, 'is same function as public instance promap')

t.end()
})

test('Arrow @@implements', t => {
const f = Arrow['@@implements']

Expand Down
7 changes: 7 additions & 0 deletions src/Arrow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,20 @@ function Arrow(runWith) {
inspect, toString: inspect, type,
runWith, id, compose, map, contramap,
promap, first, second, both,
'fantasy-land/id': id,
'fantasy-land/compose': compose,
'fantasy-land/contramap': contramap,
'fantasy-land/map': map,
'fantasy-land/promap': promap,
'@@type': _type,
constructor: Arrow
}
}

Arrow.id = _id
Arrow.type = type

Arrow['fantasy-land/id'] = _id
Arrow['@@type'] = _type

Arrow['@@implements'] = _implements(
Expand Down
11 changes: 11 additions & 0 deletions src/Assign/Assign.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ test('Assign', t => {
t.end()
})

test('Assign fantasy-land api', t => {
const m = Assign({})

t.equals(Assign['fantasy-land/empty'], Assign.empty, 'is same function as public constructor empty')

t.equals(m['fantasy-land/empty'], m.empty, 'is same function as public instance empty')
t.equals(m['fantasy-land/concat'], m.concat, 'is same function as public instance concat')

t.end()
})

test('Assign @@implements', t => {
const f = Assign['@@implements']

Expand Down
4 changes: 4 additions & 0 deletions src/Assign/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ function Assign(o) {
return {
inspect, toString: inspect,
valueOf, type, concat, empty,
'fantasy-land/empty': empty,
'fantasy-land/concat': concat,
'@@type': _type,
constructor: Assign
}
Expand All @@ -55,6 +57,8 @@ Assign['@@implements'] = _implements(

Assign.empty = _empty
Assign.type = type

Assign['fantasy-land/empty'] = _empty
Assign['@@type'] = _type

module.exports = Assign
21 changes: 21 additions & 0 deletions src/Async/Async.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ test('Async', t => {
t.end()
})

test('Arrow fantasy-land api', t => {
const rej = Async.Rejected('')
const res = Async.Resolved('')

t.equals(Async['fantasy-land/of'], Async.of, 'is same function as public constructor of')

t.equals(rej['fantasy-land/of'], rej.of, 'is same function as public rejected instance of')
t.equals(rej['fantasy-land/alt'], rej.alt, 'is same function as public rejected instance alt')
t.equals(rej['fantasy-land/bimap'], rej.bimap, 'is same function as public rejected instance bimap')
t.equals(rej['fantasy-land/map'], rej.map, 'is same function as public rejected instance map')
t.equals(rej['fantasy-land/chain'], rej.chain, 'is same function as public rejected instance chain')

t.equals(res['fantasy-land/of'], res.of, 'is same function as public resolved instance of')
t.equals(res['fantasy-land/alt'], res.alt, 'is same function as public resolved instance alt')
t.equals(res['fantasy-land/bimap'], res.bimap, 'is same function as public resolved instance bimap')
t.equals(res['fantasy-land/map'], res.map, 'is same function as public resolved instance map')
t.equals(res['fantasy-land/chain'], res.chain, 'is same function as public resolved instance chain')

t.end()
})

test('Async @@implements', t => {
const f = Async['@@implements']

Expand Down
7 changes: 7 additions & 0 deletions src/Async/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,20 @@ function Async(fn, parentCancel) {
toString: inspect, type,
swap, coalesce, map, bimap,
alt, ap, chain, of,
'fantasy-land/of': of,
'fantasy-land/alt': alt,
'fantasy-land/bimap': bimap,
'fantasy-land/map': map,
'fantasy-land/chain': chain,
'@@type': _type,
constructor: Async
}
}

Async.of = _of
Async.type = type

Async['fantasy-land/of'] = _of
Async['@@type'] = _type

Async.Rejected = Rejected
Expand Down
11 changes: 11 additions & 0 deletions src/Const/Const.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ test('Const', t => {
t.end()
})

test('Const fantasy-land api', t => {
const m = Const('always')

t.equals(m['fantasy-land/equals'], m.equals, 'is same function as public instance equals')
t.equals(m['fantasy-land/concat'], m.concat, 'is same function as public instance concat')
t.equals(m['fantasy-land/map'], m.map, 'is same function as public instance map')
t.equals(m['fantasy-land/chain'], m.chain, 'is same function as public instance chain')

t.end()
})

test('Const @@implements', t => {
const f = Const['@@implements']

Expand Down
4 changes: 4 additions & 0 deletions src/Const/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ function Const(x) {
return {
inspect, toString: inspect, valueOf,
type, equals, concat, map, ap, chain,
'fantasy-land/equals': equals,
'fantasy-land/concat': concat,
'fantasy-land/map': map,
'fantasy-land/chain': chain,
'@@type': _type,
constructor: Const
}
Expand Down
25 changes: 25 additions & 0 deletions src/Either/Either.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,31 @@ test('Either', t => {
t.end()
})

test('Either fantasy-land api', t => {
const l = Either.Left('')
const r = Either.Right('')

t.equals(Either['fantasy-land/of'], Either.of, 'is same function as public constructor of')

t.equals(l['fantasy-land/of'], l.of, 'is same function as public left instance of')
t.equals(l['fantasy-land/equals'], l.equals, 'is same function as public left instance equals')
t.equals(l['fantasy-land/alt'], l.alt, 'is same function as public left instance alt')
t.equals(l['fantasy-land/bimap'], l.bimap, 'is same function as public left instance bimap')
t.equals(l['fantasy-land/concat'], l.concat, 'is same function as public left instance concat')
t.equals(l['fantasy-land/map'], l.map, 'is same function as public left instance map')
t.equals(l['fantasy-land/chain'], l.chain, 'is same function as public left instance chain')

t.equals(r['fantasy-land/of'], r.of, 'is same function as public right instance of')
t.equals(r['fantasy-land/equals'], r.equals, 'is same function as public right instance equals')
t.equals(r['fantasy-land/alt'], r.alt, 'is same function as public right instance alt')
t.equals(r['fantasy-land/bimap'], r.bimap, 'is same function as public right instance bimap')
t.equals(r['fantasy-land/concat'], r.concat, 'is same function as public right instance concat')
t.equals(r['fantasy-land/map'], r.map, 'is same function as public right instance map')
t.equals(r['fantasy-land/chain'], r.chain, 'is same function as public right instance chain')

t.end()
})

test('Either @@implements', t => {
const f = Either['@@implements']

Expand Down
9 changes: 9 additions & 0 deletions src/Either/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,22 @@ function Either(u) {
type, concat, swap, coalesce, equals,
map, bimap, alt, ap, of, chain, sequence,
traverse,
'fantasy-land/of': of,
'fantasy-land/equals': equals,
'fantasy-land/alt': alt,
'fantasy-land/bimap': bimap,
'fantasy-land/concat': concat,
'fantasy-land/map': map,
'fantasy-land/chain': chain,
'@@type': _type,
constructor: Either
}
}

Either.of = _of
Either.type = type

Either['fantasy-land/of'] = _of
Either['@@type'] = _type

Either['@@implements'] = _implements(
Expand Down
11 changes: 11 additions & 0 deletions src/Endo/Endo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ test('Endo', t => {
t.end()
})

test('Endo fantasy-land api', t => {
const m = Endo(identity)

t.equals(Endo['fantasy-land/empty'], Endo.empty, 'is same function as public constructor empty')

t.equals(m['fantasy-land/empty'], m.empty, 'is same function as public instance empty')
t.equals(m['fantasy-land/concat'], m.concat, 'is same function as public instance concat')

t.end()
})

test('Endo @@implements', t => {
const f = Endo['@@implements']

Expand Down
4 changes: 4 additions & 0 deletions src/Endo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ function Endo(runWith) {
inspect, toString: inspect,
valueOf, type, concat, empty,
runWith,
'fantasy-land/empty': empty,
'fantasy-land/concat': concat,
'@@type': _type,
constructor: Endo
}
Expand All @@ -52,6 +54,8 @@ Endo['@@implements'] = _implements(

Endo.empty = _empty
Endo.type = type

Endo['fantasy-land/empty'] = _empty
Endo['@@type'] = _type

module.exports = Endo
Expand Down
12 changes: 12 additions & 0 deletions src/Equiv/Equiv.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ test('Equiv', t => {
t.end()
})

test('Equiv fantasy-land api', t => {
const m = Equiv(identity)

t.equals(Equiv['fantasy-land/empty'], Equiv.empty, 'is same function as public constructor empty')

t.equals(m['fantasy-land/empty'], m.empty, 'is same function as public instance empty')
t.equals(m['fantasy-land/concat'], m.concat, 'is same function as public instance concat')
t.equals(m['fantasy-land/contramap'], m.contramap, 'is same function as public instance contramap')

t.end()
})

test('Equiv @@implements', t => {
const f = Equiv['@@implements']

Expand Down
5 changes: 5 additions & 0 deletions src/Equiv/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,18 @@ function Equiv(compare) {
inspect, toString: inspect, type,
compareWith, valueOf, contramap,
concat, empty,
'fantasy-land/empty': empty,
'fantasy-land/concat': concat,
'fantasy-land/contramap': contramap,
'@@type': _type,
constructor: Equiv
}
}

Equiv.empty = _empty
Equiv.type = type

Equiv['fantasy-land/empty'] = _empty
Equiv['@@type'] = _type

Equiv['@@implements'] = _implements(
Expand Down
11 changes: 11 additions & 0 deletions src/First/First.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ test('First', t => {
t.end()
})

test('First fantasy-land api', t => {
const m = First(10)

t.equals(First['fantasy-land/empty'], First.empty, 'is same function as public constructor empty')

t.equals(m['fantasy-land/empty'], m.empty, 'is same function as public instance empty')
t.equals(m['fantasy-land/concat'], m.concat, 'is same function as public instance concat')

t.end()
})

test('First @@implements', t => {
const f = First['@@implements']

Expand Down
4 changes: 4 additions & 0 deletions src/First/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ function First(x) {
inspect, toString: inspect,
concat, empty, option, type,
valueOf,
'fantasy-land/empty': _empty,
'fantasy-land/concat': concat,
'@@type': _type,
constructor: First
}
Expand All @@ -63,6 +65,8 @@ First['@@implements'] = _implements(

First.empty = _empty
First.type = type

First['fantasy-land/empty'] = _empty
First['@@type'] = _type

module.exports = First

0 comments on commit d4ae85a

Please sign in to comment.