This file contains hidden or 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
[error] (myproject/compile:compile) scala.reflect.internal.FatalError: class Universe does not have a member Quasiquote |
This file contains hidden or 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 org.apache.commons.codec.binary.Base64 | |
import java.nio.file._ | |
import java.nio.file.attribute._ | |
import scala.collection.mutable.ListBuffer | |
val htmlTemplate = """ | |
<html> | |
<head> | |
<title>Encoded Images!</title> | |
</head> |
This file contains hidden or 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
package myproject.util | |
import myproject.macros._ | |
import scalaz._,Scalaz._,Kleisli._ | |
object KleisliEnhance { | |
implicit class KleisliEnhancer[M[+_]: Monad, A, B](kleisli: Kleisli[M, A, B]) { | |
def localFrom[AA]: Kleisli[M, AA, B] = kleisli.local(TupleTransformer.tupleToFrom[A, AA] | |
} | |
} |
This file contains hidden or 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 doThing[M[+_]: Monad, T, U, V] | |
(actionOne: () => ReaderT[M, T, Unit], | |
actionTwo: () => ReaderT[M, T, Unit], | |
actionThree: () => ReaderT[M, T, Unit], | |
actionFour: () => ReaderT[M, (T, U), Unit], | |
actionFive: () => ReaderT[M, T, Unit, | |
actionSix: () => ReaderT[M, V, Unit]) | |
(): ReaderT[M, (T, U, V), Unit] = { | |
val tFromTriple: ((T, U, V)) => T = _._1 | |
val tuFromTriple: ((T, U, V)) => (T, U) = tup => (tup._1, tup._2) |
This file contains hidden or 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 logEntry() = macro logEntryImpl | |
def method(param1: String, param2: Int): String = { | |
logEntry() | |
param1 * param2 | |
} | |
// I'd want | |
// logEntry() | |
// to be replaced with |
This file contains hidden or 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 strictFor[M[+_], T](forExp: M[T])(implicit mMonad: Monad[M]): M[T] = macro strictForImpl[M, T] | |
def strictForImpl[M[+_]: c.WeakTypeTag, T: c.WeakTypeTag](c: Context)(forExp: c.Expr[M[T]])(mMonad: c.Expr[Monad[M]]): c.Expr[M[T]] = { |
This file contains hidden or 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
// This bit is mostly getting imports together and some simple types. | |
import scala.annotation.tailrec | |
import scala.collection.mutable.ListBuffer | |
import scalaz._,Scalaz._ | |
case class User(id: Int, name: String, score: Long) | |
// EXAMPLE: Turn collection into another collection. | |
// With a for loop (in this case a foreach): |
This file contains hidden or 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
scala> import scalaz._,Scalaz._,effect._ | |
import scalaz._ | |
import Scalaz._ | |
import effect._ | |
scala> val list = List(IO(1).liftM[OptionT]) | |
list: List[scalaz.OptionT[scalaz.effect.IO,Int]] = List(OptionT(scalaz.effect.IOFunctions$$anon$5@52f3b59)) | |
scala> list.sequenceU | |
res4: G.M[List[G.A]] = OptionT(scalaz.effect.IOFunctions$$anon$5@3beab0fc) |
This file contains hidden or 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 scalaz._ | |
import Scalaz._ | |
import scalaz.concurrent._ | |
import scala.annotation.tailrec | |
import java.util.concurrent.locks.ReentrantReadWriteLock | |
trait Timeout | |
object Timeout extends Timeout | |
case class Timer(timeoutTickMs: Int = 100, workerName: String = "TimeoutContextWorker") { |
This file contains hidden or 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
scala> import scalaz._,Scalaz._,scalaz.concurrent._ | |
import scalaz._ | |
import Scalaz._ | |
import scalaz.concurrent._ | |
scala> (1 to 10).map(n => Future.fork(Future.delay{Thread.sleep(1000); n})).toList.sequence.run // Takes 10 seconds. | |
res0: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) | |
scala> Nondeterminism[Future].gather((1 to 10).map(n => Future.fork(Future.delay{Thread.sleep(1000); n})).toList).run // Takes 2 seconds. | |
res1: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) |