Skip to content

Instantly share code, notes, and snippets.

@wheaties
wheaties / FlatMap.scala
Created May 29, 2015 02:24
Automatic Transformer-like flatMap on a stack of Monads
//So close but no cigar!
sealed private[autolift] trait SideEffectFM[Obj, Function] extends DFunction2[Obj, Function]
private[autolift] object SideEffectFM extends LowPrioritySideEffectFM{
def apply[Obj, Function](implicit se: SideEffectFM[Obj, Function]): Aux[Obj, Function, se.Out] = se
implicit def recur[F[_], G, Function, Out0 >: Null](implicit bind: Bind[F], se: SideEffectFM.Aux[G, Function, Out0]): Aux[F[G], Function, se.Out] =
new SideEffectFM[F[G], Function]{
type Out = Out0
@wheaties
wheaties / mistake.scala
Last active August 29, 2015 14:23
Mistake on 2/1 of Dep Type Talk
trait IsFuture[F]{
type T
def apply(f: F): Future[T]
}
object IsFuture{
def apply[F](implicit isf: IsFuture[F]) = isf
implicit def mk[A] = new IsFuture[Future[A]]{
@wheaties
wheaties / highlight.scala
Last active August 29, 2015 14:24
Post 1
trait Container[F[_], G[_,_], A, B, C]{
def get(idx: Int): F[A]
def set(value: A, idx: Int): G[B, A]
def replaceIf(f: A => Boolean, value: A): G[B, C]
}
class Many[A](list: List[A]) extends Container[Option,Either,A,Throwable,List[A]]{
//code here...
}
@wheaties
wheaties / future.scala
Last active August 29, 2015 14:24
Too Many Types
trait Query[F[_],Key,Value]{
def get[T](key: Key)(implicit store: Store[Get, Value, T]): F[T]
def set[T](key: Key)(value: Value)(implicit store: Store[Set, Value, T]): F[T]
}
//historical chain of value.
import java.concurrent.ConcurrentSkipListMap
class History[Token, A, B](tk: => Token, prev: ConcurrentSkipListMap[Token, A], id: A => B){
def apply(f: A => A): (Token, B) ={
val token = tk
(token, id(update(token, f)))
}
def map[C](f: B => C) = new History(prev, id andThen f)
@wheaties
wheaties / example.scala
Created November 3, 2015 02:32
failed use of imports
import export._
//contrived example
trait LF[A] extends DepFn[A]
@imports[LF]
object LF{
//stuff
}
@wheaties
wheaties / mkdef.scala
Created December 2, 2015 15:19
MkExportDefMacro
def mkExportDefMacro(tcTpe: Type, exportTc: Type, nme: TermName): Tree = {
val tcRef = mkAttributedRef(tcTpe)
val kind = tcTpe.typeParams.map(_.asType.typeParams.length)
val suffix =
if(kind.exists(_ > 1) || kind.size > 22)
c.abort(c.enclosingPosition, s"$tcTpe has an unsupported kind")
else kind.mkString("")
val (f, fd) = {
val t = TypeName(c.freshName)
@wheaties
wheaties / exportgen.scala
Created December 3, 2015 20:38
Autogen Issues
// auto-generated boilerplate
package export
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
import macrocompat.bundle
@bundle
class ExportsImplExpr(val c: whitebox.Context) {
import c.universe._
@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]
++++++++
@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>();