Skip to content

Instantly share code, notes, and snippets.

@setrar
setrar / TryMonad.scala
Created May 20, 2015 04:04
A monad is a parametric type MT with two operations: flatMap and unit.
trait M[T] {
def flatMap[U](f: T => M[U]) : M[U]
def unit[T](x: T) : M[T]
}
// Example using Try Monad
import scala.util.Try
@setrar
setrar / gist:77fc1c301266afde9f7f
Last active August 29, 2015 14:03
Water pouring problem in Scala
package week7
// Rearranged from https://class.coursera.org/progfun-004
// Water pouring problem - CS212 Unit 4 - Udacity
// http://www.youtube.com/watch?v=q6M_pco_5Vo
class WaterPouring(capacities: Vector[Int]) {
/*
* Inventory
*/