Skip to content

Instantly share code, notes, and snippets.

View sofoklis's full-sized avatar

Sofoklis Papasofokli sofoklis

View GitHub Profile
@sofoklis
sofoklis / simple option.scala
Created January 17, 2013 14:19
simple option
val n = None //> n : None.type = None
val s = Some(1) //> s : Some[Int] = Some(1)
val o = Option(3) //> o : Option[Int] = Some(3)
o match {
case Some(x) => println("Count to :" + x)
case None => println("Dont count")
} //> Count to :3
val s2 = Some(null) //> s2 : Some[Null] = Some(null)
@sofoklis
sofoklis / contravariantType.scala
Created January 16, 2013 20:56
contravariant definition
class ContravariantType[-T] {
// some functions and fields
}
@sofoklis
sofoklis / contravariantExample.scala
Created January 16, 2013 20:55
contravarian example
val contravariantType1: ContravariantType[String] = new ContravariantType[String] // Allowed
val contravariantType2: ContravariantType[Any] = new ContravariantType[String] // Compile error
val contravariantType3: ContravariantType[String] = new ContravariantType[Any] // Allowed
@sofoklis
sofoklis / covariantExample.scala
Created January 16, 2013 20:17
Covariant example
val covariantType1: CovariantType[String] = new CovariantType[String] // Allowed
val covariantType2: CovariantType[Any] = new CovariantType[String] // Allowed
val covariantType3: CovariantType[String] = new CovariantType[Any] // Compile error
@sofoklis
sofoklis / CovariantType.scala
Created January 16, 2013 20:16
CovariantType
class CovariantType[+T] {
// some functions and fields
}
@sofoklis
sofoklis / NonVariantType.scala
Created January 16, 2013 20:08
NonVariantType.scala
val string: Any = "sofoklis" // String is a proper subtype of any
val nonVariantType1: NonVariantType[String] = new NonVariantType[String] // Allowed
val nonVariantType2: NonVariantType[Any] = new NonVariantType[String] // Compile error
val nonVariantType3: NonVariantType[String] = new NonVariantType[Any] // Compile error
@sofoklis
sofoklis / GenericType.scala
Last active December 11, 2015 05:08
generic type
class NonVariantType[T]
{
// some functions and fields
}
package org.example
import scala.concurrent.{ Future, Promise, future, promise }
import scala.concurrent.ExecutionContext.Implicits.global
class FuturesAndPromises
object FuturesAndPromises {
def main(args: Array[String]) {
futureSample
@sofoklis
sofoklis / gist:3483573
Created August 26, 2012 21:01
b_not_factor part 2
(x ⇒ x match { case Some(v) ~ f ⇒ !f; case None ~ f ⇒ f })
@sofoklis
sofoklis / gist:3483572
Created August 26, 2012 21:00
b_not_factor part 1
opt("not") ~ b_factor