Wednesday, August 17, 2011

1 comments:

Hi, I needed exactly this, thank you very much. I was trying to write something like that but wrote an elseif_ method - but that way, I couldn't call elseif_ but had to call .elseif_. After some painless Googling, I found your code, and integrated the missing idea into my code (with credit).

Regarding your question, here's my (simplified) version of your code. Note that it is purely functional, and that it prevents statically additional else_ branches, because else_ returns a different type; one could easily build a non-purely functional version using mutable collections, but I don't think it's worth it (not for my use-case anyway). Your code ends up implementing manually a linked list, in practice, and that's something you should avoid, especially in Scala where standard collections have so much to give.

So, here's the code (and apologies for the formatting, but the <pre> tag is forbidden here):