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 scala.util.Try | |
/** | |
* Alternative to unsound construct: "sealed abstract case class" | |
* see https://gist.github.com/tpolecat/a5cb0dc9adeacc93f846835ed21c92d2 | |
* The solution below is the summary of the comments of the above gist. | |
* | |
* Works as is in Scala 2.12 and higher | |
* In Scala 2.11.12 you have to add -Xsource:2.12 | |
*/ |
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
/** | |
* A Red / Green Tree. | |
*/ | |
case class RedGreenTree { | |
} |
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 net.gutefrage.connector.transforms | |
import java.util | |
import org.apache.kafka.common.config.ConfigDef | |
import org.apache.kafka.connect.connector.ConnectRecord | |
import org.apache.kafka.connect.data.{Schema, SchemaBuilder, Struct} | |
import org.apache.kafka.connect.transforms.Transformation | |
import org.apache.kafka.connect.transforms.util.Requirements.{requireMap, requireStruct} | |
import org.apache.kafka.connect.transforms.util.SimpleConfig |
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 org.scalactic._ | |
import play.api.libs.json.{JsError, JsLookupResult, JsSuccess, Reads} | |
object RichJsLookupResult { | |
implicit class RichPlayJsonValidateToGoodOrBad(lookupResult: JsLookupResult) { | |
def parseAs[T](implicit rds: Reads[T]): T Or Every[String] = { | |
lookupResult.validate[T] match { | |
case s: JsSuccess[T] => Good(s.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
object CollectDemo { | |
val listOfTrys: List[Try[String]] = List(Success("apple"), Failure(new Exception("some failure")), Success("peach"), Success("strawberry")) | |
val listOfExistingFruits: List[String] = listOfTrys.collect { | |
case Success(name) => name | |
} | |
// prints out: List(apple, peach, strawberry) | |
println(listOfExistingFruits) | |
} |
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 class RichView[V <: android.view.View](view: V) { | |
def onClick[U](f: android.view.View => U): V = { | |
view.setOnClickListener(new android.view.View.OnClickListener { | |
def onClick(p: android.view.View): Unit = f(p) | |
}) | |
view | |
} | |
} |
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 User(id: Int, name: String, avatarUrl: Option[String]) | |
val kevin = User(1, "Kevin", None) | |
val jeremy = User(1, "Jeremy", Some("http://someurl.de")) | |
val users = Seq(kevin, jeremy) | |
users.forEach { // iterate over the user sequence | |
user => user match { // match every entry in the value 'user' | |
case User(name, Some(url)) => |
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 User { | |
private int id; | |
private String name; | |
public int getId() { | |
return id; | |
} | |
public String getName() { | |
return 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
case class User(id: Int, name: String) |
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
button.onClick(openUri("http://wikipedia.org")) |
NewerOlder