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
var movieLists = [ | |
{ | |
name: "New Releases", | |
videos: [ | |
{ | |
"id": 70111470, | |
"title": "Die Hard", | |
"boxarts": [ | |
{ width: 150, height:200, url:"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg" }, | |
{ width: 200, height:200, url:"http://cdn-0.nflximg.com/images/2891/DieHard200.jpg" } |
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
// Astrarium constellation puzzle solver for DA: Inquisition. Just assign numeric labels to the stars, and record | |
// the connections between them in the "edges" container. | |
object ConstellationSolver extends App { | |
type Edge = (Int, Int) | |
def E(i : Int, f : Int) = (i, f) | |
def orderEdges(edges : Set[Edge]) : Set[Seq[Edge]] = { |
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 scalaz._ | |
import Scalaz._ | |
type DyckTerm = Free[List, Char] | |
type DyckSentence = List[Free[List, Char]] | |
// bracket a sentence | |
def bracket(f: DyckSentence): DyckTerm = Free.roll[List, Char](f.toList) |
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
package org.atnos.benchmark | |
import org.scalameter.api._ | |
import org.atnos.eff._ | |
import EvalEffect._ | |
import Eff._ | |
import syntax.all._ | |
import cats.implicits._ | |
import cats.Eval | |
import monix.eval.Task |
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
package qq | |
package cc | |
import cats.data.NonEmptyVector | |
import cats.implicits._ | |
import cats.{Monad, Traverse} | |
import monix.eval.Task | |
import org.atnos.eff._ | |
import org.atnos.eff.syntax.all._ | |
import qq.util._ |
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
scala> sealed trait B | |
defined trait B | |
scala> case class A(i: Int) extends B | |
defined class A | |
scala> implicit class AOps(a: A) { | |
| def stuff: Unit = println("A") | |
| } | |
defined class AOps |
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 raceFold[A, B](ob: Seq[Task[A]])(z: B)(fold: (B, A) => B): Observable[B] = { | |
Observable.unsafeCreate { subscriber => | |
// We need a monitor to synchronize on, per evaluation! | |
val lock = new AnyRef | |
val conn = StackedCancelable() | |
// Forces a fork on another (logical) thread! | |
subscriber.scheduler.executeAsync { () => | |
val _ = lock.synchronized { | |
// Keeps track of tasks remaining to be completed. | |
// Is initialized by 1 because of the logic - tasks can run synchronously, |
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 cats.Functor | |
import cats.implicits._ | |
sealed trait Freeco[F[_], V, A] { | |
def eliminate[B](pureElim: V => B, rollElim: (F[Freeco[F, V, A]], A) => B): B | |
def fold[B](pureElim: V => B, rollElim: (F[V], A) => V)(implicit F: Functor[F]): B | |
} | |
case class Pure[F[_], V, A](v: V) extends Freeco[F, V, A] { |
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
@inline final def cataM[F[_] : Traverse, M[_] : Monad, A] | |
(tf: Fix[F])(destroy: F[A] => M[A]): M[A] = { | |
val projected: F[Fix[F]] = tf.unFix | |
val looped: M[F[A]] = projected.traverse[M, A](cataM(_)(destroy)) | |
val destroyed: M[A] = looped.flatMap(destroy) | |
destroyed | |
} |
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
@inline final def cataM[F[_] : Traverse, M[_] : Monad, A, B] | |
(tf: Cofree[F, A])(destroy: (A, F[B]) => M[B]): M[B] = { | |
val head: A = tf.head | |
val tail: F[Cofree[F, A]] = tf.tailEval.value | |
val looped: M[F[B]] = tail.traverse(cataM(_)(destroy)) | |
val destroyed: M[B] = looped.flatMap(destroy(head, _)) | |
destroyed | |
} |
OlderNewer