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
shellPrompt <<= name(name => { state: State => | |
object devnull extends ProcessLogger { | |
def info(s: => String) {} | |
def error(s: => String) { } | |
def buffer[T](f: => T): T = f | |
} | |
val current = """\*\s+(\w+)""".r | |
def gitBranches = ("git branch --no-color" lines_! devnull mkString) | |
"%s:%s>" format ( | |
name, |
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 examples | |
import org.specs2.mutable.Specification | |
import org.specs2.specification.{Before, Scope} | |
class BeforeWeirdnessSpec extends Specification { | |
"Before" should { | |
"execute before the example with a object" in context1 { | |
1 must_== 1 | |
} | |
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
// Since this link got passed around some, I'm going to paste here the | |
// versions made by sirthias. If you want to see the old ones, | |
// look up the history. | |
// Well, actually, these are non-pimped versions. See the comments to | |
// a link where they are provided as pimped methods on String. | |
import scala.annotation.tailrec | |
def fastSplit(s: String, delimiter: Char): List[String] = { |
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
/** | |
* A silly example using Kleisli composition of DB operations | |
* Based on an idea from Runar Bjarnason found here: | |
* https://groups.google.com/d/msg/scala-debate/xYlUlQAnkmE/FteqYKgo2zUJ | |
* | |
* Uses Scalaz7 | |
* | |
* @author <a href="mailto:jim@corruptmemory.com">Jim Powers</a> | |
*/ | |
object Monadic { |
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 necsala.embedded | |
import scala.tools.nsc.interpreter.AbstractFileClassLoader | |
import scala.tools.nsc.{Global, Settings} | |
import scala.tools.nsc.util.BatchSourceFile | |
import scala.tools.nsc.io.{AbstractFile, VirtualDirectory} | |
import java.io.File | |
import java.util.jar.JarFile | |
import java.net.URLClassLoader |
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
trait Bind[M[_]] { | |
def fmap[A, B](ma: M[A], f: A => B): M[B] | |
def bind[A, B](ma: M[A], f: A => M[B]): M[B] | |
} | |
trait Monad[M[_]] extends Bind[M]{ | |
def unit[A](a: => A): M[A] |
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
case class Config(host: String, port: Int) { | |
def prettyPrint(prefix: String, msg: String): String = | |
List(prefix, ": ", msg, " on ", host, ":", port.toString).mkString | |
} | |
/** | |
* Passing a configuration with implicits is like | |
* working in the state monad. You can "put" a | |
* new configuration even though we don't want that | |
* to happen in this particular example. We don't |
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 scala.xml.NodeSeq | |
object RenderExample { | |
object Model { | |
trait Toy | |
case class Bike extends Toy | |
case class Train extends Toy |
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
#!/bin/bash | |
echo "Direct dependencies" | |
sbt 'show all-dependencies' | \ | |
gawk 'match($0, /List\((.*)\)/, a) {print a[1]}' | \ | |
tr -d ' ' | tr ',' '\n' | sort -t ':' | \ | |
tr ':' '\t' | expand -t 30 | |
echo -e "\nAll dependencies, including transitive dependencies" | |
sbt 'show managed-classpath' | tr -d ' ' | tr ',' '\n' | \ |
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 SKI_Applicative { | |
/* | |
First, let's talk about the SK combinator calculus and how it contributes to solving your problem. | |
The SK combinator calculus is made of two functions (aka combinators): S and K. It is sometimes called the SKI combinator calculus, however, the I combinator can be derived from S and K. The key observation of SK is that it is a turing-complete system and therefore, anything that can be expressed as SK is also turing-complete. Here is a demonstration that Scala's type system is turing-complete (and therefore, undecidable) for example[1]. | |
The K combinator is the most trivial of the two. It is sometimes called "const" (as in Haskell). There is also some discussion about its evaluation strategy in Scala and how to best express it[2]. The K function might be paraphrased as, "takes a value and returns a (constant) unary function that always returns that value." | |
*/ | |
def k[A, B]: A => B => A = | |
a => _ => a |
OlderNewer