Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

mame/enumerabler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

1 Commit

Repository files navigation

= enumerabler
* http://github.com/mame/enumerabler/tree/master
== DESCRIPTION:
enumerabler enhances Enumerable with methods returning enumerator.
== FEATURES/PROBLEMS:
- Enumerable#grepper
- Enumerable#finder_all (alias: all_finder, selector)
- Enumerable#rejecter
- Enumerable#collector (alias: mapper)
- Enumerable#flat_mapper (alias: concat_collector)
- Enumerable#zipper
- Enumerable#taker
- Enumerable#taker_while
- Enumerable#dropper
- Enumerable#dropper_while
== SYNOPSIS:
 require "enumerabler"
 # `select' and `selector' have the almost same behavior.
 ary.select {|x| x.even? }.take(10)
 ary.selector {|x| x.even? }.take(10)
 # While `select' returns an array, `selector' returns an Enumerator
 # corresponding the array. So, the latter requires no intermediate
 # array, which makes the latter more effective than the former.
 # Sieve of Eratosthenes
 def sieve(e, &blk)
 yield n = e.first
 sieve(e.rejecter {|x| x % n == 0 }, &blk)
 end
 sieve(2..(1.0/0.0)) {|x| p x } #=> 2, 3, 5, 7, 11, 13, 17, 19, 23, ...
 # Fibonacci numbers
 def fibonacci
 Enumerator.new do |e|
 e << 1
 e << 1
 fibonacci.zip(fibonacci.dropper(1)) {|x, y| e << x + y }
 end
 end
 fibonacci.each {|x| p x } #=> 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
== REQUIREMENTS:
None
== INSTALL:
* gem install enumerabler
== LICENSE:
Copyright:: Yusuke Endoh <mame@tsg.ne.jp>
License:: Ruby's

About

enumerabler enhances Enumerable with methods returning enumerator.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /