This file contains 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 sbt._ | |
import Keys._ | |
object SinksBuild extends Build { | |
// Custom keys -- things don't work well if they are on .sbt files | |
lazy val scalazVersion = settingKey[String]("Scalaz Version") | |
lazy val scodecVersion = settingKey[String]("Scodec Version") | |
lazy val unfilteredVersion = settingKey[String]("Unfiltered Version") | |
lazy val scalacheckVersion = settingKey[String]("Scalacheck Version") | |
lazy val specs2Version = settingKey[String]("Specs2 Version") |
This file contains 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 Scalaz.{merge => _, _} | |
import scalaz.concurrent._ | |
import scalaz.stream._ | |
import scala.concurrent.duration._ | |
implicit val defaultScheduler = scalaz.stream.DefaultScheduler | |
val flag = async.signal[Boolean] | |
val reset = Process.eval(flag set true).drain |
This file contains 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
### Keybase proof | |
I hereby claim: | |
* I am dcsobral on github. | |
* I am dcsobral (https://keybase.io/dcsobral) on keybase. | |
* I have a public key whose fingerprint is C049 F080 3A32 FC38 4487 9042 5F35 D49A D3BE CD47 | |
To claim this, I am signing this object: |
This file contains 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> Jsoup.parse("<B>bold, <I>bould italic, </b>italic, </i>normal text") | |
res0: org.jsoup.nodes.Document = | |
<html> | |
<head></head> | |
<body> | |
<b>bold, <i>bould italic, </i></b> | |
<i>italic, </i>normal text | |
</body> | |
</html> |
This file contains 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 findLinks(body: String): Iterator[String] = { | |
val document = Jsoup.parse(body) | |
val links = document.select("a[href]") | |
for { | |
link <- links.iterator().asScala | |
} yield link.attr("href") | |
} |
This file contains 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
/** | |
* Replaces an expression with a REPL-like evaluation of it. For example, | |
* the expression `2 + 2` would be replaced with this: | |
* | |
* {{{ | |
* scala> 2 + 2 | |
* Int: 4 | |
* }}} | |
* | |
* Clients of REPLinator *must* be compiled with -Yrangepos, until and unless |
This file contains 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 Printer { | |
import scala.reflect.runtime.currentMirror | |
import scala.tools.reflect.ToolBox | |
val toolBox = currentMirror.mkToolBox() | |
def print(s: String) = { | |
val tree = toolBox parse s | |
val typedTree = toolBox typeCheck tree | |
val tpe = typedTree.tpe.widen | |
val result = toolBox eval tree |
This file contains 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
// At the external API level, use TypeTag | |
def extract[T: TypeTag](jsv: JsValue): T = | |
extractImpl[T](jsv, typeOf[T]) | |
// But use Type for everything else | |
def extractImpl[T](jsv: JsValue, tpe: Type): T = { | |
// no need for m | |
val ex = jsv match { | |
case JsNumber(n) => n | |
case JsString(s) => s |
This file contains 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> type T = List[String] | |
defined type alias T | |
scala> val tpe = implicitly[TypeTag[T]].tpe.normalize | |
tpe: reflect.runtime.universe.Type = List[String] | |
scala> val tpeSymbol = tpe.typeSymbol.asType | |
tpeSymbol: reflect.runtime.universe.TypeSymbol = class List | |
scala> val args = tpeSymbol.typeParams.map(_.asType.toTypeIn(tpe)) |
This file contains 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 com.youdevise.lofty | |
import org.specs2.mutable._ | |
import scala.language.dynamics | |
trait State[S, A] { | |
val runState: Function[S, (S, A)] | |
def flatMap[B](f: A => Function[S, (S, B)]):Function[S, (S, B)] = (state:S) => { | |
val (newState, value) = runState(state) | |
f(value)(newState) |