Hi. Groovy's Closure have a name of method 'curry'. But this is not work for a real currying, it work as a partial function application. So, I wrote method of 'Real currying'. Referenced http://en.wikipedia.org/wiki/Currying Closure add = {a, b, c -> a + b + c } // Closure of adding 3 arguments. assert add(1, 2, 3) == realCurry(add)(1)(2)(3) assert 6 == add(1, 2, 3) def curriedAdd = realCurry(ad
withDefaultはwithLazyDefaultのエイリアスなので機能的にはwithEagerDefault、withLazyDefaultが追加されました。今までmapには似たようなのがありましたが、今回Listにも追加されました。 それぞれ要素を取得した際の要素のパディング方法や、nullの扱いが若干違います。 まずwithLazyDefaultから。要素を取得したタイミングで初期化されnullの要素が特別な意味(初期化対象)を持っています。 def items = [1, 2].withLazyDefault { it * it } assert items == [1, 2] assert items[4] == 16 // 4を取ると間の要素をnullでパディング assert items == [1, 2, null, null, 16] assert items[3]
Groovy 1.8 から closure composition が使えるようになりました。というかまだBetaですが。 closure composition は << と >> を使います。 def plus2 = { it + 2 } def times3 = { it * 3 } def composed1 = plus2 << times3 composed1 は times3 の関数の結果を plus2 に適用する関数となります。 composed1 は以下のような結果となります。 composed1(3) // plus2(times3(3)) なので 11 composed1(4) // plus2(times3(4)) なので 14 関数を入れ替えると以下のようになります。 def composed2 = times3 << plus2 composed2(3) //
Design patterns I’m learning design patterns. There is a lot of documentation about software design patterns, but I’m interested in closure design patterns.* Many patterns imply object-orientation, so may not be as applicable in dynamic languages. Peter Norvig demonstrates that 16 out of 23 patterns in the Design Patterns book are simplified or eliminated, Design Patterns in Dynamic Languages. I’v
Using design patterns with Java is a well-established topic. Design patterns also apply to Groovy: some patterns carry over directly (and can make use of normal Groovy syntax improvements for greater readability) some patterns are no longer required because they are built right into the language or because Groovy supports a better way of achieving the intent of the pattern some patterns that have
Google just announced that their Google App Engine cloud hosting platform now supports other languages than Python: namely Java and Groovy! You can now effectively write your Google App Engine applications in Groovy! A couple of weeks ago, the SpringSource Groovy team and the Google App Engine Java team worked together, hand in hand, to iron out the details, to ensure that the popular and award-wi
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く