diff --git a/.gitignore b/.gitignore index df09db7..307f9c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ -bower_components -output -.psci -.psci_modules +/.* +!/.gitignore +!/.travis.yml +/bower_components/ +/node_modules/ +/output/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..791313a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: node_js +sudo: false +node_js: + - 0.10 +env: + - PATH=$HOME/purescript:$PATH +install: + - TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p') + - wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz + - tar -xvf $HOME/purescript.tar.gz -C $HOME/ + - chmod a+x $HOME/purescript + - npm install +script: + - npm run build diff --git a/docs/Data/NonEmpty.md b/docs/Data/NonEmpty.md index e5bc251..a942576 100644 --- a/docs/Data/NonEmpty.md +++ b/docs/Data/NonEmpty.md @@ -29,6 +29,14 @@ instance foldableNonEmpty :: (Foldable f) => Foldable (NonEmpty f) instance traversableNonEmpty :: (Traversable f) => Traversable (NonEmpty f) ``` +#### `singleton` + +``` purescript +singleton :: forall f a. (Plus f) => a -> NonEmpty f a +``` + +Create a non-empty structure with a single value. + #### `(:|)` ``` purescript diff --git a/package.json b/package.json new file mode 100644 index 0000000..165f099 --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "private": true, + "scripts": { + "postinstall": "pulp dep install", + "build": "pulp test && rimraf docs && pulp docs" + }, + "devDependencies": { + "pulp": "^4.0.1", + "rimraf": "^2.4.1" + } +} diff --git a/src/Data/NonEmpty.purs b/src/Data/NonEmpty.purs index 7bdc081..69112d3 100644 --- a/src/Data/NonEmpty.purs +++ b/src/Data/NonEmpty.purs @@ -3,6 +3,7 @@ module Data.NonEmpty ( NonEmpty(..) + , singleton , (:|) , foldl1 , foldMap1 @@ -13,8 +14,9 @@ module Data.NonEmpty import Prelude -import Control.Alternative (Alternative) import Control.Alt ((<|>)) +import Control.Alternative (Alternative) +import Control.Plus (Plus, empty) import Data.Foldable (Foldable, foldl, foldr, foldMap) import Data.Traversable (Traversable, traverse, sequence) @@ -31,6 +33,10 @@ data NonEmpty f a = NonEmpty a (f a) infix 5 :| +-- | Create a non-empty structure with a single value. +singleton :: forall f a. (Plus f) => a -> NonEmpty f a +singleton a = NonEmpty a empty + -- | An infix synonym for `NonEmpty`. (:|) :: forall f a. a -> f a -> NonEmpty f a (:|) = NonEmpty