Small Examples

Another Small Example of the Type Class Pattern

Some guys at work wanted to know what was going on in this code:

import scalaz._
import Scalaz._
val x: Option[Int] = whatever
val y = ~x // Huh!?

[...]

Posted in Scala, Small Examples | Comments Off

A Small Example of Kleisli Arrows

This is a simple example of use of a mysterious beast called a Kleisli arrow.
[...]

Posted in Scala, Small Examples | 6 Comments

A Small Example of Phantom Types (with covariance thrown in)

Here is an example of so-called phantom types and covariance in Scala to improve type safety and correctness. The example is a simplified version from a real project.
[...]

Posted in Scala, Small Examples | Comments Off

A Small Example of the Typeclass Pattern in Scala

Typeclasses, (or type classes), are most famously a language feature of Haskell that has gained interest in the Scala community. Here I describe the basic pattern with references for further study.
[...]

Posted in Scala, Small Examples | 1 Comment

Flattening the Loan Pattern

The loan pattern is a common pattern for working with resources that should be closed or otherwise managed after use. It removes responsibility from the developer to manage a resource properly. When loaning several objects, one often ends up with nested functions. Here is a way to flatten that to make things clearer.
[...]

Posted in Scala, Small Examples | Comments Off

A Small Functor Example

In the world of functional programming you will quickly come across the concept of a Functor. What I present below is a simple example that might provide some intuition, with references for further reading.
[...]

Posted in Scala, Small Examples | Comments Off

A Small Example of the Scalaz IO Monad

I wanted a very tiny example of using the IO Monad in the brilliant Scalaz library, and here it is.

[...]

Posted in Scala, Small Examples | 5 Comments

A little Scalaz magic

Here are a few useful things you can do easily with Scalaz to make you code a little simpler.
[...]

Posted in Scala, Small Examples | Comments Off