trying
A poor man's pipes
% echo "gem 'trying'" | Gemfile
% gem install trying
Usage
String.include(Trying)
Range.include(Trying)
stream = (0..10).trying do
to_a
lazy
map { |x| x ** 2 }
first(10)
end
truth = "Foobar".trying do
chars
map(&:upcase)
map(&:ord)
reduce(0, :+)
with { |n| n * Math::PI }
tap { |n| puts n }
with { |n| fail if n > 1380 }
failed? { :recover }
failed?(StandardError) { :nope }
eql?(:recover)
nil?
to_s
length
with { |n| (n..n + 20) }
to_a
lazy
collect { |x| x ** 2 }
first(5)
reduce(1, &:*)
public_send(:/, 5443200)
end