Skip to content

Instantly share code, notes, and snippets.

@mike-neck
Created February 8, 2018 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-neck/9317d690e1699bd3de0600c78116521a to your computer and use it in GitHub Desktop.
Save mike-neck/9317d690e1699bd3de0600c78116521a to your computer and use it in GitHub Desktop.
Eclipse Collections 使い方メモ

primitive な コレクションを使いたい

  • IntLists factory を使う
import org.eclipse.collections.impl.factory.primitive.IntLists

def list = IntLists.mutable.of(1,2,3,4)
// -> [1, 2, 3, 4]

二つのリストをくっつけたい

  • MutableCollection#withAll(Iterable<T>) を使う
def list = Lists.mutable.of('foo', 'bar')
def another = Lists.immutable.of('baz', 'qux')

def result = list.withAll(another)
// -> [foo, bar, baz, qux]

これは Java 標準のAPI でやる場合の次のコードと同等

def list = ['foo', 'bar']
def another = ['baz', 'qux']

list.addAll(another)
list

つまり、 Collector を作る時の combiner の指定を1行のラムダに変更できる

標準API

(left, right) -> {
  left.addAll(right);
  return left;
}

eclipse collections

MutableList::withAll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment