Created
December 11, 2011 13:36
-
-
Save halcat0x15a/1460657 to your computer and use it in GitHub Desktop.
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 ScalaChan[A](value: A) | |
implicit def ScalaChanEqual[A]: Equal[ScalaChan[A]] = equalA | |
implicit def ScalaChanShow[A]: Show[ScalaChan[A]] = showA | |
implicit lazy val ScalaChanFunctor: Functor[ScalaChan] = new Functor[ScalaChan] { | |
def fmap[A, B](a: ScalaChan[A], f: A => B): ScalaChan[B] = ScalaChan(f(a.value)) | |
} | |
implicit lazy val ScalaChanBind: Bind[ScalaChan] = new Bind[ScalaChan] { | |
def bind[A, B](a: ScalaChan[A], f: A => ScalaChan[B]): ScalaChan[B] = f(a.value) | |
} | |
implicit lazy val ScalaChanApply: Apply[ScalaChan] = FunctorBindApply | |
ScalaChan(100) <*> ScalaChan((_: Int) + 100) assert_=== ScalaChan(200) |
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".some <*> ((_: String) |+| "ちゃんかわいい").some assert_=== "Scalaちゃんかわいい".some | |
("Scala".some <**> none)(_ |+| _) assert_=== none | |
(3.right[String] <***> ("4".left, 6.right))(_ |+| _ |+| _) assert_=== "4".left |
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
List("Scalaちゃん") <|*|> List("イカ娘") assert_=== List(("Scalaちゃん", "イカ娘")) | |
List("Scala") <|**|> (nil[String], List("Scalaz")) assert_=== nil | |
'a'.right[Int] <|***|> ('b'.right[Int], 'c'.right[Int], 'd'.right[Int]) assert_=== ('a', 'b', 'c', 'd').right[Int] |
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
1.some <* 10.some assert_=== 1.some | |
none[Int] *> 10.some assert_=== none | |
1.right[String] *> 10.right[String] assert_=== 10.right[String] | |
1.right[String] <* "10".left[Int] assert_=== "10".left[Int] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment