search term:

Gigahorse 0.1.0

Update: please use Gigahorse 0.1.1

Gigahorse 0.1.0 is now released. It is an HTTP client for Scala with Async Http Client underneath. Please see Gigahorse docs for the details. Here’s an example snippet to get the feel of the library.

scala> import gigahorse._
scala> import scala.concurrent._, duration._
scala> Gigahorse.withHttp(Gigahorse.config) { http =>
         val r = Gigahorse.url("").get.
             "q" -> "1 + 1",
             "format" -> "json"
         val f =, Gigahorse.asString andThen {_.take(60)})
         Await.result(f, 120.seconds)

registry and reference pattern

There’s a “pattern” that I’ve been thinking about, which arises in some situation while persisting/serializing objects. To motivate this, consider the following case class: scala> case class User(name: String, parents: List[User]) defined class User scala> val alice = User("Alice", Nil) alice: User = User(Alice,List()) scala> val bob = User("Bob", alice :: Nil) bob: User = User(Bob,List(User(Alice,List()))) scala> val charles = User("Charles", bob :: Nil) charles: User = User(Charles,List(User(Bob,List(User(Alice,List()))))) scala> val users = List(alice, bob, charles) users: List[User] = List(User(Alice,List()), User(Bob,List(User(Alice,List()))), User(Charles,List(User(Bob,List(User(Alice,List())))))) The important part is that it contains parents field, which contains a list of other users.

sjson-new and the prisoner of Azkaban

This is part 3 on the topic of sjson-new. See also part 1 and part 2.

Within the sbt code base there are a few places where the persisted data is in the order of hundreds of megabytes that I suspect it becomes a performance bottleneck, especially on machines without an SSD drive. Naturally, my first instinct was to start reading up on the encoding of Google Protocol Buffers to implement my own custom binary format.

sjson-new and custom codecs using LList

Two months ago, I wrote about sjson-new. I was working on that again over the weekend, so here’s the update. In the earlier post, I’ve introduced the family tree of JSON libraries in Scala ecosystem, the notion of backend independent, typeclass based JSON codec library. I concluded that we need some easy way of defining a custom codec for it to be usable. roll your own shapeless In between the April post and the last weekend, there were flatMap(Oslo) 2016 and Scala Days New York 2016.


background One of the fun way of thinking about software projects is literary analysis. Instead of the actual source code, think of who wrote it when and why (what problem does it solve), and how it’s written (what influenced it). Within the Scala ecosystem, not too many genre are as rich as the JSON libraries. In December 2008, the first edition of Programming in Scala came out, which used JSON as an example in the context of parser combinator, and showed that JSON parser can be written in 10 lines of code:

sbt server reboot

This is a continuation from the sbt 1.0 roadmap that I wrote recently. In this post, I’m going to introduce a new implementation of sbt server. Please post on sbt-dev mailing list for feedback.

The motivation for sbt server is better IDE integration.

A build is a giant, mutable, shared, state, device. It’s called disk! The build works with disk. You cannot get away from disk.

– Josh Suereth in The road to sbt 1.0 is paved with server

The disk on your machine is fundamentally a stateful thing, and sbt can execute the tasks in parallel only because it has the full control of the effects. Any time you are running both sbt and an IDE, or you’re running multiple instances of sbt against the same build, sbt cannot guarantee the state of the build.

sbt 1.0 roadmap

There’s been some discussions around sbt 1.0 lately, so here is a writeup to discuss it. This document is intended to be a mid-term mission statement. A refocus to get something out. Please post on sbt-dev mailing list for feedback. Timing I don’t have a good idea on the timing of when sbt 1.0 will ship. The biggest feature of sbt 1.0 is code reorganization, which is is already in progress: http://www.

ScalaMatsuri as a lifestyle

For me (and for many of the 27 organizers, I imagine) ScalaMatsuri is a lifestyle. It’s true that there was a successful two-day conference in Tokyo with 550 participants. But for us the organizers, the preparation has been going on since February 28th, for 11 months. Despite the fact that my contribution was small, planning ScalaMatsuri 2016 was by far the most amount of involvement I’ve committed to. Through the course of planning months, there were many discussions over Slack, Hangouts, and occasionally even face-to-face.

stricter Scala with -Yno-lub

For a flexible language like Scala, it’s useful to think of subset of the programming language, like your own personal Good Parts, and opinionated style guides. setup To try -Yno-lub, you can drop in the following sbt plugin to project/ynolub.sbt: addSbtPlugin("com.eed3si9n" % "sbt-ynolub" % "0.2.0") lub When Scala’s type inferencer finds type A and type B to unify, it tries to calculate the lub (least upper bounds) of two types with regards to <:<.

herding cats: day 1

Check out my new series herding cats. (I’m writing it using Pamflet from the get go)

