This gist has been upgraded to a blog post here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main(main) where | |
import Data.Maybe | |
import Data.List | |
-- Data table copied from https://matthewearl.github.io/2015/12/10/gchq-xmas-card/ | |
width = 25 | |
height = 25 | |
rows = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> case class Foo(x: Int = -12345) | |
defined class Foo | |
scala> def y = 5 | |
y: Int | |
scala> val x = Foo(y) | |
x: Foo = Foo(5) | |
scala> val x = Foo{y} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for a given typeclass | |
trait CharIso[T] { | |
def toChar(t: T): Char | |
def fromChar(c: Char): T | |
} | |
// provide the following apply method | |
// so that you can write: CharIso[T].toChar(...) instead of implicitly[CharIso[T]].toChar(...) | |
object CharIso { | |
def apply[T : CharIso]: CharIso[T] = implicitly[CharIso[T]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://en.wikipedia.org/wiki/Geohash | |
object geohash { | |
val LAT_RANGE = (-90.0, 90.0) | |
val LON_RANGE = (-180.0, 180.0) | |
private def mid(pair:(Double,Double)) = (pair._1+pair._2) / 2 | |
private def decodePart(range:(Double,Double), bin:String) = bin.map(_.toInt - '0'.toInt).foldLeft(range)( (acc,bit) => if (bit == 0) (acc._1, mid(acc)) else (mid(acc), acc._2) ) | |
import base32._ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait PartialType[T[_, _], A] { | |
type Apply[B] = T[A, B] | |
type Flip[B] = T[B, A] | |
} | |
trait Fluffy[F[_]] { | |
def furry[A, B](f: A => B, fa: F[A]): F[B] | |
} | |
object Fluffy { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Part Zero : 10:15 Saturday Night | |
* | |
* (In which we will see how to let the type system help you handle failure)... | |
* | |
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0) | |
*/ | |
import scalaz._ | |
import Scalaz._ |