Skip to content

Instantly share code, notes, and snippets.

def getSome(a: Int): Option[Int] = Some(a)
def getNone(a: Int): Option[Int] = None
def add(a: Int, b: Int): Int = a + b
val aOpt = getSome(1)
val bOpt = getSome(2)
package org.example.ktz.blog
import cats.syntax.all._
import cats.instances.future._
import org.scalatest._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import cats.data.Writer
def greetW(name: String, logged: Boolean): Writer[List[String], String] =
Writer(List("Compose a greeting"), {
val userName = if(logged) name else "User"
s"Hello $userName"
})
def isLoggedW(name: String): Writer[List[String], Boolean] =
Writer(List("Checking if user is logged in"), name.length == 3)
trait AuthService {
def isLogged(name: String): Boolean
}
class AuthServiceChar3 extends AuthService{
override def isLogged(name: String): Boolean = name.length == 3
}
class AuthServiceChar5 extends AuthService{
override def isLogged(name: String): Boolean = name.length == 5
class Person(val name: String, val age: Int, val weight: Int)
object Person {
def apply(name: String, age: Int, weight: Int): Person = new Person(name, age, weight)
def unapply(arg: Person): Option[(String, Int, Int)] =
if(arg.age >= 20) Some(arg.name, arg.age, arg.weight)
else None
}
type List[+A] = scala.collection.immutable.List[A]
val obj: Object = "Hello World!"
val listString: List[String] = List.empty
val listAny: List[Any] = listString
@knightpop
knightpop / Variance.java
Created July 12, 2017 17:41
Java Variance Test
package org.ktz.example.blog;
import java.util.ArrayList;
import java.util.List;
public class Variance {
public static void main(String[] args) {
String str = "";
Object obj = str;