Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.*
!/.gitignore
!/.travis.yml
package-lock.json
/bower_components/
/node_modules/
/output/
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"dependencies": {
"purescript-bifunctors": "^3.0.0",
"purescript-monoid": "^3.0.0"
"purescript-monoid": "^3.0.0",
"purescript-foldable-traversable": "^3.6.1"
}
}
12 changes: 11 additions & 1 deletion src/Data/Validation/Semigroup.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ module Data.Validation.Semigroup
import Prelude

import Control.Apply (lift2)

import Data.Bifunctor (class Bifunctor)
import Data.Foldable (class Foldable)
import Data.Monoid (class Monoid, mempty)
import Data.Traversable (class Traversable)

-- | The `V` functor, used for applicative validation
-- |
Expand Down Expand Up @@ -79,3 +80,12 @@ instance semigroupV :: (Semigroup err, Semigroup a) => Semigroup (V err a) where

instance monoidV :: (Semigroup err, Monoid a) => Monoid (V err a) where
mempty = pure mempty

instance foldableV :: Foldable (V err) where
foldMap = unV (const mempty)
foldr f b = unV (const b) (flip f b)
foldl f b = unV (const b) (f b)

instance traversableV :: Traversable (V err) where
sequence = unV (pure <<< Invalid) (map Valid)
traverse f = unV (pure <<< Invalid) (map Valid <<< f)
14 changes: 12 additions & 2 deletions src/Data/Validation/Semiring.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ module Data.Validation.Semiring
import Prelude

import Control.Alt (class Alt)
import Control.Alternative (class Alternative)
import Control.Apply (lift2)
import Control.Plus (class Plus)
import Control.Alternative (class Alternative)

import Data.Bifunctor (class Bifunctor)
import Data.Foldable (class Foldable)
import Data.Monoid (class Monoid, mempty)
import Data.Traversable (class Traversable)

-- | The `V` functor, used for alternative validation
-- |
Expand Down Expand Up @@ -94,3 +95,12 @@ instance plusV :: (Semiring err) => Plus (V err) where
empty = Invalid zero

instance alernativeV :: (Semiring err) => Alternative (V err)

instance foldableV :: Foldable (V err) where
foldMap = unV (const mempty)
foldr f b = unV (const b) (flip f b)
foldl f b = unV (const b) (f b)

instance traversableV :: Traversable (V err) where
sequence = unV (pure <<< Invalid) (map Valid)
traverse f = unV (pure <<< Invalid) (map Valid <<< f)