Skip to content

Instantly share code, notes, and snippets.

Avatar

Joni Freeman jonifreeman

View GitHub Profile
@jonifreeman
jonifreeman / bus.md
Last active Aug 29, 2015
Bus of Doom
View bus.md

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 Sep 15, 2013
Explicit type for a Shapeless record, version: type FieldType[K, V] = (K, V)
View gist:6570276
// 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 Dec 23, 2015
type FieldType[K, V] = (K, V)
View gist:6552821
// 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 Sep 13, 2013
Records with objects as keys
View gist:6550962
// 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 Sep 13, 2013
Record compilation performance
View gist:6550469
// 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) ::
View 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) ::
@jonifreeman
jonifreeman / gist:6533463
Created Sep 12, 2013
Explicit type for a Shapeless record.
View gist:6533463
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 Apr 17, 2013
Negroni in do-notation
View gist:5404963
assemble = function(g, v, a) {
return $do {
gin <- g
vermouth <- v
amaro <- a
return new Negroni(gin, vermouth, amaro)
}
}
@jonifreeman
jonifreeman / gist:5402450
Created Apr 17, 2013
Do-notation for Fantasy Land
View gist:5402450
/*
$do {
x <- foo
y <- bar
z <- baz
return x * y * z
}
Desugars into:
View gist:3667222
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
You can’t perform that action at this time.