Skip to content

Instantly share code, notes, and snippets.

@wheaties
wheaties / merge.scala
Last active February 22, 2016 14:09
Single level merge
trait Merge[LSet, RSet]{
type Out
}
object Merge extends LowPriorityMerge{
implicit def left[L, R]: Aux[L, L|R, L|R] = new Merge[L, L|R]{ type Out = L|R }
implicit def right[L, R]: Aux[R, L|R, L|R] = new Merge[R, L|R]{ type Out = L|R }
}
@wheaties
wheaties / merge.scala
Last active February 22, 2016 14:09
Unique merges
trait Merge[LSet, RSet]{
type Out
}
object Merge extends LowPriorityMerge{
implicit def left[L, R]: Aux[L, L|R, L|R] = new Merge[L, L|R]{ type Out = L|R }
implicit def right[L, R]: Aux[R, L|R, L|R] = new Merge[R, L|R]{ type Out = L|R }
}
class Contains[Items]{
def apply[Obj](obj: Obj)(implicit oneOf: OneOf[Obj, Items]) = obj
}
val isd = new Contains[Int|String|Double]
//success test cases
isd(1)
isd(2.0)
isd("hello")
@wheaties
wheaties / OneOf.scala
Created February 18, 2016 02:24
Inheritance
trait OneOf[Obj, Items]
object OneOf extends LowPriorityOneOf{
implicit def left[L, R, Obj <: L] = new OneOf[Obj, L | R]
}
protected trait LowPriorityOneOf{
implicit def right[L, R, Obj <: R] = new OneOf[Obj, L | R]
}
trait OneOf[Obj, Items]
object OneOf extends LowPriorityOneOf{
implicit left[L, R] = new OneOf[L, L | R]{}
}
trait LowPriorityOneOf{
implicit right[L, R] = new OneOf[R, L | R]{}
}
@wheaties
wheaties / OneOf.scala
Last active February 18, 2016 13:53
First OneOf
trait OneOf[Obj, Items]
class Prove[Items]{
def check[Obj](obj: Obj)(implicit proof: OneOf[Obj, Items]) = obj
}
type |[A, B] = (A, B)
@wheaties
wheaties / OneOfProof.scala
Created February 16, 2016 16:05
Add type level boolean to OneOf
trait OneOfProof[Obj, Types] {
type Cond <: Bool
}
object OneOfProof extends OneOfProof1{
implicit def left[Obj, R]: Aux[Obj, Obj | R, True] = new OneOfProof[Obj, Obj | R] { type Cond = True }
}
trait OneOfProof1 extends OneOfProof2{
implicit def right[Obj, L]: Aux[Obj, L | Obj, True] = new OneOfProof[Obj, L | Obj] { type Cond = True }
@wheaties
wheaties / OneOf.scala
Last active July 31, 2018 20:55
Type Level OneOf
trait OneOf[Obj, Items]
object OneOf extends LowPriorityOneOf{
implicit def apply[Obj, Items](implicit oneOf: OneOf[Obj, Items]) = oneOf
implicit def left[L, R, Obj <: L] = new OneOf[Obj, L | R]{}
}
protected trait LowPriorityOneOf extends LowPriorityOneOf1{
implicit def right[L, R, Obj <: R] = new OneOf[Obj, L | R]{}
@wheaties
wheaties / stuff.txt
Created December 3, 2015 21:35
Exports
2.10.6 (not working)
______
object Triple extends LowerPriorityTriple {
def <init>() = {
super.<init>();
()
};
object exports extends scala.AnyRef {
def <init>() = {
super.<init>();
@wheaties
wheaties / foo.txt
Created December 3, 2015 21:04
raw and println output of 2.10.6 vs 2.11.7 for export-hook boilerplate
2.10.6 (not working)
____________
implicit <macro> def tpedefns$Triple$anonimplicit$0[$41$[$42$, $43$, $44$] >: tpedefns.this.Triple[$42$, $43$, $44$], $45$ >: _root_.scala.Nothing <: _root_.scala.Any, $46$ >: _root_.scala.Nothing <: _root_.scala.Any, $47$ >: _root_.scala.Nothing <: _root_.scala.Any]: export.this.Export5[$41$[$45$, $46$, $47$]] = _root_.export.ExportsImplExpr.exportsImpl000[tpedefns.this.Triple, $45$, $46$, $47$, export.this.Export5]
2.11.7 (working)
____________
implicit <macro> def tpedefns$Triple$anonimplicit$0[fresh$macro$753[fresh$macro$754, fresh$macro$755, fresh$macro$756] >: tpedefns.this.Triple[fresh$macro$754, fresh$macro$755, fresh$macro$756], fresh$macro$757, fresh$macro$758, fresh$macro$759]: export.this.Export5[fresh$macro$753[fresh$macro$757, fresh$macro$758, fresh$macro$759]] = _root_.export.ExportsImplExpr.exportsImpl000[tpedefns.this.Triple, fresh$macro$757, fresh$macro$758, fresh$macro$759, export.this.Export5]
++++++++