diff options
| author | Joey Hess <joeyh@joeyh.name> | 2015-10-10 15:17:15 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2015-10-10 15:17:15 -0400 |
| commit | 480a25aaa804208d76cd362c9a6bd222ec66dee6 (patch) | |
| tree | 7fae0a11735caab29e5c1106a243d7527b25e3d8 /src/Propellor/PropAccum.hs | |
| parent | 1799f634d89f588eeaef6ff2f6226adf5add3389 (diff) | |
| parent | 63d653ee19b0f1bf2f4115d9f4ae9a93b00bae90 (diff) | |
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/PropAccum.hs')
| -rw-r--r-- | src/Propellor/PropAccum.hs | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/src/Propellor/PropAccum.hs b/src/Propellor/PropAccum.hs index dec204a2..61cf3dc8 100644 --- a/src/Propellor/PropAccum.hs +++ b/src/Propellor/PropAccum.hs @@ -2,10 +2,10 @@ module Propellor.PropAccum ( host - , props , PropAccum(..) + , (&) + , (&^) , (!) - , PropList , propigateContainer ) where @@ -25,49 +25,41 @@ import Propellor.PrivData host :: HostName -> Host host hn = Host hn [] mempty --- | Starts accumulating a list of properties. --- --- > propertyList "foo" $ props --- > & someproperty --- > ! oldproperty --- > & otherproperty -props :: PropList -props = PropList [] - -- | Something that can accumulate properties. class PropAccum h where -- | Adds a property. - -- - -- Can add Properties and RevertableProperties - (&) :: IsProp p => h -> p -> h + addProp :: IsProp p => h -> p -> h - -- | Like (&), but adds the property at the front of the list. - (&^) :: IsProp p => h -> p -> h + -- | Like addProp, but adds the property at the front of the list. + addPropFront :: IsProp p => h -> p -> h getProperties :: h -> [Property HasInfo] -instance PropAccum Host where - (Host hn ps is) & p = Host hn (ps ++ [toProp p]) - (is <> getInfoRecursive p) - (Host hn ps is) &^ p = Host hn (toProp p : ps) - (getInfoRecursive p <> is) - getProperties = hostProperties - -data PropList = PropList [Property HasInfo] +-- | Adds a property to a `Host` or other `PropAccum` +-- +-- Can add Properties and RevertableProperties +(&) :: (PropAccum h, IsProp p) => h -> p -> h +(&) = addProp -instance PropAccum PropList where - PropList l & p = PropList (toProp p : l) - PropList l &^ p = PropList (l ++ [toProp p]) - getProperties (PropList l) = reverse l +-- | Adds a property before any other properties. +(&^) :: (PropAccum h, IsProp p) => h -> p -> h +(&^) = addPropFront -- | Adds a property in reverted form. (!) :: PropAccum h => h -> RevertableProperty -> h h ! p = h & revert p -infixl 1 &^ infixl 1 & +infixl 1 &^ infixl 1 ! +instance PropAccum Host where + (Host hn ps is) `addProp` p = Host hn (ps ++ [toProp p]) + (is <> getInfoRecursive p) + (Host hn ps is) `addPropFront` p = Host hn (toProp p : ps) + (getInfoRecursive p <> is) + getProperties = hostProperties + -- | Adjust the provided Property, adding to its -- propertyChidren the properties of the provided container. -- |
