るりまサーチ

最速Rubyリファレンスマニュアル検索!
19件ヒット [1-19件を表示] (0.021秒)
トップページ > ライブラリ:ビルトイン[x] > クエリ:==[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 (18139.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}" }
p c...
...5]
p a.chunk_while {|i, j| i <= j }.to_a
# => [[0, 9], [2, 2, 3], [2, 7], [5, 9], [5]]

# 隣り合う偶数同士、奇数同士の部分配列ごとに分ける。
# (Enumerable#chunk を使って実現する事も可能)
a = [7, 5, 9, 2, 0, 7, 9, 4, 2, 0]
p a.chunk_while {|i, j| i.even? == j.even...

Enumerator::Lazy (14.0)

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

...t_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オブジェクトは、Enumerable#lazyメソッ...
...
# 巨大な配列を確保しようとしてメモリを使い切ったりはしない
open("log.txt"){|f|
f.each_line.lazy.map{|line|
Hash[line.split(/\t/).map{|s| s.split(/:/, 2)}]
}.select{|hash|
hash["req"] =~ /GET/ && hash["status"] == "200"
}.each{|hash|
p hash
}
}
//}...
...lter_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オブジェクトは、Enumerable#lazyメソッ...
...lter_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オブジェクトは、Enumerable#lazy...