mirror of
https://iceshrimp.dev/blueb/Chuckya-fe-standalone.git
synced 2026-01-13 22:43:15 -08:00
26 lines
545 B
Ruby
26 lines
545 B
Ruby
|
|
# frozen_string_literal: true
|
||
|
|
|
||
|
|
module Enumerable
|
||
|
|
# TODO: Remove this once stop to support Ruby 2.6
|
||
|
|
if RUBY_VERSION < '2.7.0'
|
||
|
|
def filter_map
|
||
|
|
if block_given?
|
||
|
|
result = []
|
||
|
|
each do |element|
|
||
|
|
res = yield element
|
||
|
|
result << res if res
|
||
|
|
end
|
||
|
|
result
|
||
|
|
else
|
||
|
|
Enumerator.new do |yielder|
|
||
|
|
result = []
|
||
|
|
each do |element|
|
||
|
|
res = yielder.yield element
|
||
|
|
result << res if res
|
||
|
|
end
|
||
|
|
result
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|