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
object OptionGolf { | |
import scalaz._ | |
import Scalaz._ | |
val moviel = Map("title" -> "South Park", | |
"user" -> "Terrence", | |
"rating" -> "3") | |
val incompleteMovie = Map("name" -> "Jaws") |
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
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 |
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._ |
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
<?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" /> |
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
<?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" /> |
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
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 |
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> (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 |
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
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] { |
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 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") | |
} |
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
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) |
OlderNewer