Safe Haskell | None |
---|
A small utility module that provides a foundation for dynamically enabling and disabling features.
- data FeatureToggle a
- data FeatureProvider a = FeatureProvider {
- enabledProvider :: a
- enabledProviderName :: Text
- availableProviders :: [(Text, a)]
- defaultProvider :: a
- enable :: FeatureToggle a -> FeatureToggle a
- disable :: FeatureToggle a -> FeatureToggle a
- toggle :: FeatureToggle a -> FeatureToggle a
- withToggle :: FeatureToggle a -> b -> b -> b
- whenEnabled :: (Functor m, Monad m) => FeatureToggle a -> m b -> m ()
- whenDisabled :: (Functor m, Monad m) => FeatureToggle a -> m b -> m ()
- use :: Text -> FeatureProvider a -> Either (FeatureProvider a) (FeatureProvider a)
- withProvider :: FeatureProvider a -> (a -> b) -> b
Documentation
data FeatureToggle a Source
A simple toggle for selectively enabling or disabling functionality.
Eq (FeatureToggle a) | |
Read (FeatureToggle a) | |
Show (FeatureToggle a) |
data FeatureProvider a Source
A union of different feature providers which maintains a currently active provider and facilities for changing providers.
Use this when you don't need to disable a feature, just to replace the implementation.
FeatureProvider | |
|
enable :: FeatureToggle a -> FeatureToggle aSource
Enable a feature.
disable :: FeatureToggle a -> FeatureToggle aSource
Disable a feature.
toggle :: FeatureToggle a -> FeatureToggle aSource
Flip a toggle from enabled to disabled or vice versa.
withToggle :: FeatureToggle a -> b -> b -> bSource
Switch on values depending on whether a toggle is enabled or disabled.
whenEnabled :: (Functor m, Monad m) => FeatureToggle a -> m b -> m ()Source
Execute an action only when the specified feature is enabled.
whenDisabled :: (Functor m, Monad m) => FeatureToggle a -> m b -> m ()Source
Execute an action only when the specified feature is disabled.
use :: Text -> FeatureProvider a -> Either (FeatureProvider a) (FeatureProvider a)Source
Replace the current feature provider with another provider. Returns Left if the default provider is used due to a failed lookup. Returns Right if the lookup succeeded.
Use "default" as the lookup value if you want to explicitly load the default provider.
withProvider :: FeatureProvider a -> (a -> b) -> bSource
Apply a function that takes a feature provided by a FeatureProvider.