Skip to content

Instantly share code, notes, and snippets.

View oxbowlakes's full-sized avatar

Christopher Marshall oxbowlakes

View GitHub Profile
object OptionGolf {
import scalaz._
import Scalaz._
val moviel = Map("title" -> "South Park",
"user" -> "Terrence",
"rating" -> "3")
val incompleteMovie = Map("name" -> "Jaws")
@oxbowlakes
oxbowlakes / range.scala
Created December 6, 2010 22:28
Range class for ranges [a, b], (a, b), (a, b], [a, b) where (a and b) may be unbounded
package test
import scalaz._
import Scalaz._
import test.IRange.Increment
sealed trait Limit[+Z] {
def open : Boolean
def bound : Option[Z]
final def closed = !open
@oxbowlakes
oxbowlakes / 3nightclubs.scala
Created May 13, 2011 15:14
A Tale of 3 Nightclubs
/**
* 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._
@oxbowlakes
oxbowlakes / oxbow.xml
Created June 20, 2011 09:32
IntelliJ IDEA color scheme for Scala/Java
<?xml version="1.0" encoding="UTF-8"?>
<scheme name="oxbow" version="1" parent_scheme="Default">
<option name="LINE_SPACING" value="1.0" />
<option name="EDITOR_FONT_SIZE" value="12" />
<option name="EDITOR_FONT_NAME" value="Consolas" />
<colors />
<attributes>
<option name="ABSTRACT_CLASS_NAME_ATTRIBUTES">
<value>
<option name="FOREGROUND" value="666666" />
@oxbowlakes
oxbowlakes / ScalaSolarizedDark.xml
Created June 20, 2011 13:13
ScalaSolarizedDark.xml
<?xml version="1.0" encoding="UTF-8"?>
<scheme name="OxbowSolarizedDark" version="1" parent_scheme="Default">
<option name="LINE_SPACING" value="1.2" />
<option name="EDITOR_FONT_SIZE" value="13" />
<option name="EDITOR_FONT_NAME" value="Consolas" />
<colors>
<option name="ADDED_LINES_COLOR" value="" />
<option name="ANNOTATIONS_COLOR" value="2b36" />
<option name="ANNOTATIONS_MERGED_COLOR" value="" />
<option name="CARET_COLOR" value="dc322f" />
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) Server VM, Java 1.6.0_18).
Type in expressions to have them evaluated.
Type :help for more information.
scala> type Tagged[U] = { type Tag = U }
defined type alias Tagged
scala> type @@[T, U] = T with Tagged[U]
defined type alias $at$at
@oxbowlakes
oxbowlakes / gist:1869377
Created February 20, 2012 14:06
Simple scala collection examples
scala> (1 to 20).toList
res1: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
//Simple side effects
scala> res1 take 3 foreach (i => println(i))
1
2
3
scala> res1 take 3 foreach println
@oxbowlakes
oxbowlakes / scala-interview1.scala
Last active October 1, 2015 08:48
Scala interview questions
object GOption {
def some[A](a: A): GOption[A] = new GOption[A] {
def cata[B](n: => B, s: A => B): B = sys.error("Implement me")
}
def none[A]: GOption[A] = new GOption[A] {
def cata[B](n: => B, s: A => B): B = sys.error("Implement me")
}
}
trait GOption[+A] {
@oxbowlakes
oxbowlakes / scala-interview2.scala
Created March 2, 2012 12:08
Scala interview questions hard
trait MyList[+A] {
def fold[B](k: Option[(A, B)] => B): B
def map[B](f: A => B): MyList[B] = sys.error("Implement me in terms of fold")
def flatMap[B](f: A => MyList[B]): MyList[B] = sys.error("Implement me in terms of fold")
def headOption: Option[B] = sys.error("Implement me in terms of fold")
def tailOption: Option[MyList[B]] = sys.error("Implement me in terms of fold")
def isEmpty = sys.error("Implement me in terms of fold")
def length = sys.error("Implement me in terms of fold")
}
@oxbowlakes
oxbowlakes / imperial-fx.scala
Created March 13, 2012 12:52
FX Rate example
import java.util.Currency
object Fx {
type CcyPair = (Currency, Currency)
case class FxRate(from: Currency, to: Currency, rate: BigDecimal) {
def pair: CcyPair = from → to
def unary_~ = FxRate(to, from, 1 / rate)
def *(that: FxRate): FxRate = {
require(this.to == that.from)
FxRate(this.from, that.to, this.rate * that.rate)