My Secret Life as a Spaghetti Coder
home | about | contact | privacy statement
With a name like each_cons, I thought you were going to iterate through all the permutations of how I could construct a list you operated upon. For example, I thought

[1,2,3,4].each_cons do |x| # I did not notice the required argument
  puts x.inspect
end
 

would output:

[[1,2,3,4], []]
[[1,2,3], [4]]
[[1,2], [3,4]]
[[1], [2,3,4]]
[[], [1,2,3,4]]

So when I needed to find the local maxima in an image projection to algorithmically find the staves in sheet music, I found myself wanting a C-style for loop.

I didn't know you'd provide me with a wonderful sliding window!

[1,2,3,4].each_cons(2) do |x|
  puts x.inspect
end

[1, 2]
[2, 3]
[3, 4]

From now on, I'll turn to you when I need that functionality. Thanks for waiting on me, each_cons. Not everyone would be as patient as you.

Warm Regards,
Sam

PS: In case you're interested, the "cons" in "each_cons" is short for "consecutive," not "construct," as Matz informed me:

Matz says 'I am not the one who come up with the name, but I suppose cons is the short form of consecutive.'

Hey! Why don't you make your life easier and subscribe to the full post or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!


Comments
Leave a comment

There are no comments for this entry yet.

Leave a comment

Leave this field empty
Your Name
Email (not displayed, more info?)
Website

Comment:

Subcribe to this comment thread
Remember my details
Google
Web CodeOdor.com

Me
Picture of me

Topics
.NET (18)
AI/Machine Learning (13)
Answers To 100 Interview Questions (10)
Bioinformatics (1)
C and C++ (6)
cfrails (22)
ColdFusion (78)
Customer Relations (15)
Databases (3)
DRY (18)
DSLs (11)
Future Tech (5)
Games (4)
Groovy/Grails (8)
Hardware (1)
IDEs (9)
Java (38)
JavaScript (3)
Linux (2)
Lisp (1)
Mac OS (3)
Management (14)
MediaServerX (1)
Miscellany (69)
OOAD (36)
Productivity (9)
Programming (150)
Programming Quotables (6)
Rails (28)
Ruby (61)
Save Your Job (41)
scriptaGulous (4)
Software Development Process (22)
TDD (40)
TDDing xorblog (6)
Tools (5)
Web Development (7)
Windows (1)
With (1)
YAGNI (10)

Resources
Agile Manifesto & Principles
Principles Of OOD
ColdFusion
CFUnit
Ruby
Ruby on Rails
JUnit



RSS 2.0: Full Post | Short Blurb
Subscribe by email:

Delivered by FeedBurner