- TalkBack 1 of 1:
- Thread View
- Flat View
- An alternative implementation
-
David,
I really like your code. I've got an alternative implementation that demonstrates a slightly different take on Scala:
def interpret(in: String, f: String => Unit) {
def sing(n: Int): List[String] = {
def bb(in: Int) = in match {
case 1 => "1 bottle of beer"
case x => ""+x+" bottles of beer"
}
if (n == 0) Nil
else {
f(bb(n)+" on the wall.")
f(bb(n)+".")
f("Take one down, pass it around,")
f(bb(n - 1)+" on the wall.")
sing(n - 1)
}
}
in.map(Character.toUpperCase).
foldLeft(0) {
case (x, 'H') => f("Hello World") ; x
case (x, 'Q') => f(in) ; x
case (x, '9') => sing(99) ; x
case (x, '+') => x + 1
case (x, _) => x
}
}
interpret(argv(0), println)
I hope the readers like to see the flexibility and different styles in Scala code.
Thanks,
David - Posted by: feeder_of_the_bears Posted on: 12/08/08 You are currently: a Guest | Members login | Terms of Use
|
|
What do you think?
SponsoredWhite Papers, Webcasts, and Downloads
- Using NIC Teaming to Achieve High Availability on Linux Platforms Dell Network interface card (NIC) teaming is one method for providing high ... Download Now
- Reducing Server Total Cost of Ownership with VMware Virtualization Software VMware VMware virtualization enables customers to reduce their server TCO and ... Download Now
- The True Costs of Virtual Server Solutions VMware In an economic environment that is repeatedly heralding the message "do ... Download Now
Premier Vendor Content Whitepapers, webcasts & resources from our Power Center Sponsors
- Learn more about tools to grow your business
-
The Business Essentials Guide provides you useful tools and templates to help grow your business and save you time with automated shipping solutions.
- Save time with the UPS Business Essentials Guide
- Keep Up With The Latest In Document Management with The DocuMentor.
-
Doc delivers the scoop on today's enterprise content management, printer maintenance, and all other issues related to document management. It's the DocuMentor Blog.
- Learn more >>
- New Online Dashboard for IT Leaders
-
Read about top issues IT decision-makers face every day, plus get cost-effective solutions to real-life IT problems.
- Learn more >>
- The more you simplify, the more you save
-
When you transition from your existing Red Hat environment to SUSE Linux Enterprise from Novell, you can recognize dramatic cost savings, perhaps as much 50%
- Learn more >>
- Microsoft Dynamics CRM Online - Free Six-Month Trial for Eligible Organizations
-
Microsoft Dynamics CRM Online provides fast online access, simple contact management and better sales performance for a low monthly cost - the best value on the market today.

- Learn more about the free, six-month trial offer>>
SmartPlanet
- Thought-provoking progressive ideas on diverse topics that intersect with technology, business, and life, and matter to the world at large. Visit SmartPlanet
- More from IBM
- How to Drive Better Business Outcomes with Exceptional Web Experiences Download the eBook
- Driving Business Agility through SOA Connectivity & Integration Read the White Paper from IBM
- Linking Decisions and Information for Organizational Performance Read the Tom Davenport study





