Created
December 3, 2011 01:51
-
-
Save halcat0x15a/1425709 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
def check[A: Equal: Show: Monoid](a: A) = { | |
a |+| mzero[A] assert_=== a | |
mzero[A] |+| a assert_=== a | |
} | |
check(1) | |
check("Scalaz") | |
check(List(1, 2, 3)) | |
check(Ikamusume()) |
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 Ikamusume(syokusyu: Int = 10) | |
implicit def IkamusumeEqual: Equal[Ikamusume] = equalA | |
implicit def IkamusumeShow: Show[Ikamusume] = shows("ゲソ" * _.syokusyu) | |
implicit def IkamusumeSemigroup: Semigroup[Ikamusume] = semigroup(_.syokusyu + _.syokusyu |> Ikamusume) | |
(Ikamusume() |+| Ikamusume()).shows assert_=== "ゲソゲソゲソゲソゲソゲソゲソゲソゲソゲソゲソゲソゲソゲソゲソゲソゲソゲソゲソゲソ" |
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 |+| 1 assert_=== 2 | |
List(1) |+| List(1) assert_=== List(1, 1) | |
"Hello" |+| "World" assert_=== "HelloWorld" | |
1.some |+| 1.some assert_=== 2.some | |
false |+| true assert_=== true | |
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(name: String = "Scalaちゃん") | |
implicit def ScalaChanShow: Show[ScalaChan] = show(_.name.toList) | |
implicit def ScalaChanShow: Show[ScalaChan] = shows(_.name) | |
ScalaChan().shows assert_=== "Scalaちゃん" | |
case class Ikamusume() { override def toString = "イカちゃん" } | |
implicit def IkamusumeShow: Show[Ikamusume] = showA | |
Ikamusume().shows assert_=== "イカちゃん" | |
implicit def SomeShow[A: Show]: Show[Some[A]] = showBy(s => (s: Option[A])) | |
Some(1).shows assert_=== "Some(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
"Scalaz".show assert_=== List('S', 'c', 'a', 'l', 'a', 'z') | |
"Scalaz".shows assert_=== "Scalaz" | |
346.shows assert_=== "346" |
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> 1.print | |
1 | |
scala> "Scalaz".println | |
Scalaz | |
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
implicit def ElemShow: Show[xml.Elem] = showA | |
<scala>{ "Scalaちゃん".text }</scala> assert_=== <scala>Scalaちゃん</scala> |
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
mzero[Int] assert_=== 0 | |
mzero[String] assert_=== "" | |
mzero[List[Int]] assert_=== nil[Int] | |
mzero[Option[Int]] assert_=== none[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
implicit def IkamusumeZero: Zero[Ikamusume] = zero(Ikamusume(0)) | |
mzero[Ikamusume].shows assert_=== "" |
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
lazy val geso: Option[Int] => String = _.matchOrZero { | |
case Some(n) => "ゲソ" * n | |
} | |
geso(2.some) assert_=== "ゲソゲソ" | |
geso(none) assert_=== "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment