Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial version #1

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a67bdb9
feat(init): initial version
safareli Oct 7, 2016
36d5ce4
refactor(equals): move equals function into seperate file and resuse …
safareli Oct 8, 2016
578ede0
refactor(test): add custom assertion method for fantasy-land/equals
safareli Oct 8, 2016
8c150c9
refactor(fl): make of a prototype based constructor and use nonnamesp…
safareli Oct 8, 2016
7c831e1
docs(anotation): add type anotations to common structures
safareli Oct 9, 2016
d089c8e
refactor(order): reorder method definitions in common structures
safareli Oct 9, 2016
de2f412
refactor(empty): make definition of `empty` compact
safareli Oct 9, 2016
e3eacd3
refactor(fl-patch): make fl-patch take array of objects and update usage
safareli Oct 9, 2016
3e427c1
refactor(chainStep): move chainRec step functions and equals into sha…
safareli Oct 9, 2016
27909fe
refactor(order): reorder method definitions
safareli Oct 9, 2016
747e507
test(Of.of): test of(a).constructor.of
safareli Oct 9, 2016
11ba91d
feat(Foldable): make Of a Foldable
safareli Oct 9, 2016
576093e
feat(Traversable): make Of a Traversable
safareli Oct 9, 2016
0f4595f
feat(Extend): make Of an Extend
safareli Oct 9, 2016
353eca9
fix(traversable): fix traverse error message on Of.empty
safareli Oct 9, 2016
aec5e2b
feat(Comonad): make Of a Comonad
safareli Oct 9, 2016
66f3b06
feat(Of): do not export constructor
safareli Oct 9, 2016
6745eec
docs(Of): update comments
safareli Oct 9, 2016
c97eeec
fix(linter): fix some linter issues
safareli Oct 9, 2016
a5a50bb
docs(quasi): add some commets and type signatures
safareli Oct 10, 2016
f1eb329
test(examples): move `common` files to `examples`; add tests for Iden…
safareli Oct 11, 2016
a451348
test(Func): add tests for Func
safareli Oct 11, 2016
c776ace
test(Pair): add tests for Pair
safareli Oct 11, 2016
71b3630
test(Future): rename Task to Future; add tests for it
safareli Oct 11, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable no-unused-vars */
const OFF = 0
const WARNING = 1
const ERROR = 2
/* eslint-enable no-unused-vars */

module.exports = {
parser: 'babel-eslint',

extends: 'standard',

rules: {
'comma-dangle': [ERROR, 'always-multiline'],
'space-before-function-paren': [
ERROR,
{anonymous: 'never', named: 'never'},
],
},
}
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
dist

# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
sudo: false
language: node_js
cache:
directories:
- node_modules
notifications:
email: false
node_js:
- '6'
before_install:
- npm i -g npm@^3.0.0
before_script:
- npm prune
script:
- npm run check
- npm run coverage
- npm run build
after_success:
- npm run semantic-release
branches:
except:
- /^v\d+\.\d+\.\d+$/
51 changes: 51 additions & 0 deletions examples/Func.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const daggy = require('daggy')

const Q = require('../src/quasi.js')
const fl = require('../src/fl.js')
const flPatch = require('../src/fl-patch.js')

// type Func a b = Func (a -> b)
const Func = daggy.tagged('run')

// instance Semigroup b => Semigroup (Func a b) where
// concat :: Func a b ~> Func a b -> Func a b
Func.prototype.concat = function(g) {
if (Q.isEmpty(g)) {
return this
}
return Func((x) => {
const a = this.run(x)
const b = Q.foldIfIsOf(Func[fl.of], g).run(x)
if (Q.isEmpty(a)) {
return b
} else if (Q.isEmpty(b)) {
return a
} else {
return a[fl.concat](b)
}
})
}

// instance Monoid b => Monoid (Func a b) where
// empty :: Func a b
Func.empty = Func((_) => Q.empty)

// instance Functor (Func a) where
// map :: Func a b ~> (b -> c) -> Func a c
Func.prototype.map = function(f) {
return Func((x) => f(this.run(x)))
}

// instance Apply (Func a) where
// ap :: Func a b ~> Func a (b -> c) -> Func a c
Func.prototype.ap = function(g) {
return this.map(x => Q.foldIfIsOf(Func[fl.of], g).run(x)(x))
}

// instance Applicative (Func a) where
// of :: b -> Func a b
Func.of = (a) => Func((_) => a)

flPatch([Func, Func.prototype])

module.exports = Func
73 changes: 73 additions & 0 deletions examples/Future.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const daggy = require('daggy')

const Q = require('../src/quasi.js')
const fl = require('../src/fl.js')
const flPatch = require('../src/fl-patch.js')

// type Future a = Future (a -> ()) -> ())
const Future = daggy.tagged('fork')

// instance Semigroup a => Semigroup (Future a) where
// concat :: Future a ~> Future a -> Future a
Future.prototype.concat = function(g) {
if (Q.isEmpty(g)) {
return this
}
return Future.parallel(this, Q.foldIfIsOf(Future[fl.of], g)).map(([a, b]) => {
if (Q.isEmpty(a)) {
return b
} else if (Q.isEmpty(b)) {
return a
} else {
return a[fl.concat](b)
}
})
}

