るりまサーチ

最速Rubyリファレンスマニュアル検索!
21件ヒット [1-21件を表示] (0.039秒)
トップページ > ライブラリ:ビルトイン[x] > クエリ:map[x] > クエリ:Lazy[x] > クエリ:filter_map[x]

別のキーワード

  1. matrix map
  2. _builtin map
  3. matrix map!
  4. _builtin flat_map
  5. array map

検索結果

Enumerator::Lazy#filter_map {|item| ... } -> Enumerator::Lazy (27425.0)

Enumerable#filter_map と同じですが、配列ではなく Enumerator::Lazy を返します。

...erable#filter_map と同じですが、配列ではなく Enumerator::Lazy を返します。

@raise ArgumentError ブロックを指定しなかった場合に発生します。

//emlist[例][ruby]{
1.step.lazy.filter_map { |n| n * 2 if n.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: (1.st...
...ep)>:filter_map>

1.step.lazy.filter_map { |n| n * 2 if n.even? }.take(10).force
# => [4, 8, 12, 16, 20, 24, 28, 32, 36, 40]
//}

@see Enumerable#filter_map...

Enumerator::Lazy (18108.0)

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

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

動作は通常の Enumerator と同じですが、以下のメソッドが遅延評価を行う
(つまり、配列ではなく Enumerator を返す) ように再定義されています。

* map/collect...
...* flat_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
オブジェクト...
...Enumerable#lazyメソッドによって生成されます。

Lazy
から値を取り出すには、Enumerator::Lazy#force または
Enumerable#first を呼びます。

//emlist[例][ruby]{
# 二乗して偶数になるような整数を、小さい方から5個表示する
p 1.step.lazy.select{|n|...
...* flat_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
オブ...

Enumerator::Lazy.new(obj, size=nil) {|yielder, *values| ... } -> Enumerator::Lazy (3207.0)

Lazy Enumerator を作成します。Enumerator::Lazy#force メソッドなどに よって列挙が実行されたとき、objのeachメソッドが実行され、値が一つずつ ブロックに渡されます。ブロックは、yielder を使って最終的に yield される値を 指定できます。

...
Lazy
Enumerator を作成します。Enumerator::Lazy#force メソッドなどに
よって列挙が実行されたとき、objのeachメソッドが実行され、値が一つずつ
ブロックに渡されます。ブロックは、yielder を使って最終的に yield される値を
指定で...
...きます。

//emlist[Enumerable#filter_map と、その遅延評価版を定義する例][ruby]{
module Enumerable
def filter_map(&block)
map
(&block).compact
end
end

class Enumerator::Lazy
def filter_map
Lazy
.new(self) do |yielder, *values|
result = yield *values
yielder...
...<< result if result
end
end
end

1.step.lazy.filter_map{|i| i*i if i.even?}.first(5)
# => [4, 16, 36, 64, 100]
//}

@raise ArgumentError 引数を指定しなかった場合、ブロックを指定しなかった場合に発生します。

@see Enumerator.new...