Skip to content

Instantly share code, notes, and snippets.

View 1ambda's full-sized avatar
🦁
in the jungle

Kun 1ambda

🦁
in the jungle
View GitHub Profile
@shajra
shajra / free1.scala
Last active August 29, 2015 14:03 — forked from danclien/step1.scala
// Implementing functor manually
import scalaz._, Scalaz._, Free.liftF
sealed trait TestF[+A]
case class Foo[A](o: A) extends TestF[A]
case class Bar[A](h: (Int => A)) extends TestF[A]
case class Baz[A](h: (Int => A)) extends TestF[A]
implicit def testFFunctor[B]: Functor[TestF] = new Functor[TestF] {
import scalaz.{ Free, Coyoneda, Monad, ~>, State, NonEmptyList }
import scalaz.std.function._
import scalaz.syntax.monad._
import scalaz.effect.IO
import scala.util.Random
object freecoyo extends App {
// An algebra of primitive operations in the context of a random number generator
@d-plaindoux
d-plaindoux / gist:6cf61856a137e3491d31
Last active August 29, 2015 14:19
Type Level programming
//
// From https://www.parleys.com/tutorial/type-level-programming-scala-101
//
import scala.language.higherKinds
// Int type programming level
sealed trait IntType {
type plus[that <: IntType] <: IntType
@kaizawa
kaizawa / TextFieldSample.scala
Created February 11, 2011 16:06
Sample code which listens to Enter key event on TextField
/**
* Sample code which listens to Enter key event on TextField
*/
package myscala
import scala.swing.BorderPanel
import scala.swing.Label
import scala.swing.MainFrame
import scala.swing.SimpleSwingApplication
import scala.swing.TextField
@derekwyatt
derekwyatt / ReceiveComp.scala
Created February 17, 2012 19:27
An experiment in receive method composition for Akka
trait ReceiveComposiingActor extends Actor {
trait Key
lazy val receivePartials = scala.collection.mutable.Map.empty[Key, Receive]
// Fronts 'context.become' to alter map before recomposition
def becomeNew(key: Key, behaviour: Receive) {
receivePartials += (key -> behaviour)
context.become(composeReceive)
}
@sassunt
sassunt / dispatch1.scala
Created February 19, 2012 13:10
dispatchの基本的な使い方
scala> import dispatch._
import dispatch._
scala> val req = :/("gist.github.com") / "1614046"
req: dispatch.Request = dispatch.Request@4e04622f
scala> req.host
res0: org.apache.http.HttpHost = http://gist.github.com
scala> req.path
@kenbot
kenbot / Hose.scala
Last active November 25, 2015 15:51
Garden Hoses as a Category in Scala
// Category
//
trait Category[Arrow[_,_]] {
def compose[A,B,C](c1: Arrow[B,C], c2: Arrow[A,B]): Arrow[A,C]
def id[A]: Arrow[A,A]
}
object Category {
implicit object FunctionCat extends Category[Function1] {
def compose[A,B,C](f: B => C, g: A => B): A => C = f compose g
val one = Function.const(1)_
one(2) assert_=== 1
one("hoge") assert_=== 1
@travisbrown
travisbrown / build.sbt
Last active December 20, 2015 09:09
Simple example of how to use Dispatch to access the Chronicling America API asynchronously.
scalaVersion := "2.10.2"
libraryDependencies ++= Seq(
"net.databinder.dispatch" %% "dispatch-core" % "0.11.0",
"net.databinder.dispatch" %% "dispatch-json4s-jackson" % "0.11.0",
"net.sf.opencsv" % "opencsv" % "2.0"
)
@xuwei-k
xuwei-k / Main.scala
Created September 8, 2013 09:20
Json4s Scalaz7 example
/**
* https://github.com/json4s/json4s/issues/39
*
* Validation Monad instance removed from Scalaz7.
* https://github.com/scalaz/scalaz/blob/v6.0.4/core/src/main/scala/scalaz/Validation.scala#L133-L147
*
* need explicitly convert to `scalaz.\/` (aka disjunction) if you want use the `Kleisli` composition
*/
object Main extends App {