Skip to content

Instantly share code, notes, and snippets.

@aeg
Created December 31, 2012 16:30
Show Gist options
  • Save aeg/4421070 to your computer and use it in GitHub Desktop.
Save aeg/4421070 to your computer and use it in GitHub Desktop.
リストのリストをフラットなリストにする
// Case #1
// リストのリストをフラットなリストにする
assert ['a', ['b', 'c',['d', 'e']]].flatten() == ['a', 'b', 'c', 'd', 'e']
// Case #2
// リスト展開演算子を用いて、リストを展開する
assert ['a', 'b', *['c', 'd']] == ['a', 'b', 'c', 'd']
// Case #3
// リスト展開演算子を用いて、変数に入っているリストを展開する
def list1 = ['c', 'd']
assert ['a', 'b', *list1] == ['a', 'b', 'c', 'd']
// Case #4
// リスト展開演算子が適用されるのは1段階のみ
def list2 = ['a', *['b', ['c', 'd']]]
assert list2 == ['a', 'b', ['c', 'd']]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment