Created
October 13, 2012 16:52
-
-
Save aeg/3885319 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 | |
// リストの指定した要素で新たなリストを取得する | |
def list = ['a', 'b', 'c', 'd', 'e'] | |
assert list[0, 2, 4] == ['a', 'c', 'e'] | |
// Case #2 | |
// リストの指定した範囲で新たなリストを取得する | |
list = ['a', 'b', 'c', 'd', 'e'] | |
assert list[1..3] == ['b', 'c', 'd'] | |
// Case #3 | |
// リストの先頭からn要素を取得する。 | |
list = ['a', 'b', 'c', 'd', 'e'] | |
assert list.take(3) == ['a', 'b', 'c'] | |
// Case #4 | |
// リストの先頭要素以外の要素を取得する。 | |
list = ['a', 'b', 'c', 'd', 'e'] | |
assert list.tail() == ['b', 'c', 'd', 'e'] | |
// Case #5 | |
// リストの特定の条件にマッチするまでの要素を取得する。 | |
list = ['a', 'b', 'c', 'd', 'e'] | |
assert list.takeWhile{it < 'c'} == ['a', 'b'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment