Functional programming for a Rubyist
Command-line programs
source 'https://rubygems.org' | |
gem 'activerecord', '~>4.0' | |
gem 'sqlite3' |
Loading development environment (Rails 3.2.19) | |
irb(main):001:0> Time.zone | |
=> #<ActiveSupport::TimeZone:0x007fa2e4533d68 @name="Osaka", @utc_offset=nil, @tzinfo=#<TZInfo::TimezoneProxy: Asia/Tokyo>, @current_period=nil> | |
irb(main):002:0> p = Plan.new | |
=> #<Plan id: nil, decided_on: nil> | |
irb(main):003:0> time = 1.day.ago | |
=> Fri, 26 Sep 2014 06:31:54 JST +09:00 | |
irb(main):004:0> time.to_date | |
### | |
=> Fri, 26 Sep 2014 |
require 'parslet' | |
class FooParser < Parslet::Parser | |
rule(:space) { match('\s').repeat(1) } | |
rule(:space?) { space.maybe } | |
rule(:dot) { str('.') >> space? } | |
rule(:colon) { str(':') >> space? } | |
rule(:comma) { str(',') >> space? } | |
rule(:comma?) { comma.maybe } |
def qsort(list) | |
return list if list.empty? | |
x, *xs = list | |
smaller, larger = xs.partition { |n| n < x } | |
qsort(smaller) + [x] + qsort(larger) | |
end | |
describe 'qsort' do |
I have been programming for about 10 years. 3 of those years I have been writing Ruby. Recently I have developed a deep interest in good software design, appropriate levels of testing, and other programming paradigms.
I am a consultant and (Ruby) instructor at Big Nerd Ranch. I am one of a handful of nerds that who works remotely full-time. I love working remotely, but it is not without its challenges! My wife
I'm not a huge fan of resumes, but alas I do, in fact, do (and have done) things in case you're interested. Find me at http://iamvery.com.
--color | |
-r turnip/rspec |
extension Array { | |
func deduce (initial: T? = nil, _ combine: (T, T) -> T) -> T? { | |
if let initial = initial { | |
return reduce(initial, combine: combine); | |
} | |
if count > 1 { | |
var rest = self[1..<count] | |
return rest.reduce(first!, combine: combine) | |
} else { |