Skip to content

Instantly share code, notes, and snippets.

@aeg
Last active December 10, 2015 10:18
Show Gist options
  • Save aeg/4419954 to your computer and use it in GitHub Desktop.
Save aeg/4419954 to your computer and use it in GitHub Desktop.
リストの和と積をとる
// Case #1
// リストの集合演算的な和をとる
def list1 = ['a' ,'b', 'c']
def list2 = ['b', 'c', 'd', 'e']
assert (list1 + list2).unique() == ['a', 'b', 'c', 'd', 'e']
// Case #2
// リストの集合演算的な積をとる(リストの共通部分をとる)
assert list1.intersect(list2) == ['b', 'c']
// Case #3
// リストの集合演算的な差をとる
// list2 にある要素を list1 から消したものが得られる
assert list1 - list2 == ['a']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment