Last active
August 29, 2015 14:15
-
-
Save kamiyaowl/a510f1d929df340a6dc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fizz (x:Int) : (Int, Boolean) = x match { case _ if x % 3 == 0 => (x,true) ; case _ => (x,false) } | |
def buzz (x:((Int, Boolean))) : (Int, Boolean, Boolean) = x._1 match { case n if n % 5 == 0 => (x._1, x._2,true) ; case _ => (x._1,x._2,false) } | |
def fizzbuzz(x:((Int,Boolean,Boolean))) : String = x match { | |
case (_, true, true) => "FizzBuzz" | |
case (_, true, false) => "Fizz" | |
case (_, false, true) => "Buzz" | |
case (n,_,_) => n.toString | |
} | |
implicit class FizzBuzz[A](self:A) { | |
def fizz(x:Any) = self | |
def buzz(x:Any) = self | |
def _2(x:Int => (Int, Boolean))(implicit ev: A <:< Int) = 1 to 100 map(x) | |
def _4(x:((Int,Boolean)) => (Int,Boolean, Boolean))(implicit ev: A <:< Seq[(Int,Boolean)]) = self.map(x) | |
def _8(x:Any) = self | |
def _14(x:((Int,Boolean,Boolean)) => String)(implicit ev: A <:< Seq[(Int, Boolean, Boolean)]) = self.map(x) | |
} | |
println(1 _2 fizz _4 buzz fizz 7 _8 "fizz" buzz 11 fizz 13 _14 fizzbuzz) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vector(1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz, 94, Buzz, Fizz, 97, 98, Fizz, Buzz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment