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
class TestClass { | |
def func(inFunc: => Unit) { | |
println("Before") | |
try { inFunc } | |
catch { case _ => } | |
println("After") | |
} | |
} |
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
object Program { | |
def main(args: Array[String]) { | |
val obj = new TestClass | |
obj func { println("inside") } | |
} | |
} |
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
object Program { | |
def main(args: Array[String]) { | |
val obj = new TestClass | |
obj func { println("inside"); return } | |
} | |
} |
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 isGreate0(list:List[Int]):Boolean = { | |
for (i <- list) | |
if (i <= 0) | |
return false | |
true | |
} |
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
trait Semigroup[A] { | |
def append(a1: A, a2: A): A | |
} | |
sealed abstract class Validation[F: Semigroup] { | |
final def and(other: Validation[F]) = (this, other) match { | |
case (Failure(e1), Failure(e2)) => Failure(implicitly[Semigroup[F]].append(e1, e2)) | |
case (Failure(e1), Success()) => Failure(e1) | |
case (Success(), Failure(e2)) => Failure(e2) | |
case (Success(), Success()) => Success |
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
implicit val listSemigroup = new Semigroup[List[String]] { | |
def append(a1: List[String], a2: List[String]): List[String] = { | |
a1 ::: a2 | |
} | |
} |
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
case class Weapon(name: String, ammo: Long) | |
case class Soldier(rank: Int, weapon: Weapon) | |
case class Lens[R, F](get: R => F, set: (R, F) => R) { | |
def compose[Q](g: Lens[Q, R]): Lens[Q, F] = | |
Lens(get = get compose g.get, | |
set = (q, f) => g set(q, set(g get q, f))) | |
} |
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 validateAmmo(ammo: => Long): Validation[List[String]] = { | |
if (ammo > 0) Success[List[String]]() | |
else Failure(List("Negative ammo")) | |
} | |
def validateName(name: => String): Validation[List[String]] = { | |
if (!name.isEmpty) Success[List[String]]() | |
else Failure(List("Empty Name")) | |
} |
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
val blaster = new Weapon("", -99) | |
val soldier = new Soldier(4, blaster) | |
val validationR = validateAmmo(soldierAmmoL.get(soldier)) and validateName(soldierWeaponName.get(soldier)) |
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
<dependency> | |
<groupId>org.codehaus.groovy</groupId> | |
<artifactId>groovy-all</artifactId> | |
<version>${groovy.version}</version> | |
</dependency> |
OlderNewer