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
{-# LANGUAGE RankNTypes #-} | |
newtype State s a = State { runState :: forall r. s -> (a -> s -> r) -> r } | |
stateReturn :: a -> State s a | |
stateReturn = undefined | |
stateMap :: (a -> b) -> State s a -> State s b | |
stateMap = undefined |
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
{-# LANGUAGE RankNTypes #-} | |
newtype State s a = State { runState :: forall r. s -> (a -> s -> r) -> r } | |
stateReturn :: a -> State s a | |
stateReturn a = State $ \s k -> k a s | |
stateMap :: (a -> b) -> State s a -> State s b | |
stateMap f (State sa) = State $ \s kb -> sa s (kb . f) |
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
exports.Person = function(firstName,lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
}; |
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._ | |
import scalaz.iteratee._ | |
import EnumeratorT._ | |
def counter[A, F[+_]: Pointed] = | |
IterateeT.fold[A, F, Int](0) { (acc: Int, a: A) => acc + 1 } | |
def count[A, F[+_]: Monad](e: EnumeratorT[A, F]) = | |
(counter[A, F] &= e).run |
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
sealed trait KeyValueStore[+A] { | |
def map[B](f: A => B): KeyValueStore[B] = | |
this match { | |
case Put(k, v, q) => Put(k, v, f compose q) | |
case Get(k, q) => Get(k, f compose q) | |
case Del(k, q) => Del(k, f compose q) | |
} | |
} | |
case class Put[A](k: String, v: String, q: Option[String] => A) extends KeyValueStore[A] | |
case class Get[A](k: String, q: Option[String] => A) extends KeyValueStore[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
source "http://rubygems.org" | |
gem "guard-shell" | |
gem "rake" |
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
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> import shapeless._ | |
import shapeless._ | |
scala> import syntax.tuple._ | |
import syntax.tuple._ |
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
/* discovered njoin on this thread: https://github.com/functional-streams-for-scala/fs2/issues/251 - which also cites (adjusted to match example below): | |
If we increase maxQueued up to 100, and `handle` emits multiple `A` values, up to 100 will be prefetched | |
before we block on the consumer of results. (Not actually blocking by occupying a thread, but semantically blocking.) | |
If we increase maxOpen to 50, then we can have 50 `item` streams processing concurrently. | |
*/ | |
import scalaz.stream.{Sink,Process,sink,channel} | |
import scalaz.stream.nondeterminism.njoin |
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
// An ADT+shapeless as a drop-in replacement for a standard Scala Enumeration. | |
// | |
// First the unsafe standard Scala Enumeration ... | |
// | |
object ScalaEnumDemo extends App { | |
// Example from scala.Enumeration scaladoc. Terse ... | |
object WeekDay extends Enumeration { | |
type WeekDay = Value | |
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value | |
} |
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
# Upgrade to OS X Lion, notice your virtualenvs are all hosed. | |
# Install Xcode 4.1 from the app store (or //fs2/IT/Apple/). | |
# Make sure to actually *run* the install, it's an app inside Applications. Throw it away afterwards, if you want the space back. | |
sudo easy_install pip | |
sudo pip install virtualenv virtualenvwrapper ipython | |
# blow the old one(s) away | |
rmvirtualenv playdoh |
OlderNewer