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 OneWayImplicits { | |
//outside implicits visible, but T is not visible inside | |
case class Outwards[T](value: T) extends AnyVal | |
//outside implicits invisible, T is visible inside | |
case class Inwards[T](value: T) extends AnyVal | |
implicit def outwardsFromT[T](implicit t: T): Outwards[T] = Outwards(t) | |
implicit def tFromInwards[T](implicit inw: Inwards[T]): T = inw.value |
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 shapeless._ | |
def abc0[M[_]] = ??? | |
def abc1[M[+_]] = ??? | |
def abc2[M[-_]] = ??? | |
//this one should accept an arbitrary invariant M | |
def abc3[M[_] <: Set[_]] = ??? | |
type Predicate[-a] = a => Boolean |
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 Example { | |
case class Sample(age: Int) | |
def wrapsBlock(block1: Any) = ??? | |
def ifHasImplicit(block2: Any)(implicit request: String) = ??? | |
def sample(sampleObj: Sample) = wrapsBlock { | |
ifHasImplicit { | |
import sampleObj.age |
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 Sample { | |
public static void main(String[] args) { | |
new Dog().speak(10); //I am 10 | |
new Dog().speak("kek"); //I am kek wow | |
} | |
} | |
class Animal { | |
void speak(Object something){ |
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
//see original SO answer: https://stackoverflow.com/a/49184270/1927425 | |
import shapeless.ops.hlist._ | |
import shapeless.{::, _} | |
trait EmptyOf[T <: HList, AsList <: HList] { | |
def empty(): AsList | |
} | |
object EmptyOf { |
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
sealed trait GameCreationError extends Product with Serializable | |
object GameCreationError { | |
case class NameTooShort(min: Int) extends GameCreationError | |
case class NameTooLong(max: Int) extends GameCreationError | |
case class PlatformNotFound(platformSlug: String) extends GameCreationError | |
case class PlayersFromTooLow(min: Int) extends GameCreationError | |
case object PlayersToSmallerThanFrom extends GameCreationError | |
case object NameNotUnique extends GameCreationError | |
case object NoPlatformsSupplied extends GameCreationError |
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 io.circe.generic.JsonCodec | |
@JsonCodec(decodeOnly = true) | |
case class GameToCreate(name: String, platforms: List[String], players: Players) | |
@JsonCodec(decodeOnly = true) | |
case class Players(from: Int, to: Option[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
object map { | |
/** | |
* Allows a Map to become total forever. | |
* It's isomorphic to `Map.withDefaultValue`, but has a more specific return type, in particular: | |
* <ul> | |
* <li>it leaves out the information that the returned value is a Map</li> | |
* <li>it manifests that the returned value is a total function.</li> | |
* </ul> | |
* | |
* This is useful for a single reason - Maps by default aren't total functions, so `map.apply` can potentially |
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 time() = System.currentTimeMillis() | |
val t1 = time() | |
val x = calculateSomething(args) | |
val t2 = time() | |
println(t2 - t1) //print the time it took for `x` to be computed |
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 time(): Future[Long] = Future { System.currentTimeMillis() } | |
for { | |
t1 <- time() | |
x = calculateSomething(args) | |
t2 <- time() | |
} println(t2 - t1) |