// instance Monoid a => Monoid (Future a) where
// empty :: Future a
Future.empty = Future((done) => done(Q.empty))

// instance Functor Future where
// map :: Future a ~> (a -> b) -> Future b
Future.prototype.map = function(f) {
return Future((done) => this.fork((v) => done(f(v))))
}

// instance Apply Future where
// ap :: Future a -> Future (a -> b) -> Future b
Future.prototype.ap = function(g) {
return Future.parallel(this, Q.foldIfIsOf(Future[fl.of], g)).map(([v, f]) => f(v))
}

// instance Applicative Future where
// of :: a -> Future a
Future.of = (a) => Future((done) => done(a))

Future.parallel = function(a, b) {
return Future((done) => {
let aDone = false
let bDone = false
let aRes = null
let bRes = null
const check = () => {
if (aDone && bDone) {
done([aRes, bRes])
}
}
a.fork((a) => {
aDone = true
aRes = a
check()
})
b.fork((b) => {
bDone = true
bRes = b
check()
})
})
}

flPatch([Future, Future.prototype])

module.exports = Future
72 changes: 72 additions & 0 deletions examples/Identity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const daggy = require('daggy')

const Q = require('../src/quasi.js')
const { equals, chainRecNext, chainRecDone } = require('../src/shared.js')
const fl = require('../src/fl.js')
const flPatch = require('../src/fl-patch.js')

// type Identity a = Identity a
const Identity = daggy.tagged('value')

// instance Setoid a => Setoid (Identity a) where
// equals :: Identity a ~> Identity a -> Boolean
Identity.prototype.equals = function(b) {
return equals(this.value, b.value)
}

// instance Semigroup a => Semigroup (Identity a) where
// concat :: Identity a ~> Identity a -> Identity a
Identity.prototype.concat = function(b) {
b = Q.foldIfIsOf(Identity[fl.of], b)
if (Q.isEmpty(this.value)) {
return b
} else if (Q.isEmpty(b) || Q.isEmpty(b.value)) {
return this
} else {
return Identity(this.value[fl.concat](b.value))
}
}

// instance Monoid a => Monoid (Identity a) where
// empty :: Identity a
Identity.empty = Identity(Q.empty)

// instance Functor Identity where
// map :: Identity a ~> (a -> b) -> Identity b
Identity.prototype.map = function(f) {
return Identity(f(this.value))
}

// instance Apply Identity where
// ap :: Identity a ~> Identity (a -> b) -> Identity b
Identity.prototype.ap = function(f) {
if (Q.isOf(f)) {
return this.map(f.value)
} else {
return Identity(f.value(this.value))
}
}

// instance Applicative Identity where
// of :: a -> Identity a
Identity.of = (a) => Identity(a)

// instance Chain Identity where
// chain :: Identity a ~> (a -> Identity b) -> Identity b
Identity.prototype.chain = function(f) {
return f(this.value)
}

// instance ChainRec Identity where
// chainRec :: ((a -> c, b -> c, a) -> Identity c, a) -> Identity b
Identity.chainRec = function(f, i) {
var state = chainRecNext(i)
while (state.isNext) {
state = f(chainRecNext, chainRecDone, state.value).value
}
return Identity(state.value)
}

flPatch([Identity, Identity.prototype])

module.exports = Identity
56 changes: 56 additions & 0 deletions examples/List.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const daggy = require('daggy')

const Q = require('../src/quasi.js')
const { equals } = require('../src/shared.js')
const fl = require('../src/fl.js')
const flPatch = require('../src/fl-patch.js')

// type List a = Nil | Cons a (List a)
const List = daggy.taggedSum({
Cons: ['x', 'xs'],
Nil: [],
})

// instance Setoid a => Setoid (List a) where
// equals :: List a ~> List a -> Boolean
List.prototype.equals = function(b) {
return this.cata({
Nil: () => b.cata({
Nil: () => true,
Cons: (x, xs) => false,
}),
Cons: (x, xs) => b.cata({
Nil: () => false,
Cons: (y, ys) => equals(x, y) && xs[fl.equals](ys),
}),
})
}

// instance Semigroup List where
// concat :: List a ~> List a -> List a
List.prototype.concat = function(ys) {
if (Q.isEmpty(ys)) {
return this
}
return this.cata({
Nil: () => ys,
Cons: (x, xs) => List.Cons(x, xs[fl.concat](ys)),
})
}

// instance Monoid List where
// empty :: List a
List.empty = List.Nil

List.prototype.toString = function() {
return this.cata({
Nil: () => 'Nil',
Cons: (x, xs) => 'Cons(' + x + ',' + xs + ')',
})
}

List.fromArray = (arr) => arr.reduceRight((acc, a) => List.Cons(a, acc), List.Nil)

flPatch([List, List.prototype])

module.exports = List
Loading