mirror of
https://github.com/typeable/validationt.git
synced 2024-11-22 01:34:05 +03:00
Merge pull request #6 from ilyakooo0/fixed-unexpexed-behaviour
Fixed unexpected behaviour
This commit is contained in:
commit
d676bd9d08
@ -81,25 +81,18 @@ mmAppend (MonoidMap a) (MonoidMap b) = MonoidMap $ M.unionWith (<>) a b
|
||||
-- | Convenient for 'vZoom' as first artument. Will prevent generation
|
||||
-- of map with 'mempty' values
|
||||
mmSingleton :: (Eq v, Monoid v, Ord k) => k -> v -> MonoidMap k v
|
||||
mmSingleton k = memptyWrap mempty $ MonoidMap . M.singleton k
|
||||
mmSingleton k v
|
||||
| v == mempty = mempty
|
||||
| otherwise = MonoidMap . M.singleton k $ v
|
||||
|
||||
-- | Set given value to 'mempty'
|
||||
setMempty :: (Monoid s) => ASetter' s a -> a -> s
|
||||
setMempty setter a = set setter a mempty
|
||||
|
||||
memptyWrap :: (Eq a, Monoid a) => b -> (a -> b) -> a -> b
|
||||
memptyWrap b f a
|
||||
| a == mempty = b
|
||||
| otherwise = f a
|
||||
|
||||
-- | If given container is not 'mempty', then use given function to
|
||||
-- append all its elements and return 'Just' result
|
||||
neConcat
|
||||
:: (Foldable f, Eq (f a), Monoid a, Monoid (f a))
|
||||
=> (a -> a -> a)
|
||||
-> f a
|
||||
-> Maybe a
|
||||
neConcat f = memptyWrap Nothing (Just . F.foldl' f mempty)
|
||||
neConcat :: Foldable f => (a -> a -> a) -> f a -> Maybe a
|
||||
neConcat f a
|
||||
| F.null a = Nothing
|
||||
| otherwise = Just $ F.foldr1 f a
|
||||
|
||||
textErrors :: [Text] -> Maybe Text
|
||||
textErrors = neConcat (\a b -> a <> ", " <> b)
|
||||
|
Loading…
Reference in New Issue
Block a user