Skip to content

Instantly share code, notes, and snippets.

View edmundnoble's full-sized avatar
👋
Hi! My name is

Edmund Noble edmundnoble

👋
Hi! My name is
  • Toronto, Canada
View GitHub Profile
@edmundnoble
edmundnoble / stylekick.js
Created August 2, 2015 21:06
Stylekick challenge
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" }
@edmundnoble
edmundnoble / ConstellationSolver.scala
Created August 19, 2015 22:28
DA: Inquiisition constellation puzzle solver
// 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]] = {
@edmundnoble
edmundnoble / DyckPlusStrings.scala
Last active October 19, 2016 03:41
Dyck language plus strings
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)
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
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._
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
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,
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] {
@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
}
@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
}