packages feed

registry 0.1.0.4 → 0.1.0.5

raw patch · 2 files changed

+46/−15 lines, 2 files

Files

registry.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: bd4dc95f3b494c413fd4f8d751f461b17b0020960fcd856df631e8c826ebbfd7+-- hash: 1ca0ac117d7f1e1ba6f55c94a7f3823951cf78d4e19ef293fbd0d3afc61142af  name:           registry-version:        0.1.0.4+version:        0.1.0.5 synopsis:       data structure for assembling "components" description:    This library provides a "Registry" which is a data structure containing a list of functions and values representing dependencies in a directed acyclic graph. A `make` function can then be used to create a value of a specific type out of the registry.                 You can start with the [README](https://github.com/etorreborre/registry/blob/master/README.md) for a full description of the library.
src/Data/Registry/Registry.hs view
@@ -154,32 +154,50 @@   => b   -> Registry ins out   -> Registry ins out-specialize b (Registry values functions (Specializations c) modifiers) = Registry+specialize = specializeUnsafe @a @b @ins @out++-- | This is similar to specialize but additionally uses the 'Show' instance of @b@+--   to display more information when printing the registry out+specializeVal :: forall a b ins out . (Typeable a, Contains a out, Typeable b, Show b)+  => b+  -> Registry ins out+  -> Registry ins out+specializeVal = specializeUnsafeVal @a @b @ins @out++specializeValTo :: forall m a b ins out . (Applicative m, Typeable a, Contains a out, Typeable (m b), Typeable b, Show b)+  => b+  -> Registry ins out+  -> Registry ins out+specializeValTo = specializeUnsafeValTo @m @a @b @ins @out++-- | For a given type `a` being currently built+--   when a value of type `b` is required pass a specific+--   value+specializeUnsafe :: forall a b ins out . (Typeable a, Typeable b)+  => b+  -> Registry ins out+  -> Registry ins out+specializeUnsafe b (Registry values functions (Specializations c) modifiers) = Registry   values   functions   (Specializations ((someTypeRep (Proxy :: Proxy a), createTypeableValue b) : c))   modifiers --- | This is similar to specialize but additionally uses the 'Show' instance of @b@---   to display more information when printing the registry out-specializeVal :: forall a b ins out . (Typeable a, Contains a out, Typeable b, Show b)+specializeUnsafeVal :: forall a b ins out . (Typeable a, Contains a out, Typeable b, Show b)   => b   -> Registry ins out   -> Registry ins out-specializeVal b (Registry values functions (Specializations c) modifiers) = Registry+specializeUnsafeVal b (Registry values functions (Specializations c) modifiers) = Registry   values   functions   (Specializations ((someTypeRep (Proxy :: Proxy a), createValue b) : c))   modifiers --- | This is similar to specialize but additionally uses the 'Show' instance of @b@---   to display more information when printing the registry out and---   it "lifts" the value to an 'Applicative' context-specializeValTo :: forall m a b ins out . (Applicative m, Typeable a, Contains a out, Typeable (m b), Typeable b, Show b)+specializeUnsafeValTo :: forall m a b ins out . (Applicative m, Typeable a, Typeable (m b), Typeable b, Show b)   => b   -> Registry ins out   -> Registry ins out-specializeValTo b (Registry values functions (Specializations c) modifiers) = Registry+specializeUnsafeValTo b (Registry values functions (Specializations c) modifiers) = Registry   values   functions   (Specializations ((someTypeRep (Proxy :: Proxy a), liftProvidedValue @m b) : c))@@ -190,7 +208,15 @@   => (a -> a)   -> Registry ins out   -> Registry ins out-tweak f (Registry values functions specializations (Modifiers mf)) = Registry values functions specializations+tweak = tweakUnsafe++-- | Once a value has been computed allow to modify it before storing+--   it+tweakUnsafe :: forall a ins out . (Typeable a)+  => (a -> a)+  -> Registry ins out+  -> Registry ins out+tweakUnsafe f (Registry values functions specializations (Modifiers mf)) = Registry values functions specializations   (Modifiers ((someTypeRep (Proxy :: Proxy a), createFunction f) : mf))  -- | Return singleton values for a monadic type@@ -199,6 +225,11 @@ singleton :: forall m a ins out . (MonadIO m, Typeable a, Typeable (m a), Contains (m a) out)   => Registry ins out   -> IO (Registry ins out)-singleton r = do+singleton = singletonUnsafe @m @a @ins @out++singletonUnsafe :: forall m a ins out . (MonadIO m, Typeable a, Typeable (m a))+  => Registry ins out+  -> IO (Registry ins out)+singletonUnsafe r = do   cache <- newCache @a-  pure $ tweak @(m a) (fetch cache) r+  pure $ tweakUnsafe @(m a) (fetch cache) r