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
//some nice but perhaps not so useful list operations | |
object ListOps { | |
//translated to Scala: http://www.haskell.org/pipermail/libraries/2010-July/013842.html | |
def select[T](l: List[T]): List[(T, List[T])] = l match { | |
case Nil => Nil | |
case x::xs => (x, xs) :: (for {(y, ys) <- select(xs)} yield (y, x::ys)) | |
} | |
def separate[T](l: List[T]): List[(List[T], T, List[T])] = l match { |
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 tails[T](l: List[T]): List[List[T]] = { | |
if (l.isEmpty) List(Nil) | |
else l :: tails(l.tail) | |
} | |
def comb[T](n: Int, l: List[T]): List[List[T]] = { | |
if (n == 0) List(Nil) else {for (xs <- tails(l) if !xs.isEmpty; ys <- comb(n - 1, xs.tail)) yield (xs.head :: ys)} | |
} |
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 sbt._ | |
import Keys._ | |
import Defaults._ | |
//adding the Artifacts.settings to you project settings will create and publish the artifact defined as 'theMainArtifact' | |
object Artifacts { | |
val allTheArtifacts = TaskKey[Seq[(sbt.Artifact, java.io.File)]]("all-artifacts") | |
val theMainArtifact = TaskKey[File]("zip-artifact", "Create zip with all library dependencies") | |
val artifactConf = config("Artifact") hide //use this to scope the create artifact to this config |
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 sbt._ | |
import sbt.Keys._ | |
object build extends Build { | |
lazy val generate = Project( | |
id = "source-gen", | |
base = file("."), | |
settings = Defaults.defaultSettings ++ generateSourceSettings | |
) | |
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> for (s <- stateT[Int, Option, String](i => Some(("aaa", i + 1)))) yield(s + "bbb") | |
res0: scalaz.StateT[Int,Option,java.lang.String] = scalaz.StateTs$$anon$1@4f837a5b | |
scala> res0.runT(10) | |
res31: Option[(java.lang.String, Int)] = Some((aaabbb,11)) |
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
"FingerTree" should { | |
"apply effects in order" in { | |
import std.string._ | |
import Id._ | |
type StringWriter[A] = Writer[String, A] | |
val s: Writer[String, FingerTree[Int, Int]] = streamToTree(intStream.take(5)).traverseTree[StringWriter, Int, Int](x => Writer(x.toString, x)) | |
val (w, a) = s.runT | |
(w, a.toStream) must be_===("12345", streamToTree(intStream.take(5)).toStream) | |
} | |
} |
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 GMap[+V] { | |
type P[+_] | |
val content: P[V] | |
} | |
trait GMapKey[K] { | |
type GM[+V] <: GMap[V] | |
def empty[V]: GM[V] | |
def lookup[V](k: K, m: GM[V]): Option[V] | |
def insert[V](k: K, v: V, m: GM[V]): GM[V] | |
} |
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 Semigroup_ { | |
type F | |
def append(a: F, b: => F): F | |
} | |
trait Monoid_ extends Semigroup_ { | |
def zero: F | |
} | |
trait Functor_ { |
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
{-# LANGUAGE FlexibleInstances #-} | |
import Data.Char | |
import Control.Monad | |
import Control.Exception | |
import Control.Monad.Trans | |
import System.IO |
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
#!/usr/bin/env bash | |
# This is very hacky remedy to following error people using sbt | |
# and 2.10.0-M1 release of Scala are going to see: | |
# | |
# API.scala:261: error: type mismatch; | |
# found : API.this.global.tpnme.NameType | |
# (which expands to) API.this.global.TypeName | |
# required: String | |
# sym.isLocalClass || sym.isAnonymousClass || sym.fullName.endsWith(LocalChild) | |
# |
OlderNewer