Skip to content

Instantly share code, notes, and snippets.

View debasishg's full-sized avatar
🏠
Working from home

Debasish Ghosh debasishg

🏠
Working from home
View GitHub Profile
@debasishg
debasishg / gist:5567328
Created May 13, 2013 10:08
regex interpolation fails ..
Apples-MacBook-Pro:~ debasishg$ scala
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :paste
// Entering paste mode (ctrl-D to finish)
implicit class RContext(sc: StringContext) {
def r =
mapReduce :: (k1 -> v1 -> [(k2, v2)]) -- The Map function
-> (k2 -> [v2] -> Maybe v3) -- The Reduce function
-> Map k1 v1 -- a key to input - value mapping
-> Map k2 v3 -- a key to output - value mapping
mapReduce :: (k1 -> v1 -> [(k2, v2)]) -- The Map function
-> (k2 -> [v2] -> [v2]) -- The Reduce function
-> [(k1, v1)] -- a set of input key/value pairs
-> [(k2, v2)] -- a set of output key/value pairs
[error] /Users/debasishg/.../mapreduce/src/main/scala/com/eligotech/hnavigator/jobmanager/mapreduce/mr/RowProcess.scala:48: type mismatch;
[error] found : A1(in method applyOrElse)(in method applyOrElse)(in method applyOrElse)(in method applyOrElse)(in method applyOrElse)(in method applyOrElse)(in method applyOrElse)(in method applyOrElse) => Boolean
[error] required: A1(in method applyOrElse)(in method applyOrElse)(in method applyOrElse)(in method applyOrElse)(in method applyOrElse)(in method applyOrElse)(in method applyOrElse)(in method applyOrElse) => Boolean
[error] } filter {tfstat =>
@debasishg
debasishg / gist:5222566
Created March 22, 2013 16:12
The timeout exception is trapped by the Failure clause of Try.
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_43).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.util.Try
import scala.util.Try
scala> import scala.util.{Success, Failure}
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_43).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scalaz._
import scalaz._
scala> import Scalaz._
scala> :paste
// Entering paste mode (ctrl-D to finish)
val doOne = (user: String) => List("one" + "*" + user)
val doTwo = (user: String) => List("two" + "*" + user)
val doThree = (user: String) => List("three" + "*" + user)
def collectAll(funs: List[String => List[String]])(user: String): List[String] =
(List[String]() /: funs)((a, b) => a ::: b(user))
14:26 ~/Projects/210x (2.10.x)$ scala
Welcome to Scala version 2.10.1-20130204-105326-3d318be51f (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37).
Type in expressions to have them evaluated.
Type :help for more information.
scala> case class Shop(store: String, item: String, cost: Int) { def this() = this(null, null, 0) }
defined class Shop
scala> val t = typeOf[Shop]
t: reflect.runtime.universe.Type = Shop
import scala.reflect.runtime.universe._
import scala.reflect.api.{TypeCreator, Universe}
object Test extends App {
def foo[T: TypeTag] = TypeTag(typeTag[T].mirror, new TypeCreator {
override def apply[U <: Universe with Singleton](m: scala.reflect.api.Mirror[U]): U # Type = {
typeTag[T].in(m).tpe match {
case TypeRef(_, _, argHead :: Nil) => argHead.asInstanceOf[U#Type]
}
}
@debasishg
debasishg / gist:4713638
Created February 5, 2013 10:39
Trying to invoke the no-arg constructor - stuck at the last step ..
scala> case class Shop(store: String, item: String, cost: Int) {
| def this() = this(null, null, 0)
| }
defined class Shop
scala> val t = typeOf[Shop]
t: reflect.runtime.universe.Type = Shop
scala> val m = runtimeMirror(getClass.getClassLoader)
m: reflect.runtime.universe.Mirror = JavaMirror with scala.tools.nsc.interpreter