Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 8f274da

Browse files
committed
Initial commit.
0 parents  commit 8f274da

18 files changed

+360
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.orig
2+
node_modules
3+
dist
4+
npm-debug.log
5+
docs

.hgignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
syntax: glob
2+
*.orig
3+
node_modules
4+
dist
5+
npm-debug.log
6+
docs

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
build/

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
node_js:
3+
- "0.11"
4+
- "0.10"

LICENCE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2014 Quildreen Motta
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
macros.operators
2+
================
3+
4+
[![Build Status](https://secure.travis-ci.org/folktale/macros.operators.png?branch=master)](https://travis-ci.org/folktale/macros.operators)
5+
[![NPM version](https://badge.fury.io/js/macros.operators.png)](http://badge.fury.io/js/macros.operators)
6+
[![Dependencies Status](https://david-dm.org/folktale/macros.operators.png)](https://david-dm.org/folktale/macros.operators)
7+
[![experimental](http://hughsk.github.io/stability-badges/dist/experimental.svg)](http://github.com/hughsk/stability-badges)
8+
9+
10+
Sweet.js operator macros for common operations
11+
12+
13+
## Example
14+
15+
```js
16+
f >>= g; // chaining
17+
a <*> b <*> c; // ap
18+
a +++ b +++ c; // concat
19+
a |> f; g <| a; // piping
20+
f ->> g; f <<- g; // function composition
21+
```
22+
23+
24+
## Installing
25+
26+
$ npm install macros.operators
27+
28+
29+
## Licence
30+
31+
Copyright (c) 2014 Quildreen Motta.
32+
33+
Released under the [MIT licence](https://github.com/folktale/macros.operators/blob/master/LICENCE).
34+
35+
<!-- links -->
36+
[Fantasy Land]: https://github.com/fantasyland/fantasy-land
37+
[Browserify]: http://browserify.org/
38+
[Git]: http://git-scm.com/
39+
[Make]: http://www.gnu.org/software/make/
40+
[Node.js]: http://nodejs.org/
41+
[es5-shim]: https://github.com/kriskowal/es5-shim
42+
[docs]: http://folktale.github.io/macros.operators
43+
<!-- [release: https://github.com/folktale/macros.operators/releases/download/v$VERSION/macros.operators-$VERSION.tar.gz] -->
44+
[release]: https://github.com/folktale/macros.operators/releases/download/v0.0.0/macros.operators-0.0.0.tar.gz
45+
<!-- [/release] -->

macros/#index.sjs#

Whitespace-only changes.

macros/.#index.sjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queen@Monn.16107:1401189013

macros/alternative.sjs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2014 Quildreen Motta <[email protected]>
2+
//
3+
// Permission is hereby granted, free of charge, to any person
4+
// obtaining a copy of this software and associated documentation files
5+
// (the "Software"), to deal in the Software without restriction,
6+
// including without limitation the rights to use, copy, modify, merge,
7+
// publish, distribute, sublicense, and/or sell copies of the Software,
8+
// and to permit persons to whom the Software is furnished to do so,
9+
// subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be
12+
// included in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
operator (<|>) 10 left { $l, $r } => #{
23+
$l.orElse(function(a){ return $r })
24+
}
25+
26+
export <|>

macros/applicative.sjs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2014 Quildreen Motta <[email protected]>
2+
//
3+
// Permission is hereby granted, free of charge, to any person
4+
// obtaining a copy of this software and associated documentation files
5+
// (the "Software"), to deal in the Software without restriction,
6+
// including without limitation the rights to use, copy, modify, merge,
7+
// publish, distribute, sublicense, and/or sell copies of the Software,
8+
// and to permit persons to whom the Software is furnished to do so,
9+
// subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be
12+
// included in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
operator (<*>) 11 left { $l, $r } => #{
23+
$l.ap($r)
24+
}
25+
26+
operator (<**>) 11 right { $l, $r } => #{
27+
$r.ap($l)
28+
}
29+
30+
export <*>
31+
export <**>

macros/function.sjs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2014 Quildreen Motta <[email protected]>
2+
//
3+
// Permission is hereby granted, free of charge, to any person
4+
// obtaining a copy of this software and associated documentation files
5+
// (the "Software"), to deal in the Software without restriction,
6+
// including without limitation the rights to use, copy, modify, merge,
7+
// publish, distribute, sublicense, and/or sell copies of the Software,
8+
// and to permit persons to whom the Software is furnished to do so,
9+
// subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be
12+
// included in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
operator (|>) 1 left { $l, $r } => #{
23+
$r($l)
24+
}
25+
26+
operator (<|) 1 right { $l, $r } => #{
27+
$l($r)
28+
}
29+
30+
operator (->>) 18 right { $f, $g } => #{
31+
(function(a){ return $g($f(a)) })
32+
}
33+
34+
operator (<<-) 18 left { $f, $g } => #{
35+
(function(a){ return $f($g(a)) })
36+
}
37+
38+
export |>
39+
export <|
40+
export ->>
41+
export <<-

macros/index.sjs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
macro (::) {
2+
rule infix { $obj:expr | $name:ident } => {
3+
$obj.prototype.$name
4+
}
5+
}
6+
7+
8+
teste::beleza;

macros/monad.sjs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2014 Quildreen Motta <[email protected]>
2+
//
3+
// Permission is hereby granted, free of charge, to any person
4+
// obtaining a copy of this software and associated documentation files
5+
// (the "Software"), to deal in the Software without restriction,
6+
// including without limitation the rights to use, copy, modify, merge,
7+
// publish, distribute, sublicense, and/or sell copies of the Software,
8+
// and to permit persons to whom the Software is furnished to do so,
9+
// subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be
12+
// included in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
operator (>>=) 12 left { $l, $r } => #{
23+
$l.chain($r)
24+
}
25+
26+
operator (=<<) 12 right { $l, $r } => #{
27+
$r.chain($l)
28+
}
29+
30+
operator (>=>) 12 right { $f, $g } => #{
31+
(function(a){ return $f(a) >>= $g })
32+
}
33+
34+
operator (<=<) 12 right { $f, $g } => #{
35+
(function(a){ return $g(a) >>= $f })
36+
}
37+
38+
export >>=
39+
export =<<
40+
export >=>
41+
export <=<

