Skip to content

Commit

Permalink
Merge 517d451 into a006e6e
Browse files Browse the repository at this point in the history
  • Loading branch information
briancavalier committed Oct 31, 2016
2 parents a006e6e + 517d451 commit 789bab0
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@
"rollup": "^0.36.3",
"rollup-plugin-buble": "^0.14.0",
"uglify-js": "^2.7.3"
},
"dependencies": {
"fantasy-land": "^2.0.0"
}
}
29 changes: 28 additions & 1 deletion src/Promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import Race from './Race'
import Merge from './Merge'
import { resolveIterable, resultsArray } from './iterable'

import fl from 'fantasy-land'

const taskQueue = new TaskQueue()
export { taskQueue }

Expand All @@ -25,7 +27,8 @@ const errorHandler = new ErrorHandler(makeEmitError(), e => {
// ## Types
// -------------------------------------------------------------

// Internal base type to hold fantasy-land static constructors
// Internal base type, provides fantasy-land namespace
// and type representative
class Core {
// empty :: Promise e a
static empty () {
Expand All @@ -36,6 +39,30 @@ class Core {
static of (x) {
return fulfill(x)
}

static [fl.empty] () {
return never()
}

static [fl.of] (x) {
return fulfill(x)
}

[fl.map] (f) {
return this.map(f)
}

[fl.ap] (pf) {
return pf.ap(this)
}

[fl.chain] (f) {
return this.chain(f)
}

[fl.concat] (p) {
return this.concat(p)
}
}

// data Promise e a where
Expand Down
65 changes: 65 additions & 0 deletions test/fantasyland-laws-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { describe, it } from 'mocha'
import { fulfill, Promise } from '../src/main'
import { assertSame } from './lib/test-util'
import * as Functor from 'fantasy-land/laws/functor'
import * as Chain from 'fantasy-land/laws/chain'
import * as Apply from 'fantasy-land/laws/apply'
import * as Applicative from 'fantasy-land/laws/applicative'
import * as Semigroup from 'fantasy-land/laws/semigroup'
import * as Monoid from 'fantasy-land/laws/monoid'

describe('fantasyland laws', () => {
describe('functor', () => {
it('should satisfy identity', () => {
return Functor.identity(fulfill, assertSame, {})
})

it('should satisfy composition', () => {
const f = x => x + 'f'
const g = x => x + 'g'
return Functor.composition(fulfill, assertSame, f, g, 'x')
})
})

describe('apply', () => {
it('should satisfy composition', () => {
return Apply.composition(fulfill, assertSame, {})
})
})

describe('applicative', () => {
it('should satisfy identity', () => {
return Applicative.identity(Promise, assertSame, {})
})

it('should satisfy homomorphism', () => {
return Applicative.homomorphism(Promise, assertSame, {})
})

it('should satisfy interchange', () => {
return Applicative.interchange(Promise, assertSame, {})
})
})

describe('chain', () => {
it('should satisfy associativity', () => {
return Chain.associativity(fulfill, assertSame, {})
})
})

describe('semigroup', () => {
it('should satisfy associativity', () => {
return Semigroup.associativity(fulfill, assertSame, {})
})
})

describe('monoid', () => {
it('should satisfy rightIdentity', () => {
return Monoid.rightIdentity(Promise, assertSame, {})
})

it('should satisfy leftIdentity', () => {
return Monoid.leftIdentity(Promise, assertSame, {})
})
})
})

0 comments on commit 789bab0

Please sign in to comment.