Created
December 15, 2011 13:49
-
-
Save halcat0x15a/1481143 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
implicit lazy val IkamusumeEach: Each[Ikamusume] = new Each[Ikamusume] { | |
def each[A](e: Ikamusume[A], f: A => Unit): Unit = e.value.foreach(f) | |
} | |
Ikamusume(2, 3, 5, 7, 11).foreach(print) | |
Ikamusume(1, 1, 2, 3, 5) |>| print | |
scala> implicit lazy val IkamusumeEach: Each[Ikamusume] = new Each[Ikamusume] { | |
| def each[A](e: Ikamusume[A], f: A => Unit): Unit = e.value.foreach(f) | |
| } | |
IkamusumeEach: scalaz.Each[Ikamusume] = <lazy> | |
scala> Ikamusume(2, 3, 5, 7, 11).foreach(print) | |
235711 | |
scala> Ikamusume(1, 1, 2, 3, 5) |>| print | |
11235 |
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 lazy val IkamusumeEmpty: Empty[Ikamusume] = new Empty[Ikamusume] { | |
def empty[A]: Ikamusume[A] = Ikamusume[A]() | |
} | |
<∅>[List, Int] assert_=== nil[Int] | |
<∅>[Ikamusume, Int] assert_=== Ikamusume[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 lazy val IkamusumeIndex: Index[Ikamusume] = new Index[Ikamusume] { | |
def index[A](a: Ikamusume[A], i: Int): Option[A] = (i == 0).option(a.value) | |
} | |
Ikamusume(0) | |
nel('Scala, 'Scalaz).index(1) assert_=== Some('Scalaz) | |
nil[Int].index(2) assert_=== None | |
nel(3, 4, 6).index_!(0) assert_=== 3 | |
'z'.some -!- 0 assert_=== 'z' |
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
nel(1, 2, 3) <---> nel(1, 2, 3) assert_=== 0 | |
nel(1, 2, 3) <---> nel(1, 2, 4) assert_=== 1 | |
nel(1, 2, 3) <---> nel(4, 5, 6) assert_=== 3 | |
nel(1, 2, 3) <---> nel(3, 2, 1) assert_=== 2 | |
nel(1) <---> nel(1, 2, 3, 4, 5) assert_=== 4 | |
1.some <---> none 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
case class Ikamusume[A](value: A*) | |
implicit def IkamusumeEqual[A]: Equal[Ikamusume[A]] = equalA | |
implicit def IkamusumeShow[A]: Show[Ikamusume[A]] = shows(Function.const("イカ娘")) | |
implicit lazy val IkamusumeLength: Length[Ikamusume] = new Length[Ikamusume] { | |
def len[A](a: Ikamusume[A]): Int = 10 | |
} | |
List('a, 'b, 'c).len assert_=== 3 | |
Ikamusume("ゲソ!").len assert_=== 10 |
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 lazy val IkamusumePlus: Plus[Ikamusume] = new Plus[Ikamusume] { | |
def plus[A](a1: Ikamusume[A], a2: => Ikamusume[A]): Ikamusume[A] = Ikamusume(a1.value ++ a2.value: _*) | |
} | |
Ikamusume('Scala) <+> Ikamusume('Scalaz) assert_=== Ikamusume('Scala, 'Scalaz) | |
nel(1, 2, 3) <+> nel(4, 5, 6) assert_=== NonEmptyList(1, 2, 3, 4, 5, 6) | |
1.some <+> 2.some assert_=== Some(1) | |
none <+> 1.some assert_=== Some(1) | |
"Scalaz".left[Int] <+> 100.right[String] assert_=== Right(100) | |
"Scalaz".left[Int] <+> "Scala".left[Int] assert_=== Left("Scalaz") | |
1 <+>: nel(2, 3) assert_=== NonEmptyList(1, 2, 3) | |
'a' <+>: 'z'.some assert_=== Some('a') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment