On Wed, Feb 23, 2011 at 8:50 PM, MightyByte <[email protected]> wrote:
> I agree that this would probably be a good addition.  Looks like
> mapValues should actually be:
>
> mapBind :: (Monad m) => (a -> [(Text, Template)]) -> [a] -> TemplateMonad m ()
>
> ...keeping these definitions in mind:
>
> type Template = [Node]
> type Splice m = TemplateMonad m Template
>
> The substantive difference between this and yours is returning ()
> because this function really just modifies the template state.

No, the point is that it modifies the template state, runs the child
nodes, and concats the results; so it really would be a splice.


> However, I was wondering if the first parameter should be (a ->
> [(Text, Splice m)]).  (Returning TemplateMonad computations instead of
> pure templates.)  This fits more naturally with the the existing
> bindSplices.
>
> bindSplices :: Monad m => [(Text, Splice m)] -> TemplateState m ->
> TemplateState m
>
> And maybe we should call it mapBind instead of mapValues.  Thoughts?
> If this seems reasonable I'll go ahead and commit it.

I think we're talking about slightly different things; to be clear, my
idea for mapValues would be:

  1. get the original TemplateState out of the TemplateMonad with
"getTS"; call this "origTS"

  2. get the child nodes out of the TemplateMonad; i.e.
         nodes <- liftM childNodes getParamNode

  3. for each element in the list:

    * 1) bind the tags you got from applying the map function (the
[(Text, Template)] values)
        putTS (bindSplices ... origTS)

    * 2) run the nodes given the new template state, i.e.:
        runNodeList nodes

  4. after you mapM #3 across your input list, take the list of
results (of type [Template]) and concat them to get a value of type
Template

  5. reset the original template state and return the result from #4

G.
-- 
Gregory Collins <[email protected]>
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap

Reply via email to