Copyright | Copyright © 2015 PivotCloud Inc. |
---|---|
License | MIT |
Maintainer | Lars Kuhtz <lkuhtz@pivotmail.com> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
The distinction between appending on the left and appending on
the right is important for monoids that are sensitive to ordering
such as List
. It is also of relevance for monoids with set semantics
with non-extensional equality such as HashMap
.
Synopsis
- data LeftMonoidalUpdate a
- leftMonoidalUpdate :: Iso (LeftMonoidalUpdate a) (LeftMonoidalUpdate b) a b
- fromLeftMonoidalUpdate :: Iso a b (LeftMonoidalUpdate a) (LeftMonoidalUpdate b)
- pLeftMonoidalUpdate :: Monoid a => Parser a -> MParser a
- data RightMonoidalUpdate a
- rightMonoidalUpdate :: Iso (RightMonoidalUpdate a) (RightMonoidalUpdate b) a b
- fromRightMonoidalUpdate :: Iso a b (RightMonoidalUpdate a) (RightMonoidalUpdate b)
- pRightMonoidalUpdate :: Monoid a => Parser a -> MParser a
Documentation
data LeftMonoidalUpdate a Source #
Update a value by appending on the left. Under normal
circumstances you'll never use this type directly but only
its FromJSON
instance. See the leftMonoidalUpdate
for an example.
Instances
Semigroup a => Semigroup (LeftMonoidalUpdate a) Source # | |
Defined in Configuration.Utils.Monoid (<>) :: LeftMonoidalUpdate a -> LeftMonoidalUpdate a -> LeftMonoidalUpdate a # sconcat :: NonEmpty (LeftMonoidalUpdate a) -> LeftMonoidalUpdate a # stimes :: Integral b => b -> LeftMonoidalUpdate a -> LeftMonoidalUpdate a # | |
Monoid a => Monoid (LeftMonoidalUpdate a) Source # | |
Defined in Configuration.Utils.Monoid mempty :: LeftMonoidalUpdate a # mappend :: LeftMonoidalUpdate a -> LeftMonoidalUpdate a -> LeftMonoidalUpdate a # mconcat :: [LeftMonoidalUpdate a] -> LeftMonoidalUpdate a # | |
(FromJSON a, Monoid a) => FromJSON (LeftMonoidalUpdate a -> LeftMonoidalUpdate a) Source # | |
Defined in Configuration.Utils.Monoid parseJSON :: Value -> Parser (LeftMonoidalUpdate a -> LeftMonoidalUpdate a) # parseJSONList :: Value -> Parser [LeftMonoidalUpdate a -> LeftMonoidalUpdate a] # |
leftMonoidalUpdate :: Iso (LeftMonoidalUpdate a) (LeftMonoidalUpdate b) a b Source #
Update a value by appending on the left.
newtype RoutingTable = RoutingTable { _routingTableMap ∷ HashMap T.Text T.Text } $(makeLenses ''RoutingTable) instance FromJSON (RoutingTable → RoutingTable) where parseJSON = withObject "RoutingTable" $ \o → id <$< routingTableMap . from leftMonoidalUpdate %.: "route_map" % o
fromLeftMonoidalUpdate :: Iso a b (LeftMonoidalUpdate a) (LeftMonoidalUpdate b) Source #
This is the same as from leftMonoidalUpdate
but doesn't depend on
the lens Library.
pLeftMonoidalUpdate :: Monoid a => Parser a -> MParser a Source #
Update a value by appending on the left.
newtype RoutingTable = RoutingTable { _routingTableMap ∷ HashMap T.Text T.Text } $(makeLenses ''RoutingTable) pRoutingTable ∷ MParser RoutingTable pRoutingTable = routingTableMap %:: pLeftMonoidalUpdate pRoute where pRoute = option (eitherReader readRoute) % long "route" <> help "add a route to the routing table; the APIROUTE part must not contain a colon character" <> metavar "APIROUTE:APIURL" readRoute s = case break (== ':') s of (a,':':b) → fmapL T.unpack $ do validateNonEmpty "APIROUTE" a validateHttpOrHttpsUrl "APIURL" b return $ HM.singleton (T.pack a) (T.pack b) _ → Left "missing colon between APIROUTE and APIURL" fmapL f = either (Left . f) Right
data RightMonoidalUpdate a Source #
Update a value by appending on the right. Under normal
circumstances you'll never use this type directly but only
its FromJSON
instance. See the leftMonoidalUpdate
for an example.
Instances
Semigroup a => Semigroup (RightMonoidalUpdate a) Source # | |
Defined in Configuration.Utils.Monoid (<>) :: RightMonoidalUpdate a -> RightMonoidalUpdate a -> RightMonoidalUpdate a # sconcat :: NonEmpty (RightMonoidalUpdate a) -> RightMonoidalUpdate a # stimes :: Integral b => b -> RightMonoidalUpdate a -> RightMonoidalUpdate a # | |
Monoid a => Monoid (RightMonoidalUpdate a) Source # | |
Defined in Configuration.Utils.Monoid mempty :: RightMonoidalUpdate a # mappend :: RightMonoidalUpdate a -> RightMonoidalUpdate a -> RightMonoidalUpdate a # mconcat :: [RightMonoidalUpdate a] -> RightMonoidalUpdate a # | |
(FromJSON a, Monoid a) => FromJSON (RightMonoidalUpdate a -> RightMonoidalUpdate a) Source # | |
Defined in Configuration.Utils.Monoid parseJSON :: Value -> Parser (RightMonoidalUpdate a -> RightMonoidalUpdate a) # parseJSONList :: Value -> Parser [RightMonoidalUpdate a -> RightMonoidalUpdate a] # |
rightMonoidalUpdate :: Iso (RightMonoidalUpdate a) (RightMonoidalUpdate b) a b Source #
Update a value by appending on the right. See leftMonoidalUpdate
for
an usage example.
fromRightMonoidalUpdate :: Iso a b (RightMonoidalUpdate a) (RightMonoidalUpdate b) Source #
This is the same as from rightMonoidalUpdate
but doesn't depend on
the lens Library.
pRightMonoidalUpdate :: Monoid a => Parser a -> MParser a Source #
Update a value by appending on the right. See pLeftMonoidalUpdate
for an usage example.