Cascade Of Insights

The blog of Adam Gordon Bell (agbell)

  • More Scala Groups And Tuples

    Continuing from here, I have lists of tuples and I want to group them. Here I have a list of 4-tuples and I want to group the second tuple by the first. The fact that I need to do this probably represents some greater problem, but that is a story for another time

    import shapeless._
    import syntax.std.tuple._
    import poly._
    object GroupLists {
    def group1TwoExtra[A,B,C,D](t : List[(A,B,C,D)]) : List[(A,List[B],C,D)] = {
          val map = LinkedHashMap[A, LinkedHashSet[B]]()
          val mapOther = scala.collection.mutable.Map[A,(C,D)]()
          for (i <- t) {
            val key = i.head
            map(key) = map.lift(key).getOrElse(LinkedHashSet[B]()) + i.drop(1).head
            mapOther += (key -> i.drop(2))
 => (b._1, b._2.toList) ++ mapOther(b._1)).toList
  • Scala Slick Group

    In slick, if each foo has many bars and I need to retrive several foos and associtated bars I will do something like this:

    val join = for {
         (f,b) <-
                      foo.filter(...) on  innerJoin
                      bar on (...)
       } yield (o,i,s)


NakedObjectsFramework antlr aop attribute-based-caching blog bluetooth brain_gym c# ci clojure comedy data emacs essay euler f# faq field-level-authorization fitness good-judgement-project gym hakyll haskell haskell-is-hard humor ideas keyboard nparsec parsec parser parser-combinator paul-graham postsharp prediction presentation release row-level-authorization scala slick tags thinkpad tuples windows wordpress wssf