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
package com.wix.accord.examples | |
class Stateful(allowedNames: Set[String]) { | |
import com.wix.accord.dsl._ | |
import com.wix.accord._ | |
private implicit val classroomValidator = validator[Classroom] { c => | |
c.teacher.name is in(allowedNames) | |
c.students.map(_.name).each is in(allowedNames) |
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
import java.util.function.Supplier; | |
class A { | |
static int staticSupplier() { return 5; } | |
int instanceSupplier() { return 10; } | |
static void printOut(Supplier<Integer> supplier) { | |
System.out.println(supplier.get()); | |
} |
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
public class ClassWithLazyLogs implements LazyLogging { | |
public String getNormalizedName(Person person) { | |
info(() -> "getNormalizedName called"); | |
debug(() -> "Normalizing " + person.toString()); | |
String normalizedName = | |
person.getName().toUpperCase().trim(); | |
debug(() -> "Normalized name is: " + normalizedName); | |
return normalizedName; | |
} | |
} |
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
arilou:accord tomer$ scala | |
Welcome to Scala version 2.11.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_05). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> trait A { case object B } | |
defined trait A | |
scala> def m[T <: A](x: T): T#B = x.B | |
<console>:8: error: type B is not a member of type parameter T |
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
scala> val validPerson = Person( "Wernher", "von Braun" ) | |
validPerson: Person = Person(Wernher,von Braun) | |
scala> validate( validPerson ) | |
res0: com.wix.accord.Result = Success | |
scala> val invalidPerson = Person( "", "No First Name" ) | |
invalidPerson: Person = Person(,No First Name) | |
scala> validate( invalidPerson ) |
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
import com.wix.accord.dsl._ // Import the validator DSL | |
case class Person( firstName: String, lastName: String ) | |
case class Classroom( teacher: Person, students: Seq[ Person ] ) | |
implicit val personValidator = validator[ Person ] { p => | |
p.firstName is notEmpty // The expression being validated is resolved automatically, see below | |
p.lastName as "last name" is notEmpty // You can also explicitly describe the expression being validated | |
} |
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
package com.tomergabel | |
import scala.util.parsing.combinator.RegexParsers | |
import java.text.SimpleDateFormat | |
import java.util.Date | |
import scala.util.parsing.input.Reader | |
import java.io.{InputStreamReader, BufferedReader, FileInputStream} | |
object StatLogProcessor { | |
case class Commit( hash: String, author: String, timestamp: Date, message: String, locs: Map[ String, Int ] ) |
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
/* | |
Reproduction scenario for Scala 2.10 compiler issue. | |
To compile: scalac Test.scala | |
To execute: | |
wanamingo:tmp tomer$ scala com.tomergabel.examples.Test | |
java.lang.ClassFormatError: Duplicate method name&signature in class file com/tomergabel/examples/Derived$$anonfun$defect$1 | |
at java.lang.ClassLoader.defineClass1(Native Method) | |
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) |
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
package com.tomergabel.examples | |
import net.liftweb.json._ | |
import net.liftweb.json.JsonDSL._ | |
/** | |
* A chained object which provides JSON serialization/deserialization facilities for multiple enumerations. | |
* Intended as a workaround for the following issue: https://github.com/lift/framework/issues/1080 | |
* | |
* To use simply add to your formats: `implicit val formats = DefaultFormats + new ChainedEnumSerializer( enum1, enum2 )` |
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
package com.tomergabel.examples | |
import org.squeryl.PrimitiveTypeMode._ | |
import org.squeryl.{Session, SessionFactory, KeyedEntity, Schema} | |
import java.sql.Timestamp | |
/** | |
* Created by tomer on 7/2/12. | |
*/ |
NewerOlder