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
| private def color(node: Node, attr: String): Seq[Int] = { | |
| val a = """#(.{2})(.{2})(.{2})""".r | |
| val b = """#(.)(.)(.)""".r | |
| val c = """rgb\((\d+)\,(\d+)\,(\d+)\)""".r | |
| val d = """rgb\((\d+)%\,(\d+)%\,(\d+)%\)""".r | |
| node.attribute(attr) map (_.text) orElse { | |
| (node.attribute("style") map { style => | |
| style.text.split(";") find (_.contains(attr)) map { str => | |
| str.trim.split(":").last | |
| } |
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
| (defmacro sfn [params expr] | |
| `(proxy [~(symbol (str "scala.Function" (count params)))] [] | |
| (apply ~params | |
| ~expr))) |
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 json | |
| sealed abstract class JValue[+A](value: A) | |
| case class JString(value: String) extends JValue(value) { | |
| override def toString = "\"" + value + "\"" | |
| } |
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 AbstractList | |
| trait Cons[X, XS <: AbstractList] extends AbstractList | |
| trait Nil extends AbstractList | |
| type TypeList = List[Manifest[_]] | |
| def typeList[A <: AbstractList: Manifest]: TypeList = { | |
| lazy val typeList: PartialFunction[TypeList, TypeList] = { |
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 scalaz._ | |
| import effects._ | |
| import Scalaz._ | |
| val i = for { | |
| _ <- putStrLn("Greetings! What is your name?") | |
| inpStr <- readLn | |
| outStr = "Welcome to Scalaz, " |+| inpStr |+| "!" | |
| _ <- putStrLn(outStr) | |
| } yield () |
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
| sealed trait StreamG[+E] | |
| case class Empty[E]() extends StreamG[E] | |
| case class El[E](el: E) extends StreamG[E] | |
| case class EOF[E]() extends StreamG[E] | |
| sealed trait IterV[+E, +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
| sealed trait StreamG[+E] | |
| case object Empty extends StreamG[Nothing] | |
| case class El[E](el: E) extends StreamG[E] | |
| case object EOF extends StreamG[Nothing] | |
| sealed trait IterV[+E, +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
| (use '[clojure.string :only (join split capitalize)]) | |
| (defn split-hyphen [string] | |
| (split string #"\-")) | |
| (defn upper-camel [string] | |
| (join (map capitalize (split-hyphen string)))) | |
| (defn lower-camel [string] | |
| (let [strings (split-hyphen string)] |
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.io._ | |
| import scala.io._ | |
| import scalaz._ | |
| import Scalaz._ | |
| import effects._ | |
| import IterV._ | |
| object A extends App { | |
| val PairRegex = """(\d+) (\d+)""".r |
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
| def putStrLn[E: Show]: IterV[E, IO[Unit]] = { | |
| def step(i: IO[Unit])(input: Input[E]): IterV[E, IO[Unit]] = | |
| input(el = e => Cont(step(i >|> effects.putStrLn(e.shows))), | |
| empty = Cont(step(i)), | |
| eof = Done(i, EOF[E])) | |
| Cont(step(mzero[IO[Unit]])) | |
| } |
OlderNewer