This is a log of me going through Cats, a functional programming library for Scala that is currently experimental and under active development.

switching Java version

I’ve been switching between Mac and Ubuntu, and between Java 6 and 7 lately. This is a memo of how to switch Java versions on both Mac and Ubuntu. Update: Yoshida-san told me about this thing called jEnv, which does all this. Zshrc Here’s one way of loading different shell files depending on the OS: ## basic [ -f $HOME/dotfiles/zshrc.basic ] && source $HOME/dotfiles/zshrc.basic ## aliases [ -f $HOME/dotfiles/zshrc.alias ] && source $HOME/dotfiles/zshrc.

monads are fractals

On my way back from Uppsala, my mind wandered to a conversation I had with a collegue about the intuition of monads, which I pretty much butchered at the time. As I was mulling this over, it dawned on me.

Sierpinski triangle

monads are fractals

The above is a fractal called Sierpinski triangle, the only fractal I can remember to draw. Fractals are self-similar structure like the above triangle, in which the parts are similar to the whole (in this case exactly half the scale as parent triangle).

Monads are fractals. Given a monadic data structure, its values can be composed to form another value of the data structure. This is why it’s useful to programming, and this is why it occurrs in many situations.

Let’s look at some examples:

scala> List(List(1), List(2, 3), List(4))
res0: List[List[Int]] = List(List(1), List(2, 3), List(4))

towards universal access at a conference

Two days of #ScalaMatsuri ended as a huge success. But for the next year, I’m leaving ourselves a few homeworks to work on. As the title suggests, the next goal that we should aim for is universal access. In Scala language, universal access principle indicates the fact that both methods and fields can be accessed interchangeably from outside. For a conference, I mean universal access to mean being more inclusive to various groups of people:

ScalaMatsuri day1

This year was the second Scala conference in Japan. We’ve changed the name to ScalaMatsuri, which means Scala festival in Japanese. 300 tickets sold out. With invited guests and free tickets for sponsors, there may have been even more people. The venue was at CyberAgent, which runs blog service and online ad services. Day 1 kicked off with Martin’s (@ordersky) ‘Evolution of Scala.’ Many people were looking forward to see Martin, so I think it was full house from the get go.

IRC memo

register your nick /msg NickServ REGISTER %password% What is the recommended way to set up my IRC nickname? make new channel To check whether a channel has already been registered, use the command: /msg ChanServ info ##channelname /join ##channelname The command to register your channel (once you’ve joined it and you have op status) is as follows: /msg ChanServ register ##channelname Registering a channel on freenode moderate a channel Only users who have a voice are able to talk.

Vim memo

Personally, I don’t mind using SublimeText, which is my editor of choice for a while. But I’m also curious about commandline editors since many people taut their ability to code over the network. You could forward X or remote in using some other way and still use Sublime, but let’s see how if goes. I started working on this Vim setup when I got a new MBP recently. Figured, I can try something new.

scripting with Scala

The need for regular expressions is real. Whenver I need to transform a set of text files it usually ends up with fumbling through the documentation of find command, zsh, and StackOverflow Perl questions. I would rather use Scala instead of muddling through Perl. It’s really the matter of my familiarity than anything else. For example, I now have over a hundred reStructuredText files that I want to convert into markdown.

constraining class linearization (mixin order) in Scala

Woke up early yesterday, so I started skimming @xuwei_k’s override blog post. The topic was so intriguing, I got out of the bed and started translating it as the curious case of putting override modifier when overriding an abstract method in Scala. In there he describes the conundrum of providing the default instances to typeclasses by using Scalaz codebase as an example. Here’s a simplified representation of the problem: trait Functor { def map: String } trait Traverse extends Functor { override def map: String = "meh" } sealed trait OneOrFunctor extends Functor { override def map: String = "better" } sealed trait OneOrTraverse extends OneOrFunctor with Traverse { } object OneOr { def OneOrFunctor: Functor = new OneOrFunctor {} def OneOrTraverse: Traverse = new OneOrTraverse {} } To test this you can run:

curious case of putting override modifier when overriding an abstract method in Scala

This is a translation of Scalaで抽象メソッドをoverrideする際にoverride修飾子を付けるべきかどうかの是非 by Kenji Yoshida (@xuwei_k), a Scalaz committer. First, a quote from Programming in Scala, 2nd ed. p. 192: Scala requires [override] modifier for all members that override a concrete member in a parent class. The modifier is optional if a member implements an abstract member with the same name. In this post, we’ll discuss this “The modififier is optional.” Since overriding an existing method with implementation requires override modifier, and failure to do so would result to a compiler error, there’s not much to talk about for that case.

sequencing tasks with sbt-sequential

