Skip to content

Instantly share code, notes, and snippets.

View jonifreeman's full-sized avatar

Joni Freeman jonifreeman

View GitHub Profile
@jonifreeman
jonifreeman / bus.md
Last active August 29, 2015 14:10
Bus of Doom

Bus of Doom

In a previous Bacon blog post a way to structure Bacon application was outlined. It introduces Buses as a central way to glue components with each other. I'm in a very strong disagreement with the proposed style. Why?

Quoting Erik Meijer

Subjects are the "mutable variables" of the Rx world and in most cases you do not need them.

In Bacon parlance that would be

@jonifreeman
jonifreeman / gist:6570276
Created September 15, 2013 12:13
Explicit type for a Shapeless record, version: type FieldType[K, V] = (K, V)
// See https://gist.github.com/jonifreeman/6533463
object TestExplicitRecordType {
import shapeless._, record._, syntax.singleton._
object testF extends Poly1 {
implicit def atFieldType[K, V] = at[(K, V)] {
case (k, v) => k.toString
}
}
@jonifreeman
jonifreeman / gist:6552821
Last active December 23, 2015 00:19
type FieldType[K, V] = (K, V)
// Singleton types as keys
r get "k01" // 1s was 1s
r get "k02" // 3s was 4s
r get "k03" // 5s was 7s
r get "k04" // 6s was 10s
r get "k05" // 7s was 12s
r get "k10" // 12s was 21s
r get "k20" // 16s was 30s
// Objects as keys
@jonifreeman
jonifreeman / gist:6550962
Created September 13, 2013 13:48
Records with objects as keys
// Test3.scala
import shapeless._
import syntax.singleton._
object Test3 {
val r =
(k01 ->> 1) :: (k02 ->> 1) :: (k03 ->> 1) :: (k04 ->> 1) :: (k05 ->> 1) ::
(k06 ->> 1) :: (k07 ->> 1) :: (k08 ->> 1) :: (k09 ->> 1) :: (k10 ->> 1) ::
(k11 ->> 1) :: (k12 ->> 1) :: (k13 ->> 1) :: (k14 ->> 1) :: (k15 ->> 1) ::
(k16 ->> 1) :: (k17 ->> 1) :: (k18 ->> 1) :: (k19 ->> 1) :: (k20 ->> 1) ::
@jonifreeman
jonifreeman / gist:6550469
Created September 13, 2013 13:09
Record compilation performance
// Compilation time of each commented function on my machine (as repoted by sbt console).
// **********************************************************************
// Test.scala
import shapeless._
import syntax.singleton._
object Test {
val r =
("k01" ->> 1) :: ("k02" ->> 1) :: ("k03" ->> 1) :: ("k04" ->> 1) :: ("k05" ->> 1) ::
// Compilation time of each commented function on my machine (as repoted by sbt console).
// **********************************************************************
// Test.scala
import shapeless._
import syntax.singleton._
object Test {
val r =
("k01" ->> 1) :: ("k02" ->> 1) :: ("k03" ->> 1) :: ("k04" ->> 1) :: ("k05" ->> 1) ::
@jonifreeman
jonifreeman / gist:6533463
Created September 12, 2013 05:54
Explicit type for a Shapeless record.
object TestExplicitRecordType {
import shapeless._, record._, syntax.singleton._
object testF extends Poly1 {
implicit def atFieldType[F, V](implicit wk: shapeless.Witness.Aux[F]) = at[FieldType[F, V]] {
f => wk.value.toString
}
}
// Is there more straighforward way to give an explicit type for a record?
@jonifreeman
jonifreeman / gist:5404963
Created April 17, 2013 14:55
Negroni in do-notation
assemble = function(g, v, a) {
return $do {
gin <- g
vermouth <- v
amaro <- a
return new Negroni(gin, vermouth, amaro)
}
}
@jonifreeman
jonifreeman / gist:5402450
Created April 17, 2013 07:37
Do-notation for Fantasy Land
/*
$do {
x <- foo
y <- bar
z <- baz
return x * y * z
}
Desugars into:
@jonifreeman
jonifreeman / gist:3667222
Created September 7, 2012 15:35
Kiama rewrite
scala> import org.kiama.rewriting.Rewriter._
import org.kiama.rewriting.Rewriter._
scala> trait Expr
defined trait Expr
scala> case class Constant(x: Int) extends Expr
defined class Constant
scala> case class Add(e1: Expr, e2: Expr) extends Expr