Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 13816bc

Browse files
committed
Merge pull request #1 from purescript-contrib/topic/implementation
Implementation
2 parents cea533a + 39bb946 commit 13816bc

File tree

7 files changed

+162
-0
lines changed

7 files changed

+162
-0
lines changed

LICENSE

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

MODULE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Module Documentation
2+
3+
## Module Data.Inject
4+
5+
### Type Classes
6+
7+
class Inject f g where
8+
inj :: forall a. f a -> g a
9+
prj :: forall a. g a -> Maybe (f a)
10+
11+
12+
### Type Class Instances
13+
14+
instance injectLeft :: Inject f (Coproduct f g)
15+
16+
instance injectReflexive :: Inject f f
17+
18+
instance injectRight :: (Inject f g) => Inject f (Coproduct h g)
19+
20+
21+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# purescript-inject

bower.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "purescript-inject",
3+
"homepage": "https://github.com/purescript-contrib/purescript-inject",
4+
"description": "Inject typeclass",
5+
"keywords": [
6+
"purescript"
7+
],
8+
"license": "MIT",
9+
"ignore": [
10+
"**/.*",
11+
"node_modules",
12+
"bower_components",
13+
"examples",
14+
"dist"
15+
],
16+
"dependencies": {
17+
"purescript-coproducts": "0.1.0",
18+
"purescript-either": "0.1.4",
19+
"purescript-maybe": "0.2.1"
20+
}
21+
}

gulpfile.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
var gulp = require('gulp')
2+
, gutil = require('gulp-util')
3+
, plumber = require('gulp-plumber')
4+
, purescript = require('gulp-purescript')
5+
, sequence = require('run-sequence')
6+
, del = require('del')
7+
, config = {
8+
del: ['dist'],
9+
purescript: {
10+
src: [
11+
'bower_components/purescript-*/src/**/*.purs*',
12+
'src/**/*.purs'
13+
],
14+
dest: 'dist',
15+
docs: 'MODULE.md'
16+
}
17+
}
18+
;
19+
20+
function error(e) {
21+
gutil.log(gutil.colors.magenta('>>>> Error <<<<') + '\n' + e.toString().trim());
22+
this.emit('end');
23+
}
24+
25+
gulp.task('del', function(cb){
26+
del(config.del, cb);
27+
});
28+
29+
gulp.task('make', function(){
30+
return (
31+
gulp.src(config.purescript.src).
32+
pipe(plumber()).
33+
pipe(purescript.pscMake({output: config.purescript.dest})).
34+
on('error', error)
35+
);
36+
});
37+
38+
gulp.task('psci', function(){
39+
return (
40+
gulp.src(config.purescript.src).
41+
pipe(plumber()).
42+
pipe(purescript.dotPsci()).
43+
on('error', error)
44+
);
45+
});
46+
47+
gulp.task('docs', function(){
48+
return (
49+
gulp.src(config.purescript.src[1]).
50+
pipe(plumber()).
51+
pipe(purescript.pscDocs()).
52+
on('error', error).
53+
pipe(gulp.dest(config.purescript.docs))
54+
);
55+
});
56+
57+
gulp.task('watch', function(cb){
58+
gulp.watch(config.purescript.src, ['make']);
59+
});
60+
61+
gulp.task('default', function(){
62+
sequence('del', 'make', ['psci', 'docs']);
63+
});

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "purescript-inject",
3+
"private": true,
4+
"devDependencies": {
5+
"del": "0.1.3",
6+
"gulp": "3.8.10",
7+
"gulp-plumber": "0.5.6",
8+
"gulp-purescript": "0.1.2",
9+
"gulp-util": "2.2.14",
10+
"run-sequence": "0.3.6"
11+
}
12+
}

src/Data/Inject.purs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Data.Inject
2+
( Inject
3+
, inj, prj
4+
) where
5+
6+
import Data.Either (Either(..))
7+
import Data.Functor.Coproduct (Coproduct(..), coproduct)
8+
import Data.Maybe (Maybe(..))
9+
10+
class Inject f g where
11+
inj :: forall a. f a -> g a
12+
prj :: forall a. g a -> Maybe (f a)
13+
14+
instance injectReflexive :: Inject f f where
15+
inj = id
16+
prj = Just
17+
18+
instance injectLeft :: Inject f (Coproduct f g) where
19+
inj = Coproduct <<< Left
20+
prj = coproduct Just (const Nothing)
21+
22+
instance injectRight :: (Inject f g) => Inject f (Coproduct h g) where
23+
inj = Coproduct <<< Right <<< inj
24+
prj = coproduct (const Nothing) prj

0 commit comments

Comments
 (0)