summaryrefslogtreecommitdiff
path: root/spec/ruby/core/enumerator/lazy/filter_map_spec.rb
blob: 3480af0865f352fd7ffdad6e30329640f01d89dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# -*- encoding: us-ascii -*-

require_relative '../../../spec_helper'
require_relative 'fixtures/classes'

ruby_version_is "2.7" do
  describe "Enumerator::Lazy#filter_map" do
    it "maps only truthy results" do
      (1..Float::INFINITY).lazy.filter_map { |i| i if i.odd? }.first(4).should == [1, 3, 5, 7]
    end

    it "does not map false results" do
      (1..Float::INFINITY).lazy.filter_map { |i| i.odd? ? i : false }.first(4).should == [1, 3, 5, 7]
    end
  end
end