Data.Unique

This commit is contained in:
mechairoi 2015-08-09 18:56:26 +09:00
parent 8f3474b712
commit c738def21c
6 changed files with 191 additions and 0 deletions

48
MODULE.md Normal file
View File

@ -0,0 +1,48 @@
# Module Documentation
## Module Data.Unique
#### `Uniq`
``` purescript
data Uniq :: !
```
#### `Unique`
``` purescript
newtype Unique
```
#### `newUnique`
``` purescript
newUnique :: forall e. Eff (uniq :: Uniq | e) Unique
```
#### `showUnique`
``` purescript
instance showUnique :: Show Unique
```
#### `eqUnique`
``` purescript
instance eqUnique :: Eq Unique
```
#### `ordUnique`
``` purescript
instance ordUnique :: Ord Unique
```

6
README.md Normal file
View File

@ -0,0 +1,6 @@
purescript-unique [![Build Status](https://travis-ci.org/mechairoi/purescript-unique.svg?branch=master)](https://travis-ci.org/mechairoi/purescript-unique)
===
Data.Unique for PureScript.
## Documentations
- [Module documentation](MODULE.md)

23
bower.json Normal file
View File

@ -0,0 +1,23 @@
{
"name": "purescript-unique",
"version": "0.0.1",
"homepage": "https://github.com/mechairoi/purescript-unique",
"authors": [
"mechairoi <ttsujikawa@gmail.com>"
],
"keywords": [
"purescript"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
},
"devDependencies": {
}
}

52
gulpfile.js Normal file
View File

@ -0,0 +1,52 @@
'use strict';
var gulp = require('gulp')
, run = require('gulp-run')
, purescript = require('gulp-purescript')
;
var paths = {
src: 'src/**/*.purs',
doc: 'MODULE.md',
docSrc: ['src/**/*.purs', '!src/**/Internal/**/*.purs' ],
bowerSrc: 'bower_components/purescript-*/src/**/*.purs',
dest: 'output',
example: 'examples/*.purs',
test: 'test/**/*.purs'
};
gulp.task('make', function() {
return gulp.src([paths.src].concat(paths.bowerSrc))
.pipe(purescript.pscMake({}))
.pipe(gulp.dest(paths.dest));
});
gulp.task('test-make', function() {
return gulp.src([paths.src, paths.test].concat(paths.bowerSrc))
.pipe(purescript.pscMake({}))
.pipe(gulp.dest(paths.dest));
});
gulp.task('test', ['test-make'], function() {
var env = {};
for (var e in process.env) env[e] = process.env[e];
env.NODE_PATH = 'output';
run('node -e "require(\'Test.Main\').main();"', { 'env': env }).exec();
});
gulp.task('docs', function() {
return gulp.src(paths.docSrc)
.pipe(purescript.pscDocs())
.pipe(gulp.dest(paths.doc));
});
gulp.task('psci', function() {
return gulp.src([paths.src, paths.test, paths.example].concat(paths.bowerSrc))
.pipe(purescript.dotPsci());
});
gulp.task('watch', function() {
gulp.watch(paths.src, ['make', 'docs']);
});
gulp.task('default', ['make', 'docs']);

18
package.json Normal file
View File

@ -0,0 +1,18 @@
{
"name": "purescript-unique",
"version": "0.0.1",
"description": "Data.Unique for PureScript",
"dependencies": {
"gulp-run": "^1.6.7"
},
"devDependencies": {
"gulp": "^3.8.10",
"gulp-purescript": "^0.3.1",
"vinyl-source-stream": "^1.0.0"
},
"scripts": {
"test": "gulp test",
"make": "gulp make",
"watch": "gulp watch"
}
}

44
src/Data/Unique.purs Normal file
View File

@ -0,0 +1,44 @@
module Data.Unique
( newUnique
, Unique()
, Uniq()
) where
import Control.Monad.Eff
foreign import data Uniq :: !
newtype Unique = Unique String
foreign import newUnique """
var newUnique = (function() {
var MAX_SAFE_INTEGER = 9007199254740991;
var uniqueSource = [];
function iter(i) {
if(uniqueSource.length === i) {
for(var j = 0; j < i; ++j) uniqueSource[j] = 0;
uniqueSource[i] = 1;
} else {
if(uniqueSource[i] === MAX_SAFE_INTEGER) {
uniqueSource[i] = 0;
iter(i + 1);
} else {
uniqueSource[i]++;
}
}
};
return function() {
iter(0);
return uniqueSource.length === 1 ? (uniqueSource[0] + "") : uniqueSource.join(',');
};
})();""" :: forall e. Eff (uniq :: Uniq | e) Unique
instance showUnique :: Show Unique where
show (Unique a) = a
instance eqUnique :: Eq Unique where
(==) (Unique a) (Unique b) = a == b
(/=) (Unique a) (Unique b) = a /= b
instance ordUnique :: Ord Unique where
compare (Unique a) (Unique b) = compare a b