Skip to content

Instantly share code, notes, and snippets.

@rajish
Created May 4, 2012 14:02
Show Gist options
  • Save rajish/2594972 to your computer and use it in GitHub Desktop.
Save rajish/2594972 to your computer and use it in GitHub Desktop.
y is 6 afraid of 7
// A scala exercise based on the http://thedet.wordpress.com/2012/04/25/y-is-6-afraidof-7/ blog entry
// The goal is to remove the parenthesis
case class Fears(value:Int) {
var s: String = "... Wait! %d has no fears!".format(value)
def afraid(f: Fears) = {
if (value == 6)
f.s = s + f.s
else
f.s = s
f
}
def of(n: Int = value) = n match {
case 7 => " " + (7 to 9).toList.map(_.toString).reduce(_+" "+_)
case _ => "... Wait! There's nothing to fear!"
}
def afraid_of(f: Fears) = {
f.s = of(f.value)
afraid(f)
}
override def toString() = s
}
def of(f: Fears) = {
f.s = f.of()
f
}
implicit def numbersFears(n: Int) = new Fears(n)
object Y {
def is(f: Fears) = {
f.s = f.value match {
case 6 => "because"
case _ => "wrong question"
}
f
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment