freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ondra Žižka (JIRA) <j...@apache.org>
Subject [jira] [Comment Edited] (FREEMARKER-73) ?seq to convert some models to a sequence
Date Sat, 30 Sep 2017 03:24:00 GMT

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

Ondra Žižka edited comment on FREEMARKER-73 at 9/30/17 3:23 AM:
----------------------------------------------------------------

If I use {{sometimesNull!?sequence}}, that would give me {{""?sequence}} and thus error, then?
How could I get an empty sequence rather than error? Did you mean {{sometimesNull![]?sequence}}
?

Anyway, you're right. Type magic is a bad idea.

The thing is that I have highly unpredictable models, deep models where things can be missing
almost at any level (It's a graph traversed through method or getter calls). And handling
the missing cases is a large part of FM template code. Although it got a lot better with few
recent changes. (The Iterators change helped a lot.)
I will come up with something better ;)


was (Author: pekarna):
If I use {{sometimesNull!?sequence}}, that would give me {{""?sequence}} and thus error, then?
How could I get an empty sequence rather than error? Did you mean {{sometimesNull![]?sequence}}
?

Also, before I open an issue, what would be your view on a.very.long.expr!! being a shorthand
for {{(a.very.long.expr)!}} ?  The effect of !! would go back to the "root" of the expression,
i.e. where the part the !! comes after started. Not sure if that would have clear enough rules,
though.

Anyway, you're right. Type magic is a bad idea.

The thing is that I have highly unpredictable models, deep models where things can be missing
almost at any level (It's a graph traversed through method or getter calls). And handling
the missing cases is a large part of FM template code. Although it got a lot better with few
recent changes. (The Iterators change helped a lot.)
I will come up with something better ;)

> ?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)

Mime
View raw message