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
module Dist where | |
import System.Random | |
data Dist a = Dist { | |
support :: [a], | |
gen :: StdGen -> (a, StdGen), | |
expect :: (a -> Float) -> Float | |
} |
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._ | |
object distribMonad { | |
import Scalaz._ | |
import scala.util.Random | |
abstract class Dist[A] { | |
def support: List[A] | |
def gen: Random => (A, Random) |
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 Global[A](a: A, state: Int) { | |
def map[B](fun: A => B): Global[B] = Global(fun(a), state) | |
def flatMap[B](fun: A => Global[B]): Global[B] = fun(a) | |
override def toString = a.toString + " " + state | |
} | |
object Global { | |
def point[A](a: A): Global[A] = Global(a, 0) | |
} |
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 TupoIO[A](a: A, out: String) { | |
def map[B](fun: A => B): TupoIO[B] = TupoIO(fun(a), out) | |
def flatMap[B](fun: A => TupoIO[B]): TupoIO[B] = { | |
val res = fun(a) | |
TupoIO(res.a, out + res.out) | |
} | |
override def toString = out + a.toString | |
} | |
object TupoIO { |
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 TupoOI[A](a: A, inputs: Stream[String]) { | |
def copoint: A = a | |
def map[B](fun: A => B): TupoOI[B] = TupoOI(fun(a), inputs) | |
def coflatMap[B](fun: TupoOI[A] => B): TupoOI[B] = { | |
TupoOI(fun(this), inputs.tail) | |
} | |
override def toString = a.toString | |
} | |
object comonadTupoOI { |
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 skipLast[T](s: Stream[T], c: Int): Stream[T] = { | |
var buf = s take c | |
s drop c flatMap { x => | |
val h = if (!buf.isEmpty) | |
Stream(buf.head) else Stream() | |
buf = buf.drop(1) :+ x | |
h | |
} | |
} |
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.stream.nio.{file => nio} | |
import scodec.bits.ByteVector | |
... | |
val uuidSource: Process[Task, String] = | |
Process.repeatEval( | |
Task.delay( | |
// uuid creation | |
) |
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 shapeless._ | |
import shapeless.PolyDefns.~> | |
import shapeless.HList._ | |
object Test { | |
object size extends (Id ~> Const[Int]#λ) { | |
def apply[T](t : T) = 1 | |
} | |
implicit def sizeString = size.λ[String](s => s.length) |
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 argonaut._, Argonaut._, Shapeless._ | |
object Tool { | |
trait Enum { | |
type EnumVal <: Value | |
protected trait Value { self: EnumVal => | |
val name: 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
import scala.concurrent.Await | |
import scala.concurrent.duration._ | |
import monifu.reactive.Observable | |
import monifu.concurrent.Scheduler | |
class Monix { | |
val s1 = Scheduler.singleThread("test") | |
val s2 = Scheduler.computation(Runtime.getRuntime.availableProcessors()) |
OlderNewer