[ 
https://issues.apache.org/jira/browse/FREEMARKER-73?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16185094#comment-16185094
 ] 

Ondra Žižka commented on FREEMARKER-73:
---------------------------------------

One more note for {{?sequence}}.
How would that handle non-existing variables, nulls and scalar types? Is there 
any specification?

How about these:
""?seqence         ->  [""] ?
nonExistent?seqence   ->   [] ?
nonExistent!?seqence  ->   [] ?   Would [""]  make  sense here?
false?sequence            ->   [] ?  Or [false] ?
null?sequence            ->   [] ?  Or null?

As a starting point here, I would take that scalar values would come before 
{{?sequence}} mostly as a result of a missing value, a safeguard for it 
({{!}}), a check for it, or a function returning something else than normally 
(e.g. no items found -> null) etc.

Therefore, the resulting values should be the least surprise, i.e. I would 
prefer [] in most places. Because then, the value is most likely going to be 
used for {{<#list>}} or other way of iteration, and (not) iterating over an 
empty sequence won't do any harm. 

> ?seq to convert some models to a sequence
> -----------------------------------------
>
>                 Key: FREEMARKER-73
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-73
>             Project: Apache Freemarker
>          Issue Type: Bug
>          Components: engine
>    Affects Versions: 2.3.26-incubating
>            Reporter: Ondra Žižka
>             Fix For: 2.3.27-incubating
>
>
> The objects I feed to FreeMarker often cotain {{Iterator}}s rather than 
> {{Collection}}s.
> While it's quite easy to write a FreeMarker function 
> {{iteratorToList(Iterator)}}, it would be convenient to have the following:
> A built-in that would convert various models to a sequence. Could be named 
> {{?seq}} or {{?sequence}}.
> Usage:
> {code}<#assign foo = myIterable?seq>{code}
> {code}<#assign foo = myIterator?seq>{code}
> * A sequence would stay intact.
> * An {{Iterable}} wrapped in FM model would become internally a {{List}} - 
> all elements consumed and stored.
> For me, other cases are not that important, but with some imagination, other 
> models could also leverage it, like,
> * A {{Stream}} could be also turned into a {{List}}.
> * A hash could turn into a sequence of key/value pairs. That could be useful 
> for debugging purposes.
> I am not sure if I didn't propose that already, but I could only find 
> FREEMARKER-62.
> Thanks for considering.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to