Skip to content

Instantly share code, notes, and snippets.

@aeg
Created October 13, 2012 16:52
Show Gist options
  • Save aeg/3885319 to your computer and use it in GitHub Desktop.
Save aeg/3885319 to your computer and use it in GitHub Desktop.
部分リスト作成を追加。
// 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