In this post, I will discuss the execution semantics and task sequencing in sbt 0.13. First we will cover the background, and then I will introduce a new experimental plugin sbt-sequential that adds sequential tasks. background Mark said: The sbt model is to have your side effects be local to your task so that as long as dependencies are satisfied, the task can be executed whenever. The win is parallel by default and enabling faster builds in practice.

traveling through the 4th dimension with sbt 0.13

Warning: This is a memo about sbt for intermediate users. setting system At the heart of sbt 0.13 is the setting system, just like sbt 0.12. Let’s look at Settings.scala: trait Init[Scope] { ... final case class ScopedKey[T]( scope: Scope, key: AttributeKey[T]) extends KeyedInitialize[T] { ... } sealed trait Initialize[T] { def dependencies: Seq[ScopedKey[_]] def evaluate(map: Settings[Scope]): T ... } sealed class Setting[T] private[Init]( val key: ScopedKey[T], val init: Initialize[T], val pos: SourcePosition) extends SettingsDefinition { .

what is object-oriented programming?

How do you define oop?

purely object-oriented programming

Purely object-oriented programming is defined to be:

programming with objects.

What’s an object?

It is an atom that can hold references to other objects, receive predefined list of messages, and send messages to other objects and itself; and nothing else. A message consists of a name and a list of reference to objects.

This is it. The wording is mine, but the idea is from Alan Kay (2003), the guy who coined the term object-oriented programming. Anything else is either not directly tied to oop or an implementation detail.

sbt-logo proposal

See sbt-logo proposals thread on sbt-dev and the original thread on sbt. The source is at eed3si9n/sbt-logo. Edit: Changed the tail of ’t’. See github for the original. .sbt build definition sbt is a build tool for Scala and Java projects that aims to do the basics well. sbt is a build tool for Scala and Java projects that aims to do the basics well. > ~compile .sbt build definition sbt is a build tool for Scala and Java projects that aims to do the basics well.

Scala: the flying sandwich parts

JavaScript existed since 1995 long before ‘JavaScript: The Good Parts’ (2008), jQuery (2006), and V8 (2008) happened. The interesting thing about Douglas Crockford’s ‘The Good Parts’ is that unlike the other additive work, it’s a book about subtracting features from the language.

I’ve been thinking about exploring a subset of Scala in a wonderland setting without the “real world” constraints such as Java familiarity and interoperability. If using Scala as an alternative Java is acceptable, why not try using it as an alternative functional programming language? Another point of this thought experiment is to see some of the duplicate constructs can be reduced. In this article, I’m not interested in finding out the idiomatic way, or calling something good or bad. I’m calling this The Flying Sandwich Parts (TFSP).

scopt 3.0

scopt is a little command line options parsing library. Today, I’m releasing scopt 3.0. If you’re not interested in the implementation details, skip to the readme. Around March 4th, 2010, I became a committer to scopt, a fork of Aaron Harnly’s scala-options that was written in 2008. I think I wanted to make a few changes around the usage text, key=value options, and argument list. Since then I’ve been fielding all the bug reports, including the request to publish the jar on scala-tools.

how to write a Dispatch plugin

Dispatch has been the de facto library to get to the Internet from Scala. To keep in step with the recent move towards non-blocking IO, @n8han rewrote the library as Reboot based on Async Http Client. This became Dispatch 0.9. Then Dispatch 0.10 came out to replace its own Promise type with the standarized SIP-14 Future.

As with Dispatch Classic, Reboot lets you write plugins to wrap around web APIs. In this post we’ll port a plugin from Classic to explore how it works.

working on your own twitter bot?

Notes on 'Monads Are Not Metaphors'

This is a translation of 「モナドはメタファーではない」に関する補足 by Kenji Yoshida (@xuwei_k), one of the most active Scala bloggers in Japan covering wide range of topics from Play to Scalaz. Daniel Spiewak’s Monads Are Not Metaphors was written about two and a half years ago, but seeing how its Japanese translation is still being tweeted and being bookmarked by 250 users on Hantena, its popularity doesn’t seem to cease. I just remembered something to note about the example code used in the post, which could be an unstylish critique, but I’m going to jot it down here.

translating a conference

It’s been a month now, but on March 1, 2013 I flew to Japan to attend “Scala Conference in Japan 2013.” That’s the name of the conference. from a podcast One day (June 2, 2012), I was listening to Scala Types recorded at Scala Days 2012, and someone (turns out it’s @timperrett) said “I would love to see Scala Days in Asia. We had two in Europe now. It would be wicked to have it in China or Japan, or somewhere like that.

sudoku using Func

This is the 5th entry of Scalaz Advent Calendar 2012. During the months of December, tech-savvy geeks in Japan take turns to post themed blog articles, known as the “Advent Calendar”. For last year’s Scala Advent Calendar 2011 I translated Eric Torreborre’s post covering The Essence of Iterator Pattern. It was somewhat of a calculated move, knowing Japanese fondness for functional programming articles. Another selfish motive was that some of the concept would seep in to my thickness as I was translating the post word by word.

C# LINQ for Scala heads

This is a memo of C# Linq features for Scala programmers. Or vice versa. Type inference C# has type inference. I try to use var when I can for local variables. var x = 1; Scala also has var, but the preferred way is to use immutable val if possible. val x = 1 Creating a new List or an Array C# can create collections in-line. using System.Collections.Generic; var list = new List { “Adam”, “Alice”, “Bob”, “Charlie” }; var array = new [] { 0, 1, 2 }; All collections in Scala comes with a factory method.

sbt plugins roundup

Unlike XML-based build tools sbt’s build definitions are written in Scala (for both .sbt and .scala). This means that once one gets over the hurdle of learning sbt’s concepts and operators, it doesn’t take much for build users to start writing sbt plugins. I’ve ported a few from sbt 0.7 before, but I’ve also been writing some original ones recently that I’d like to share. sbt-dirty-money sbt-dirty-money is a plugin to clean Ivy cache somewhat selectively (anything that includes organization and name under ~/.

treehugger.scala pamflet

treehugger is a library to write Scala source code programmatically. It’s also an implementation of Scala AST based on Reflection API, now available from github eed3si9n/treehugger. Edit: I’ve expanded this into a complete guide using awesome n8han/pamflet. See treehugger’s pamflet

implicit parameter precedence again

Scala the language is one of the most elegant, expressive, consistent, and pragmatic languages. From pattern matching to the uniform access principle, it got so many things right. And Scala the ecosystem and Scala the community only makes it better. In Scala 2.9.1, locally declared implicits are preferred over imported ones. The problem is that the spec does not cover such behavior. My original hypothesis was that either I did not understand the spec correctly, or the spec was wrong.

revisiting implicits without import tax

Northeast Scala Symposium 2012 is coming up in a few months, but I want to revisit a talk from this year’s nescala to wrap up 2011. One after the other, nescala had amazingly high quality of talks. You can check them all out here. With Daniel’s Functional Data Structure and Jonas’s Akka each having an hour-long key notes, the symposium left an impression on me that actors and FP are two major forces within Scala community.

an unofficial guide to sbt 0.10 v2.0

version 2.0 When the original version was published on 06/19/2011, the motive for writing this guide was to aid the effort of moving people over to sbt 0.10 from 0.7, inspired by Mark’s sbt 0.10 demos that I was able to see live (first at northeast scala, and second at scala days 2011). At the time, the plugins were considered to be a major roadblock to the migration, since build users can’t move to 0.

testing sbt plugins

NOTE: Official docs: Let’s talk about testing. Once you write a plugin, it turns into a long-term thing. To keep adding new features (or to keep fixing bugs), writing tests makes sense. But how does one go about testing a plugin to a build tool? We fly, of course. scripted test framework sbt comes with scripted test framework, which let’s you script a build scenario. It was written to test sbt itself on complex scenarios such as change detection and partial compilation:

sff4s: simple future facade for Scala

I wish there was a common super trait for various future implementations in the standard library, so I can express the concept without tying the code to a specific platform stack. I am not sure if there are others who feel the same, but I think it would be useful for library authors. That’s my motivation of writing sff4s. what is future? You’ve probably come across the notion before but let’s go over it quickly.

beginning sbt 0.10

On 7/13/2011 I hosted a ny-scala meetup on sbt 0.10 migration with doug tangren and rose toomey. Here is the slides. beginning sbt 0.10 picture show

Twilight for IntelliJ IDEA

I’ve tried other IDEs for Scala, but always ended up going back to TextMate. As I am getting on the IntelliJ IDEA wagon, I’ve made a Twilight theme to make the ride smoother.

typeclass-based XML data binding

Ultimately, the users of scalaxb are interested the real problems that the entity objects express, not how they persist into XML. That’s why I knew I eventually had to vacate the singleton/companion object of the case class to implement the data binding. Until recently it has been generating the data binding implementation as follows: object Address extends rt.ElemNameParser[Address] { val targetNamespace = "" def parser(node: scala.xml.Node): Parser[Address] = ... def toXML(__obj: Address, __namespace: String, __elementLabel: String, __scope: scala.

Scala and OSGi using NetBeans

For some reason, I can’t keep OSGi in my head. Everything I read about it slips away in a few weeks, and I have re-read the guides and tutorials. Here’s a memo of setting up OSGi bundle written in Scala using NetBeans, following Neil Barlett’s OSGi in Practice, except the book uses Eclipse. Installing Scala on Mac Skip this section if you use non-Mac. Install MacPorts. Run the following from Terminal: