24件ヒット
[1-24件を表示]
(0.075秒)
別のキーワード
ライブラリ
- ビルトイン (24)
検索結果
-
Enumerable
# drop(n) -> Array (18239.0) -
Enumerable オブジェクトの先頭の n 要素を捨てて、 残りの要素を配列として返します。
...
Enumerable オブジェクトの先頭の n 要素を捨てて、
残りの要素を配列として返します。
@param n 捨てる要素数。
//emlist[例][ruby]{
e = [1, 2, 3, 4, 5, 0].each
e.drop(3) # => [4, 5, 0]
//}
@see Array#drop... -
Enumerable
# lazy -> Enumerator :: Lazy (132.0) -
自身を lazy な Enumerator に変換したものを返します。
...) ように再定義されています。
* map/collect
* flat_map/collect_concat
* select/find_all
* reject
* grep
* take, take_while
* drop, drop_while
* zip (※一貫性のため、ブロックを渡さないケースのみlazy)
* cycle (※一貫性のため、ブロックを渡さな......azy)
以下はピタゴラス数 (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......数を表示する
p pythagorean_triples.take(10).force # takeはlazyなので、forceが必要です
p pythagorean_triples.first(10) # firstはeagerです
# 100より小さいピタゴラス数を表示する
p pythagorean_triples.take_while { |*, z| z < 100 }.force
//}
@see Enumerator::Lazy...