るりまサーチ

最速Rubyリファレンスマニュアル検索!
356件ヒット [1-100件を表示] (0.143秒)

別のキーワード

  1. fiddle ruby_free
  2. rbconfig ruby
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

Enumerable#lazy -> Enumerator::Lazy (18367.0)

自身を lazy な Enumerator に変換したものを返します。

... lazy な Enumerator に変換したものを返します。

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

* map/collect
* flat_map/collect_concat
* select/find_all
* reject
*...
...grep
* take, take_while
* drop, drop_while
* zip (※一貫性のため、ブロックを渡さないケースのみlazy)
* cycle (※一貫性のため、ブロックを渡さないケースのみlazy)

以下はピタゴラス数 (a**2 + b**2 = c**2 を満たす自然数 a, b, c の組) を...
...emlist[例][ruby]{
def pythagorean_triples
(1..Float::INFINITY).lazy.flat_map {|z|
(1..z).flat_map {|x|
(x..z).select {|y|
x**2 + y**2 == z**2
}.map {|y|
[x, y, z]
}
}
}
end
# 最初の10個のピタゴラス数を表示する
p pythagorean_triples.take(...

Enumerator::Lazy#filter {|item| ... } -> Enumerator::Lazy (9368.0)

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

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

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

//emlist[例][ruby]{
1.step.lazy.find_all { |i| i.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:fi...
...nd_all>

1.step.lazy.select { |i| i.even? }.take(10).force
# => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
//}

@
see Enumerable#select...

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

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

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

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

//emlist[例][ruby]{
1.step.lazy.filter_map { |n| n * 2 if n.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: (1.step)>:filt...
...er_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#slice_after(pattern) -> Enumerator::Lazy (9355.0)

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

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

//emlist[例][ruby]{
1.step.lazy.slice_after { |e| e % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x007fd73980e6f8>:each>>

1.step.lazy.slice_after { |e| e % 3 == 0 }.take(5).forc...
...e
# => [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]
//}

@
see Enumerable#slice_after...

Enumerator::Lazy#collect_concat {|item| ... } -> Enumerator::Lazy (9279.0)

ブロックの実行結果をひとつに繋げたものに対してイテレートするような Enumerator::Lazy のインスタンスを返します。

...erator::Lazy のインスタンスを返します。

//emlist[][ruby]{
["foo", "bar"].lazy.flat_map {|i| i.each_char.lazy}.force
#=> ["f", "o", "o", "b", "a", "r"]
//}

ブロックの返した値 x は、以下の場合にのみ分解され、連結されます。

* x が配列であるか、to_...
...merator::Lazy) とき

それ以外のときは、x は分解されず、そのままの値として使われます。

//emlist[][ruby]{
[{a:1}, {b:2}].lazy.flat_map {|i| i}.force
#=> [{:a=>1}, {:b=>2}]
//}

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

@
see...
...Enumerable#flat_map...

絞り込み条件を変える

Enumerator::Lazy#flat_map {|item| ... } -> Enumerator::Lazy (9279.0)

ブロックの実行結果をひとつに繋げたものに対してイテレートするような Enumerator::Lazy のインスタンスを返します。

...erator::Lazy のインスタンスを返します。

//emlist[][ruby]{
["foo", "bar"].lazy.flat_map {|i| i.each_char.lazy}.force
#=> ["f", "o", "o", "b", "a", "r"]
//}

ブロックの返した値 x は、以下の場合にのみ分解され、連結されます。

* x が配列であるか、to_...
...merator::Lazy) とき

それ以外のときは、x は分解されず、そのままの値として使われます。

//emlist[][ruby]{
[{a:1}, {b:2}].lazy.flat_map {|i| i}.force
#=> [{:a=>1}, {:b=>2}]
//}

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

@
see...
...Enumerable#flat_map...

Enumerator::Lazy#take(n) -> Enumerator::Lazy (9272.0)

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

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

n が大きな数 (100000とか) の場合に備えて再定義されています。
配列が必要な場合は Enumerable#first を使って下さい。

@
param n 要素数を指定します。

@
raise ArgumentErr...
...or n に負の数を指定した場合に発生します。

//emlist[例][ruby]{
1.step.lazy.take(5)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:take(5)>

1.step.lazy.take(5).force
# => [1, 2, 3, 4, 5]
//}

@
see Enumerable#take...

Enumerator::Lazy#select {|item| ... } -> Enumerator::Lazy (9268.0)

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

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

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

//emlist[例][ruby]{
1.step.lazy.find_all { |i| i.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:fi...
...nd_all>

1.step.lazy.select { |i| i.even? }.take(10).force
# => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
//}

@
see Enumerable#select...

Enumerator::Lazy#collect {|item| ... } -> Enumerator::Lazy (9267.0)

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

...くEnumerator::Lazy を返します。

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

//emlist[例][ruby]{
1.step.lazy.map{ |n| n % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:map>

1.step.lazy.collect{ |n| n.succ }.take(10).fo...
...rce
# => [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
//}

@
see Enumerable#map...

Enumerator::Lazy#select {|item| ... } -> Enumerator::Lazy (9267.0)

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

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

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

//emlist[例][ruby]{
1.step.lazy.find_all { |i| i.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:fi...
...nd_all>

1.step.lazy.select { |i| i.even? }.take(10).force
# => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
//}

@
see Enumerable#select...

絞り込み条件を変える

Enumerator::Lazy#take_while -> Enumerator::Lazy (9267.0)

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

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

//emlist[例][ruby]{
1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:zip(#<Enumerator: "a".....
..."z":cycle>)>:take_while>

1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }.force.last(5)
# => [[99995, "y"], [99996, "z"], [99997, "a"], [99998, "b"], [99999, "c"]]
//}

@
see Enumerable#take_while...
<< 1 2 3 ... > >>