Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2014 PureScript

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), in the Software without restriction, including without
limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to
whom the Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 changes: 21 additions & 0 deletions MODULE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Module Documentation

## Module Data.Inject

### Type Classes

class Inject f g where
inj :: forall a. f a -> g a
prj :: forall a. g a -> Maybe (f a)


### Type Class Instances

instance injectLeft :: Inject f (Coproduct f g)

instance injectReflexive :: Inject f f

instance injectRight :: (Inject f g) => Inject f (Coproduct h g)



1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# purescript-inject
21 changes: 21 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "purescript-inject",
"homepage": "https://github.com/purescript-contrib/purescript-inject",
"description": "Inject typeclass",
"keywords": [
"purescript"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"examples",
"dist"
],
"dependencies": {
"purescript-coproducts": "0.1.0",
"purescript-either": "0.1.4",
"purescript-maybe": "0.2.1"
}
}
63 changes: 63 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
var gulp = require('gulp')
, gutil = require('gulp-util')
, plumber = require('gulp-plumber')
, purescript = require('gulp-purescript')
, sequence = require('run-sequence')
, del = require('del')
, config = {
del: ['dist'],
purescript: {
src: [
'bower_components/purescript-*/src/**/*.purs*',
'src/**/*.purs'
],
dest: 'dist',
docs: 'MODULE.md'
}
}
;

function error(e) {
gutil.log(gutil.colors.magenta('>>>> Error <<<<') + '\n' + e.toString().trim());
this.emit('end');
}

gulp.task('del', function(cb){
del(config.del, cb);
});

gulp.task('make', function(){
return (
gulp.src(config.purescript.src).
pipe(plumber()).
pipe(purescript.pscMake({output: config.purescript.dest})).
on('error', error)
);
});

gulp.task('psci', function(){
return (
gulp.src(config.purescript.src).
pipe(plumber()).
pipe(purescript.dotPsci()).
on('error', error)
);
});

gulp.task('docs', function(){
return (
gulp.src(config.purescript.src[1]).
pipe(plumber()).
pipe(purescript.pscDocs()).
on('error', error).
pipe(gulp.dest(config.purescript.docs))
);
});

gulp.task('watch', function(cb){
gulp.watch(config.purescript.src, ['make']);
});

gulp.task('default', function(){
sequence('del', 'make', ['psci', 'docs']);
});
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "purescript-inject",
"private": true,
"devDependencies": {
"del": "0.1.3",
"gulp": "3.8.10",
"gulp-plumber": "0.5.6",
"gulp-purescript": "0.1.2",
"gulp-util": "2.2.14",
"run-sequence": "0.3.6"
}
}
24 changes: 24 additions & 0 deletions src/Data/Inject.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Data.Inject
( Inject
, inj, prj
) where

import Data.Either (Either(..))
import Data.Functor.Coproduct (Coproduct(..), coproduct)
import Data.Maybe (Maybe(..))

class Inject f g where
inj :: forall a. f a -> g a
prj :: forall a. g a -> Maybe (f a)

instance injectReflexive :: Inject f f where
inj = id
prj = Just

instance injectLeft :: Inject f (Coproduct f g) where
inj = Coproduct <<< Left
prj = coproduct Just (const Nothing)

instance injectRight :: (Inject f g) => Inject f (Coproduct h g) where
inj = Coproduct <<< Right <<< inj
prj = coproduct (const Nothing) prj