Skip to content

Instantly share code, notes, and snippets.

View joost-de-vries's full-sized avatar

Joost de Vries joost-de-vries

View GitHub Profile
@joost-de-vries
joost-de-vries / gist:bf58c40d46f04dc7689a
Last active August 29, 2015 14:12
Does Java 8 obviate Scala?

Java 8 definitely took some 'oomph' out of mainstream Scala adoption. I do see a lot of Scala adoption at the moment though. Currently it's mostly in ecommerce.

For me Java 8 is too little too late. The things I really miss in Java 8 are:

  • pattern matching Not only handling the cases but more importantly deconstructing the object into variables.
  • type inferencing To prevent Javas so called type stutter SessionFactory sessionFactory = createSessionFactory();. And also to not have to type tedious generic declarations like
Map<String, Observable<JsonNode>> observableMap = stream.collect(mapCollector);
@joost-de-vries
joost-de-vries / foldfun.sc
Last active August 29, 2015 14:02 — forked from headinthebox/gist:37c76829253388fd88e3
Erik Meijers foldleft implementation using foldright rewritten in Scala
object foldfun {
def foldr[A, B](f: A => B => B)(b: B)(s: Seq[A]): B = s match {
case Nil => b
case a :: as =>
f(a)(foldr(f)(b)(as))
} //> foldr: [A, B](f: A => (B => B))(b: B)(s: Seq[A])B
foldr { a: String => b: Int => a.toInt * b.toInt }(7)(Seq("1", "2", "3"))
//> res0: Int = 42
#!/bin/bash
#
# =========================================================================
# Copyright 2014 Rado Buransky, Dominion Marine Media
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@joost-de-vries
joost-de-vries / gist:8825623
Created February 5, 2014 15:08
Compiling scala json parser combinators (from Play framework)
[error] /home/vagrant/wendwet/core/src/main/scala/annoteren/model/objectrollen.scala:78: overloaded method value format with alternatives:
[error] [T(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)](w: play.api.libs.json.Writes[T(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)])(implicit r: play.api.libs.json.Reads[T(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)])play.api.libs.json.OFormat[T(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)] <and>
[error] [T(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)(in method format)](r: play.api.libs.json.Reads[
@joost-de-vries
joost-de-vries / gist:8110503
Last active January 1, 2016 07:19
notes from Gilad Brachas talk wrt functor, monad, semigroup, monoid.The observation that a monoid is foldRightable is interesting.
a semigroup is addable
a monoid is foldRightable or aggregatable
(ie addable, zero)
a functor is mappable
a monad is chainable or flatmappable
strong suit of monads:
@joost-de-vries
joost-de-vries / gist:7946056
Last active December 31, 2015 06:09
Workaround om Play json combinators te kunnen gebruiken bij case classes met één veld
import scala.language.higherKinds
import play.api.libs.functional.InvariantFunctor
object JsonCombinatorUtil {
/** workaround voor issue dat json combinators niet kunnen omgaan met case classes met 1 veld
* zie http://stackoverflow.com/questions/15042205/how-to-serialize-deserialize-case-classes-to-from-json-in-play-2-1 */
implicit class FormatBuilder[M[_], A](o: M[A]) {
def build[B](f1: A => B, f2: B => A)(implicit fu: InvariantFunctor[M]) =
fu.inmap[A, B](o, f1, f2)
}