macros/monoid.sjs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2014 Quildreen Motta <[email protected]>
2+
//
3+
// Permission is hereby granted, free of charge, to any person
4+
// obtaining a copy of this software and associated documentation files
5+
// (the "Software"), to deal in the Software without restriction,
6+
// including without limitation the rights to use, copy, modify, merge,
7+
// publish, distribute, sublicense, and/or sell copies of the Software,
8+
// and to permit persons to whom the Software is furnished to do so,
9+
// subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be
12+
// included in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
operator (+++) 12 left { $l, $r } => #{
23+
$l.concat($r)
24+
}
25+
26+
export +++

macros/proto.sjs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2014 Quildreen Motta <[email protected]>
2+
//
3+
// Permission is hereby granted, free of charge, to any person
4+
// obtaining a copy of this software and associated documentation files
5+
// (the "Software"), to deal in the Software without restriction,
6+
// including without limitation the rights to use, copy, modify, merge,
7+
// publish, distribute, sublicense, and/or sell copies of the Software,
8+
// and to permit persons to whom the Software is furnished to do so,
9+
// subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be
12+
// included in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
macro (::) {
23+
rule infix { $obj:expr | $name:ident } => {
24+
$obj.prototype.$name
25+
}
26+
}
27+
28+
export ::

package.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "macros.operators",
3+
"version": "0.1.0",
4+
"description": "Sweet.js operator macros for common operations",
5+
"main": "lib/index.js",
6+
"scripts": {
7+
"test": "make test"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/folktale/macros.operators"
12+
},
13+
"keywords": [
14+
"fantasy-land",
15+
"folktale",
16+
"macros"
17+
],
18+
"author": "Quildreen Motta",
19+
"license": "MIT",
20+
"bugs": {
21+
"url": "https://github.com/folktale/macros.operators/issues"
22+
},
23+
"dependencies": {
24+
"sweet.js": "^0.6.0"
25+
},
26+
"devDependencies": {
27+
"hifive-tap": "^0.1.0",
28+
"hifive": "^0.1.0",
29+
"uglify-js": "^2.4.3",
30+
"alright": "^1.0.0",
31+
"sweet.js": "^0.5.0"
32+
}
33+
}

test.sjs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//foo >>= function(a){ return b } >>= bar;
2+
3+
a <*> b <*> c <*> d;
4+
5+
var x = 1

tools/bump-version.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var pkg = require('../package.json')
2+
var fs = require('fs')
3+
4+
function read(n) {
5+
return fs.readFileSync(n, 'utf-8') }
6+
7+
function write(n, s) {
8+
return fs.writeFileSync(n, s, 'utf-8') }
9+
10+
function minor(a) {
11+
return [a[0], a[1], Number(a[2]) + 1] }
12+
13+
function feature(a) {
14+
return [a[0], Number(a[1]) + 1, 0] }
15+
16+
function major(a) {
17+
return [Number(a[0]) + 1, 0, 0] }
18+
19+
function bump(what, version) {
20+
return what === 'MAJOR'? major(version)
21+
: what === 'FEATURE'? feature(version)
22+
: /* otherwise */ minor(version) }
23+
24+
25+
var old_version = pkg.version
26+
27+
pkg.version = bump(process.argv[2], pkg.version.split('.')).join('.')
28+
write('package.json', JSON.stringify(pkg, null, 2))
29+
30+
var readme = read('README.md').replace(/<\!-- \[release:\s*(.+?)\s*\] -->[\s\S]*?<\!-- \[\/release\] -->/, function(_, s) {
31+
return '<!-- [release: ' + s + '] -->\n'
32+
+ '[release]: ' + s.replace(/\$VERSION/g, pkg.version) + '\n'
33+
+ '<!-- [/release] -->'
34+
})
35+
write('README.md', readme)
36+
37+
console.log('Bumped from ' + old_version + ' to ' + pkg.version)

0 commit comments

Comments
 (0)