]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Resource/Dispatcher.hs
Rename: Resource --> Rsrc; ResourceDef --> Resource
[Lucu.git] / Network / HTTP / Lucu / Resource / Dispatcher.hs
index ac3112fb9d030cb91330f0d7c2f2d0aa3a103cba..ffaba2d1ec114e49a3a22eb900a1bc81d286055e 100644 (file)
@@ -22,23 +22,24 @@ class Dispatchable α where
     dispatch ∷ α
              → CI Text
              → [ByteString]
-             → IO (Maybe ([ByteString], ResourceDef))
+             → IO (Maybe ([ByteString], Resource))
 
     dispatcher ∷ α → Dispatcher
     {-# INLINE dispatcher #-}
     dispatcher = Dispatcher
 
--- |FIXME: doc
+-- |Container type for 'Dispatchable' type class.
 data Dispatcher = ∀α. Dispatchable α ⇒ Dispatcher α
 
 instance Dispatchable Dispatcher where
     dispatch (Dispatcher α) = dispatch α
     dispatcher = id
 
--- |FIXME: doc
+-- |@a `'mappend'` b@ first tries to find a resource with @a@, and if
+-- it returns 'Nothing', tries @b@ next.
 instance Monoid Dispatcher where
     {-# INLINE mempty #-}
-    mempty = dispatcher (return Nothing ∷ IO (Maybe ResourceDef))
+    mempty = dispatcher ()
 
     {-# INLINEABLE mappend #-}
     mappend (Dispatcher α) (Dispatcher β)
@@ -48,25 +49,33 @@ instance Monoid Dispatcher where
                               Just _  → return r
                               Nothing → dispatch β host path
 
+-- |An IO-based dispatcher returning resource paths as well as
+-- 'Resource's.
 instance Dispatchable (CI Text
                        → [ByteString]
-                       → IO (Maybe ([ByteString], ResourceDef))) where
+                       → IO (Maybe ([ByteString], Resource))) where
     dispatch = id
 
-instance Dispatchable (CI Text → [ByteString] → IO (Maybe ResourceDef)) where
+-- |An IO-based dispatcher.
+instance Dispatchable (CI Text → [ByteString] → IO (Maybe Resource)) where
     dispatch = ((((<$>) ∘ (<$>)) ((,) []) ∘) ∘)
 
-instance Dispatchable (CI Text → [ByteString] → Maybe ResourceDef) where
+-- |A pure dispatcher.
+instance Dispatchable (CI Text → [ByteString] → Maybe Resource) where
     dispatch = (((return ∘ ((,) [] <$>)) ∘) ∘)
 
-instance Dispatchable ([ByteString] → IO (Maybe ResourceDef)) where
+-- |An IO-based dispatcher ignoring host names.
+instance Dispatchable ([ByteString] → IO (Maybe Resource)) where
     dispatch = const ∘ (((<$>) ∘ (<$>)) ((,) []) ∘)
 
-instance Dispatchable ([ByteString] → Maybe ResourceDef) where
+-- |A pure dispatcher ignoring host names.
+instance Dispatchable ([ByteString] → Maybe Resource) where
     dispatch = const ∘ ((return ∘ ((,) [] <$>)) ∘)
 
-instance Dispatchable (IO (Maybe ResourceDef)) where
-    dispatch = const ∘ const ∘ ((<$>) ∘ (<$>)) ((,) [])
-
-instance Dispatchable ResourceDef where
+-- |The constant dispatcher returning always the same 'Resource'.
+instance Dispatchable Resource where
     dispatch = const ∘ const ∘ return ∘ Just ∘ (,) []
+
+-- |The empty dispatcher returning always 'Nothing'.
+instance Dispatchable () where
+    dispatch _ _ _ = return Nothing