Categories: None [Edit]
deferred_enum
== Synopsys
Ruby Enumerable extension. Main idea is lazy computations within enumerators.
== Usage
Install as a gem:
sudo gem install deferred_enum
This gem introduces DeferredEnumerator class:
ary = [1, 2, 3, 4]
deferred = ary.defer # #
DeferredEnumerator brings some optimizations to all?, any? and none? predicates
deferred.all?(&:even?) # Will stop iteration after first false-result = 1 iteration
deferred.none?(&:even?) # 2 iterations
deferred.any?(&:even?) # 2 iterations
It also introduces lazy versions of Enumerable's #select, #map and #reject methods
deferred.map { |i| i + 1 } # #:each>
deferred.select { |i| i.even? } # #:each>
deferred.reject { |i| i.odd? } # #:each>
So you can safely chain your filters, they won't be treated as arrays:
deferred.map(&:succ).select(&:even?) # #:each>
You can build chains of Enumerables:
deferred.concat([2]).to_a # [1, 2, 3, 4, 2]
Or append elements to the end of enumerator:
deferred << 2
You can even remove duplicates from enumerator, though this operation can be tough:
deferred.uniq # #:each>
There are many other methods in DeferredEnumerator, please refer to documentation.
Total
Ranking: 89,872 of 183,139
Downloads: 8,543
Daily
Ranking: 66,923 of 183,127
Downloads: 0
Downloads Trends
Ranking Trends
Num of Versions Trends
Popular Versions (Major)
Popular Versions (Major.Minor)
Depended by
Rank | Downloads | Name |
---|
Depends on
Rank | Downloads | Name |
---|---|---|
25 | 818,346,165 | rspec |
Owners
# | Gravatar | Handle |
---|---|---|
1 | amikhailov |