Skip to content

Instantly share code, notes, and snippets.

View harmeetsingh0013's full-sized avatar

Harmeet Singh(Taara) harmeetsingh0013

View GitHub Profile
harmeet@harmeet-Vostro-3558:~/akka-samples/akka-cinammon$ sbt run
[info] Loading global plugins from /home/harmeet/.sbt/0.13/plugins
[info] Loading project definition from /home/harmeet/akka-samples/akka-cinammon/project
[info] Set current project to akka-cinammon (in build file:/home/harmeet/akka-samples/akka-cinammon/)
[warn] Multiple main classes detected. Run 'show discoveredMainClasses' to see the list
Multiple main classes detected, select one to run:
[1] com.harmeetsingh13.actors.HelloWorldActor
[2] com.harmeetsingh13.actors.HelloWorldPoolActor
All exercises are attempted on https://coderpad.io
val func = (a: Int) => a + 1
def funcd(a: Int) = a + 1
scala> val func = (a: Int) => a + 1
func: Int => Int = $$Lambda$1030/1250816994@3d98d138
scala> def funcd(a: Int) = a + 1
funcd: (a: Int)Int
scala> List(1, 2, 3, 4, 5).map(func)
res0: List[Int] = List(2, 3, 4, 5, 6)
scala> List(1, 2, 3, 4, 5).map(funcd)
res1: List[Int] = List(2, 3, 4, 5, 6)
scala> val inc = funcd
<console>:12: error: missing argument list for method funcd
Unapplied methods are only converted to functions when a function type is expected.
You can make this conversion explicit by writing `funcd _` or `funcd(_)` instead of `funcd`.
val inc = funcd
^
scala> val inc = funcd _
inc: Int => Int = $$Lambda$1043/1332208607@56681eaf
object Test extends App {
val func = (a: Int) => a + 1
def funcd(a: Int) = a + 1
val inc = funcd _
List(1, 2, 3, 4, 5).map(func)
List(1, 2, 3, 4, 5).map(funcd)
}
/*
Translation 2:
def funcd(a: Int): Int = a.+(1);
private[this] val inc: Int => Int = {
((a: Int) => Test.this.funcd(a))
};
scala.collection.immutable.List.apply[Int](1, 2, 3, 4, 5).map[Int, List[Int]](Test.this.func)(immutable.this.List.canBuildFrom[Int]);
scala.collection.immutable.List.apply[Int](1, 2, 3, 4, 5).map[Int, List[Int]]({
def method1(arg: Int): String = {
s"The method1 passed value is $arg"
}
def method2(arg1: Int, arg2: Int): String = {
s"The method2 passed value sum is ${arg1 + arg2}"
}
def method3(arg1: Int, arg2: Int, arg3: Int): String = {
s"The method3 passed value sum is ${arg1 + arg2 + arg3}"