るりまサーチ

最速Rubyリファレンスマニュアル検索!
61件ヒット [1-61件を表示] (0.022秒)
トップページ > クエリ:slice[x] > クエリ:chunk_while[x]

別のキーワード

  1. _builtin chunk
  2. lazy chunk
  3. _builtin chunk_while
  4. enumerable chunk_while
  5. enumerable chunk

ライブラリ

モジュール

キーワード

検索結果

Enumerable#chunk_while {|elt_before, elt_after| ... } -> Enumerator (18137.0)

要素を前から順にブロックで評価し、その結果によって要素をチャンクに分け た(グループ化した)要素を持つEnumerator を返します。

...ックパラメータに渡す Enumerator
を返します。eachメソッドは以下のように呼び出します。
//emlist{
enum.chunk_while { |elt_before, elt_after| bool }.each { |ary| ... }
//}
to_a や map などのその他の Enumerable モジュールのメソッ...
...ドも有用です。

//emlist[例][ruby]{
# 1ずつ増加する部分配列ごとに分ける。
a = [1,2,4,9,10,11,12,15,16,19,20,21]
b = a.chunk_while {|i, j| i+1 == j }
p b.to_a # => [[1, 2], [4], [9, 10, 11, 12], [15, 16], [19, 20, 21]]
c = b.map {|a| a.length < 3 ? a : "#{a.first}-#{a.last}...
...7, 9, 4, 2, 0]
p a.chunk_while {|i, j| i.even? == j.even? }.to_a
# => [[7, 5, 9], [2, 0], [7, 9], [4, 2, 0]]
//}

Enumerable#slice_when はブロックの戻り値が真ではなく偽の時に要素
を分ける事を除いて同じ処理を行います。

@see Enumerable#slice_when, Enumerable#c...

Enumerable#slice_before {|elt| bool } -> Enumerator (6150.0)

パターンがマッチした要素、もしくはブロックが真を返した要素から 次にマッチする手前までを チャンク化(グループ化)したものを繰り返す Enumerator を 返します。

...数要素をチャンクの先頭と見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_before(&:even?).to_a
# => [[0], [2], [4, 1], [2], [4, 5, 3, 1], [4], [2]]

# 奇数要素をチャンクの先頭と見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_before(&:odd?).to_a
# => [[0, 2, 4], [1, 2, 4], [5], [3], [1, 4, 2]]...
...# ChangeLog のエントリーを順に取る
open("ChangeLog") {|f|
f.slice_before(/\A\S/).each {|e| pp e}
}

# 上と同じだが、パターンでなくブロックを使う
open("ChangeLog") {|f|
f.slice_before {|line| /\A\S/ === line }.each {|e| pp e}
}

# "svn proplist -R" の結果を...
...合、これを
まとめる処理をするためには以下のようにします
(Enumerable#chunk_while のより簡単な例も参照)。

//emlist[][ruby]{
a = [0,2,3,4,6,7,9]
prev = a[0]
p a.slice_before {|e|
prev, prev2 = e, prev
prev2 + 1 != e
}.map {|es|
es.length <= 2 ? es.join(",")...

Enumerable#slice_before(pattern) -> Enumerator (6150.0)

パターンがマッチした要素、もしくはブロックが真を返した要素から 次にマッチする手前までを チャンク化(グループ化)したものを繰り返す Enumerator を 返します。

...数要素をチャンクの先頭と見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_before(&:even?).to_a
# => [[0], [2], [4, 1], [2], [4, 5, 3, 1], [4], [2]]

# 奇数要素をチャンクの先頭と見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_before(&:odd?).to_a
# => [[0, 2, 4], [1, 2, 4], [5], [3], [1, 4, 2]]...
...# ChangeLog のエントリーを順に取る
open("ChangeLog") {|f|
f.slice_before(/\A\S/).each {|e| pp e}
}

# 上と同じだが、パターンでなくブロックを使う
open("ChangeLog") {|f|
f.slice_before {|line| /\A\S/ === line }.each {|e| pp e}
}

# "svn proplist -R" の結果を...
...合、これを
まとめる処理をするためには以下のようにします
(Enumerable#chunk_while のより簡単な例も参照)。

//emlist[][ruby]{
a = [0,2,3,4,6,7,9]
prev = a[0]
p a.slice_before {|e|
prev, prev2 = e, prev
prev2 + 1 != e
}.map {|es|
es.length <= 2 ? es.join(",")...

Enumerable#slice_when {|elt_before, elt_after| bool } -> Enumerator (6149.0)

要素を前から順にブロックで評価し、その結果によって要素をチャンクに分け た(グループ化した)要素を持つEnumerator を返します。

...ロックパラメータに渡す Enumerator
を返します。eachメソッドは以下のように呼び出します。
//emlist{
enum.slice_when { |elt_before, elt_after| bool }.each { |ary| ... }
//}
to_a や map などのその他の Enumerable モジュールのメソッ...
...ドも有用です。

//emlist[例][ruby]{
# 1ずつ増加する部分配列ごとに分ける。
a = [1,2,4,9,10,11,12,15,16,19,20,21]
b = a.slice_when {|i, j| i+1 != j }
p b.to_a # => [[1, 2], [4], [9, 10, 11, 12], [15, 16], [19, 20, 21]]
c = b.map {|a| a.length < 3 ? a : "#{a.first}-#{a.last...
...lines.slice_when {|l1, l2| /\A\s*\z/ =~ l1 && /\S/ =~ l2 }.to_a
# => [["foo\n", "bar\n", "\n"], ["baz\n", "qux\n"]]
//}

Enumerable#chunk_while はブロックの戻り値が偽ではなく真の時に要
素を分ける事を除いて同じ処理を行います。

@see Enumerable#chunk_while, Enum...

Enumerator::Lazy (24.0)

map や select などのメソッドの遅延評価版を提供するためのクラス。

...llect
* flat_map/collect_concat
* select/find_all
* reject
* grep, grep_v
* take, take_while
* drop, drop_while
* slice_before, slice_after, slice_when
* chunk, chunk_while
* uniq
* zip (※互換性のため、ブロックを渡さないケースのみlazy)

Lazyオブジェクトは、En...
...map/collect_concat
* filter_map
* select/find_all
* reject
* grep, grep_v
* take, take_while
* drop, drop_while
* slice_before, slice_after, slice_when
* chunk, chunk_while
* uniq
* zip (※互換性のため、ブロックを渡さないケースのみlazy)

Lazyオブジェクトは、En...
...map/collect_concat
* filter_map
* select/find_all
* reject
* grep, grep_v
* take, take_while
* drop, drop_while
* slice_before, slice_after, slice_when
* chunk, chunk_while
* uniq
* compact
* zip (※互換性のため、ブロックを渡さないケースのみlazy)

Lazyオブジェク...

絞り込み条件を変える

NEWS for Ruby 2.3.0 (12.0)

NEWS for Ruby 2.3.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...ding
* Encoding::IBM037 (alias ebcdic-cp-us; dummy) を追加

* Enumerable
* Enumerable#grep_v を追加
11049
* Enumerable#chunk_while
10769

* Enumerator::Lazy
* Enumerator::Lazy#grep_v を追加
11773

* File
* File.mkfifo
11536
* O_TMPFILE...
...エンコーディングであっても例外が発生しなくなりました。
11801

* Enumerable
* Enumerable#chunk と Enumerable#slice_before は初期状態を引数として受け取らなくなりました。
状態の管理にはローカル変数を使ってください...