import Control.Monad.Trans.Maybe
import Control.Monad.Unicode
import Data.Collections
+import qualified Data.Collections.Newtype.TH as C
import qualified Data.Map as M
import Data.Monoid
import Data.Monoid.Unicode
import Network.HTTP.Lucu.Resource.Internal
import Network.HTTP.Lucu.Utils
import Network.URI hiding (path)
-import Prelude hiding (filter, lookup, null)
+import Prelude hiding (filter, foldr, lookup, null)
import Prelude.Unicode
-- |FIXME: docs
= Greedy { nResource ∷ !Resource }
| NonGreedy { nResource ∷ !Resource }
--- |FIXME: doc
+-- |Make a greedy resource node.
+--
+-- Say a client is trying to access \"\/aaa\/bbb\/ccc\' while there is
+-- no resource node at the path. If there are greedy resource nodes at
+-- \"\/aaa\/bbb\", \"\/aaa\" or \"/\" they will be chosen instead as a
+-- fallback. Greedy resource nodes are searched in depth-first order.
greedy ∷ Resource → ResourceNode
{-# INLINE CONLIKE greedy #-}
greedy = Greedy
{-# INLINEABLE canonPath #-}
canonPath = filter ((¬) ∘ null)
+C.derive [d| instance Foldable ResourceTree (Path, ResourceNode)
+ |]
+
+instance Collection ResourceTree (Path, ResourceNode) where
+ {-# INLINE filter #-}
+ filter f (Tree m) = Tree $ filter f m
+
-- |'findResource' performs the longest prefix match on the tree,
-- finding the most specific one.
instance ResourceMapper ResourceTree where