Better Reduce For Xtend

A coworker pointed me to yet another “better Java” named Xtend. I currently have to use Java in my day job because of the excellent support to access MSSQL server. After fighting with Java for some days now, I hoped Xtend would make the job a little more pleasant. After tinkering a bit and stumbling a few times over the static type system I came across a real glitch, at least for me: the ubiquitous “reduce” function. It is realized as an extension method, which means one can simply call reduce on every iterable and its subtypes, and it looks quite neat:


But there is one big problem with it: the elements in the iterable and the return value have to be the same type! I have never encountered a real world case where I would want that behaviour. Another thing I missed is a optional start value. The following gist shows a different prototypical implementation of reduce, with an initial value and a return value of a different type:


I’m not sure why the original implementation is so restrained. Maybe future versions will make it better. Except the painful static typing and this glitch I think Xtend is quite amazing and can make me more productive in the Java world.

2 thoughts on “Better Reduce For Xtend

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s