Created
December 31, 2012 16:30
-
-
Save aeg/4421070 to your computer and use it in GitHub Desktop.
リストのリストをフラットなリストにする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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