File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 1717 " package.json"
1818 ],
1919 "dependencies" : {
20- "purescript-bifunctors" : " ^3.0.0"
20+ "purescript-bifunctors" : " ^3.0.0" ,
21+ "purescript-monoid" : " ^3.0.0"
2122 }
2223}
Original file line number Diff line number Diff line change @@ -13,7 +13,10 @@ module Data.Validation.Semigroup
1313
1414import Prelude
1515
16+ import Control.Apply (lift2 )
17+
1618import Data.Bifunctor (class Bifunctor )
19+ import Data.Monoid (class Monoid , mempty )
1720
1821-- | The `V` functor, used for applicative validation
1922-- |
@@ -70,3 +73,9 @@ instance applyV :: (Semigroup err) => Apply (V err) where
7073
7174instance applicativeV :: (Semigroup err ) => Applicative (V err ) where
7275 pure = Valid
76+
77+ instance semigroupV :: (Semigroup err , Semigroup a ) => Semigroup (V err a ) where
78+ append = lift2 append
79+
80+ instance monoidV :: (Semigroup err , Monoid a ) => Monoid (V err a ) where
81+ mempty = pure mempty
Original file line number Diff line number Diff line change @@ -14,10 +14,12 @@ module Data.Validation.Semiring
1414import Prelude
1515
1616import Control.Alt (class Alt )
17+ import Control.Apply (lift2 )
1718import Control.Plus (class Plus )
1819import Control.Alternative (class Alternative )
1920
2021import Data.Bifunctor (class Bifunctor )
22+ import Data.Monoid (class Monoid , mempty )
2123
2224-- | The `V` functor, used for alternative validation
2325-- |
@@ -77,6 +79,12 @@ instance applyV :: (Semiring err) => Apply (V err) where
7779instance applicativeV :: (Semiring err ) => Applicative (V err ) where
7880 pure = Valid
7981
82+ instance semigroupV :: (Semiring err , Semigroup a ) => Semigroup (V err a ) where
83+ append = lift2 append
84+
85+ instance monoidV :: (Semiring err , Monoid a ) => Monoid (V err a ) where
86+ mempty = pure mempty
87+
8088instance altV :: (Semiring err ) => Alt (V err ) where
8189 alt (Invalid err1) (Invalid err2) = Invalid (err1 + err2)
8290 alt (Invalid _) a = a
You can’t perform that action at this time.
0 commit comments