@@ -10,6 +10,7 @@ module Lumi.Components.Form.Validation
1010 , _Validated , _Fresh , _Modified
1111 , setFresh , setModified
1212 , ModifyValidated (..)
13+ , ValidatedNewtype (..), _ValidatedNewtype
1314 , class CanValidate , fresh , modified , fromValidated
1415 , validated
1516 , warn
@@ -26,10 +27,11 @@ import Data.Enum (toEnum)
2627import Data.Eq (class Eq1 )
2728import Data.Foldable (foldMap )
2829import Data.Int as Int
29- import Data.Lens (Lens , Prism' , lens , over , prism' , review , view )
30+ import Data.Lens (Lens , Prism' , Iso' , lens , over , prism' , review , view )
31+ import Data.Lens.Iso.Newtype (_Newtype )
3032import Data.Maybe (Maybe (..))
3133import Data.Monoid (guard )
32- import Data.Newtype (un )
34+ import Data.Newtype (class Newtype , un )
3335import Data.Nullable (notNull )
3436import Data.Number as Number
3537import Data.Ord (class Ord1 )
@@ -201,6 +203,13 @@ setModified = mapping (ModifyValidated (Modified <<< view _Validated))
201203-- | records containing `Validated` values.
202204newtype ModifyValidated = ModifyValidated (Validated ~> Validated )
203205
206+ newtype ValidatedNewtype a = ValidatedNewtype a
207+
208+ derive instance ntMVP :: Newtype (ValidatedNewtype a ) _
209+
210+ _ValidatedNewtype :: forall s a . Newtype s a => Iso' (ValidatedNewtype s ) a
211+ _ValidatedNewtype = _Newtype <<< _Newtype
212+
204213instance modifyValidated :: Mapping ModifyValidated a a => Mapping ModifyValidated (Validated a ) (Validated a ) where
205214 mapping m@(ModifyValidated f) = over _Validated (mapping m) <<< f
206215else instance modifyValidatedRecord ::
@@ -210,6 +219,8 @@ else instance modifyValidatedRecord ::
210219 mapping d = hmap d
211220else instance modifyValidatedArray :: Mapping ModifyValidated a a => Mapping ModifyValidated (Array a ) (Array a ) where
212221 mapping d = map (mapping d)
222+ else instance modifyValidatedNewtype :: (Newtype a b , Mapping ModifyValidated b b ) => Mapping ModifyValidated (ValidatedNewtype a ) (ValidatedNewtype a ) where
223+ mapping d = over (_Newtype <<< _Newtype) (mapping d)
213224else instance modifyValidatedIdentity :: Mapping ModifyValidated a a where
214225 mapping _ = identity
215226
0 commit comments