Skip to content

Commit 45992fa

Browse files
committed
first commit
0 parents  commit 45992fa

File tree

9 files changed

+136
-0
lines changed

9 files changed

+136
-0
lines changed

.bowerrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "bower_components"
3+
}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.*
2+
!/.bowerrc
3+
!/.gitignore
4+
/output/
5+
/node_modules/
6+
/bower_components/
7+
/tmp/

Gruntfile.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = function(grunt) {
2+
3+
"use strict";
4+
5+
grunt.initConfig({
6+
7+
libFiles: [
8+
"src/**/*.purs",
9+
"bower_components/purescript-*/src/**/*.purs"
10+
],
11+
12+
clean: ["output"],
13+
14+
pscMake: {
15+
lib: {
16+
src: ["<%=libFiles%>"]
17+
}
18+
},
19+
20+
dotPsci: ["<%=libFiles%>"]
21+
});
22+
23+
grunt.loadNpmTasks("grunt-contrib-clean");
24+
grunt.loadNpmTasks("grunt-purescript");
25+
26+
grunt.registerTask("make", ["pscMake:lib", "dotPsci"]);
27+
grunt.registerTask("default", ["clean", "make"]);
28+
};

LICENSE-MIT

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

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# purescript-unfoldable
2+
3+
Unfoldable Functors
4+
5+
## Building
6+
7+
```
8+
npm install
9+
bower update
10+
grunt
11+
```

bower.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "purescript-unfoldable",
3+
"description": "Unfoldable Functors",
4+
"keywords": ["purescript"],
5+
"ignore": [
6+
"**/.*",
7+
"bower_components",
8+
"node_modules",
9+
"output",
10+
"tests",
11+
"js",
12+
"tmp",
13+
"bower.json",
14+
"Gruntfile.js",
15+
"package.json"
16+
],
17+
"dependencies": {
18+
"purescript-arrays" : "*",
19+
"purescript-tuples" : "*",
20+
"purescript-maybe" : "*"
21+
},
22+
"devDependencies": {
23+
"purescript-quickcheck" : "*"
24+
}
25+
}

js/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("Main").main();

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "purescript-unfoldable",
3+
"version": "0.1.0",
4+
"description": "Unfoldable Functors",
5+
"main": "",
6+
"private": true,
7+
"author": "Phil Freeman",
8+
"license": "MIT",
9+
"dependencies": {
10+
"grunt": "~0.4.4",
11+
"grunt-contrib-clean": "~0.5.0",
12+
"grunt-purescript": "~0.5.0"
13+
}
14+
}

src/Data/Unfoldable.purs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Data.Unfoldable where
2+
3+
import Data.Maybe
4+
import Data.Tuple
5+
import Data.Function
6+
7+
class Unfoldable t where
8+
unfoldr :: forall a b. (b -> Maybe (Tuple a b)) -> b -> t a
9+
10+
foreign import unfoldrArray
11+
"function unfoldrArray(f, b) {\
12+
\ var result = [];\
13+
\ while (true) {\
14+
\ var maybe = f(b);\
15+
\ if (maybe.ctor === \"Data.Maybe.Nothing\") {\
16+
\ return result;\
17+
\ } else if (maybe.ctor === \"Data.Maybe.Just\") {\
18+
\ result.push(maybe.values[0].values[0]);\
19+
\ b = maybe.values[0].values[1];\
20+
\ }\
21+
\ }\
22+
\}" :: forall a b. Fn2 (b -> Maybe (Tuple a b)) b [a]
23+
24+
instance unfoldableArray :: Unfoldable [] where
25+
unfoldr = runFn2 unfoldrArray

0 commit comments

Comments
 (0)