Re: Shorthand for map (like the old Xtend shorthand for collect)

257 views
Skip to first unread message

Heribert Schütz

unread,
Jul 30, 2012, 8:26:13 AM7/30/12
to xtend...@googlegroups.com, krusche...@googlemail.com
What about "self.buildings.map[rooms].flatten.map[windows].flatten"?  Not as concise, but at least still a "linear" notation, i.e., without nesting.

If IterableExtensions provided a method combining map and flatten, say "mapFlat", one could even write "self.buildings.mapFlat[rooms].mapFlat[windows]".

(A better name than "mapFlat"? Common Lisp calls it "mapcan", but that doesn't sound appropriate for Java/Xtend.)

Regards,
Heribert.

Am Sonntag, 15. Juli 2012 21:09:40 UTC+2 schrieb krusche...@googlemail.com:
In the old Xpand / Xtend expression language, there was a shorthand for collect, as documented in the Eclipse help:

As navigation through many objects is very common, there is a shorthand notation for collect that makes the expressions more readable. Instead of

self.employee.collect(e | e.birthdate) 

one can also write:

self.employee.birthdate

In general, when a property is applied to a collection of Objects, it will automatically be interpreted as a collect over the members of the collection with the specified property.

The syntax is a shorthand for collect, if the feature does not return a collection itself. But sometimes we have the following:

self.buildings.rooms.windows // returns a list of windows

This syntax works, but one cannot express it using the collect operation in an easy way.


As far as I understood (please correct me if I'm wrong), the map lambda expression can be used as a substitue of the old collect keyword.

But it doesn't seem to be possible to navigate through a model in such an easy way like the shorthand for collect in the example above self.buildings.rooms.windows. At least Xtend does not offer this possibility in auto completion for me and the compiler complains if I try to use it.

Is it possible that you again offer this shorthand? It would be very handy and reduce a lot of code in my project :-)

Vlad Dumitrescu

unread,
Jul 30, 2012, 8:33:49 AM7/30/12
to xtend...@googlegroups.com
On Mon, Jul 30, 2012 at 2:26 PM, Heribert Schütz
<goo...@heribert-schuetz.de> wrote:
> (A better name than "mapFlat"? Common Lisp calls it "mapcan", but that
> doesn't sound appropriate for Java/Xtend.)

flatMap is used in other languages.

regards,
Vlad
Reply all
Reply to author
Forward
0 new messages