Skip to content

Instantly share code, notes, and snippets.

import PersonBuilder._
import shapeless._
case class Person(name: String, age: Int)
object PersonBuilder {
def apply() = new PersonBuilder[Start](Person("", 0))
trait Start
public class PersonBuilder {
public PersonBuilder() {
}
public StepAge name(String name) {
return new StepAge(new Person(name, -1));
}
public class StepAge {
public class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
object PlayJsonWritesDerivation {
type Typeclass[T] = Writes[T]
def combine[T](ctx: CaseClass[Writes, T]): Writes[T] =
new Writes[T] {
override def writes(o: T): JsValue =
JsObject(ctx.parameters.map {
param =>
(param.label, param.typeclass.writes(param.dereference(o)))
})
@xplosunn
xplosunn / MultiMonadFor.scala
Created August 20, 2017 15:27
An experiment where I created a for comprehension where I say the final monad and then compose different monads and return the intended one through implicit conversions.
import scala.concurrent.Future
import scala.util.Try
import For.typeMaps._
import For.typeUnits._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.Duration
import scala.concurrent.Await
import scala.language.implicitConversions