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
// 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] { |
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.{ 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 |
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
// | |
// 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 |
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
/** | |
* 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 |
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 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) | |
} |
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
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 |
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
// 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 |
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
val one = Function.const(1)_ | |
one(2) assert_=== 1 | |
one("hoge") assert_=== 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
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" | |
) |
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
/** | |
* 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 { | |
OlderNewer