The example for even numbers should be: even_numbers = [1, 2, 3, 4, 5].find_all { |element| element.even? } or even_numbers = [1, 2, 3, 4, 5].find_all(&:even?) instead of: even_numbers = [1, 2, 3, 4, 5].map { |element| element if element.even? }
If I'm writing ruby I'd prefer Array#select for this task.
Rust for Rubyists
11–20 of 45 posts
Re: Rust for Rubyists
#12Re: Rust for Rubyists
#13It's nice to see languages converging on a standard set of features. String interpolation, random number generation, package management, etc.
Or apparently the even more common functional list operations: “map”, “for_each”, “filter”, “every”, etc.
Re: Rust for Rubyists
#14Earlier quoted context omitted.
If I'm writing ruby I'd prefer Array#select for this task.
Exactly [1,2,3,4,5].select{|x| x%2 == 0} If I were interviewing a a Ruby dev, anything other than Array#select indicates lack of experience.
Re: Rust for Rubyists
#15Earlier quoted context omitted.
If I'm writing ruby I'd prefer Array#select for this task.
Exactly [1,2,3,4,5].select{|x| x%2 == 0} If I were interviewing a a Ruby dev, anything other than Array#select indicates lack of experience.
Re: Rust for Rubyists
#16Earlier quoted context omitted.
Or apparently the even more common functional list operations: “map”, “for_each”, “filter”, “every”, etc.
Well, unless your language is "go" in which case it converges on no good package management and no functional filter/map/reduce functions
Re: Rust for Rubyists
#17Or every language complicated enough is reinventing lisp partially.
Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.
Re: Rust for Rubyists
#18Docs: https://doc.rust-lang.org/std/result/enum.Result.html#method...
Re: Rust for Rubyists
#19In the section about converting a vector of strings into integers the article says that the Result returned from parse() is converted to a bool via Result::ok(). However, Result::ok() actually converts the Result into a Option which is what filter_map() expects.
Re: Rust for Rubyists
#20Or every language complicated enough is reinventing lisp partially.
For the uninitiated: Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.