2 ExistentialQuantification
7 module Network.HTTP.Lucu.Resource.Dispatcher
12 import Control.Applicative
13 import Data.ByteString (ByteString)
14 import Data.CaseInsensitive (CI)
16 import Data.Text (Text)
17 import Network.HTTP.Lucu.Resource.Internal
18 import Prelude.Unicode
21 class Dispatchable α where
25 → IO (Maybe ([ByteString], ResourceDef))
27 dispatcher ∷ α → Dispatcher
28 {-# INLINE dispatcher #-}
29 dispatcher = Dispatcher
32 data Dispatcher = ∀α. Dispatchable α ⇒ Dispatcher α
34 instance Dispatchable Dispatcher where
35 findResource (Dispatcher α) = findResource α
39 instance Monoid Dispatcher where
43 f ∷ CI Text → [ByteString] → IO (Maybe ([ByteString], ResourceDef))
44 f _ _ = return Nothing
46 {-# INLINEABLE mappend #-}
47 mappend (Dispatcher α) (Dispatcher β)
49 $ \host path → do r ← findResource α host path
52 Nothing → findResource β host path
54 instance Dispatchable (CI Text
56 → IO (Maybe ([ByteString], ResourceDef))) where
59 instance Dispatchable (CI Text
61 → Maybe ([ByteString], ResourceDef)) where
62 findResource = ((return ∘) ∘)
64 instance Dispatchable (CI Text
66 → IO (Maybe ResourceDef)) where
67 findResource = ((((<$>) ∘ (<$>)) ((,) []) ∘) ∘)
69 instance Dispatchable (CI Text
71 → Maybe ResourceDef) where
72 findResource = (((return ∘ ((,) [] <$>)) ∘) ∘)
74 instance Dispatchable ([ByteString]
75 → IO (Maybe ([ByteString], ResourceDef))) where
78 instance Dispatchable ([ByteString]
79 → Maybe ([ByteString], ResourceDef)) where
80 findResource = const ∘ (return ∘)
82 instance Dispatchable ([ByteString]
83 → IO (Maybe ResourceDef)) where
84 findResource = const ∘ (((<$>) ∘ (<$>)) ((,) []) ∘)
86 instance Dispatchable ([ByteString]
87 → Maybe ResourceDef) where
88 findResource = const ∘ ((return ∘ ((,) [] <$>)) ∘)
90 instance Dispatchable (IO (Maybe ([ByteString], ResourceDef))) where
91 findResource = const ∘ const
93 instance Dispatchable ([ByteString], ResourceDef) where
94 findResource = const ∘ const ∘ return ∘ Just
96 instance Dispatchable (IO (Maybe ResourceDef)) where
97 findResource = const ∘ const ∘ ((<$>) ∘ (<$>)) ((,) [])
99 instance Dispatchable ResourceDef where
100 findResource = const ∘ const ∘ return ∘ Just ∘ (,) []