This file contains hidden or 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 MyOption[+A] { | |
| // single abstract method | |
| def cata[X](some: A => X, none: => X): X | |
| def map[B](f: A => B): MyOption[B] = error("todo") | |
| def flatMap[B](f: A => MyOption[B]): MyOption[B] = error("todo") | |
| def getOrElse[AA >: A](e: => AA): AA = error("todo") | |
This file contains hidden or 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
| package maybe | |
| sealed trait Maybe[A] { | |
| def isEmpty: Boolean | |
| } | |
| case class Just[A](a: A) extends Maybe[A] { | |
| override final def isEmpty = true | |
| } |
This file contains hidden or 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
| ❯ date -d "9 fortnights ago" | |
| Wed Apr 2 21:46:42 EDT 2014 | |
| ❯ date -d "9.5 fortnights ago" | |
| date: invalid date ‘9.5 fortnights ago’ | |
This file contains hidden or 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
| Changes from HEAD to working tree | |
| 2 files changed, 19 insertions(+), 10 deletions(-) | |
| core/src/main/scala/scalaz/IList.scala | 16 ++++++++++------ | |
| core/src/main/scala/scalaz/Maybe.scala | 13 +++++++++---- | |
| Modified core/src/main/scala/scalaz/IList.scala | |
| diff --git a/core/src/main/scala/scalaz/IList.scala b/core/src/main/scala/scalaz/IList.scala | |
| index 946ad98..7e383c7 100644 | |
| --- a/core/src/main/scala/scalaz/IList.scala | |
| +++ b/core/src/main/scala/scalaz/IList.scala |
This file contains hidden or 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
| class Auths[F[_]](implicit I: Inject[Auth,F]) { | |
| def login(id: UserId, pwd: Password): FreeC[F,Option[User]] = | |
| lift(Login(id, pwd)) | |
| def hasPermission(u: User, p: Permission): FreeC[F,Boolean] = | |
| lift(HasPermission(u, p)) | |
| type AuthCoyo[A] = Coyoneda[F, A] | |
| type AuthFree[A] = Free[AuthCoyo, A] | |
| def point[A](a: ⇒ A): Free.FreeC[F, A] = Monad[AuthFree].point(a) | |
| } |
This file contains hidden or 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._, Scalaz._ | |
| object Main { | |
| trait A | |
| trait B | |
| trait AB extends A with B | |
| type ReadA[T] = Reader[A, T] | |
| type ReadB[T] = Reader[B, T] | |
| type ReadAB[T] = Reader[AB, T] |
This file contains hidden or 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
| module monoidy | |
| %default total | |
| class Monoidy a where | |
| mempty : a | |
| mappend : a -> a -> a | |
| left_neutrality : (x : a) -> (mappend mempty x = x) | |
| right_neutrality : (x : a) -> (mappend x mempty = x) | |
| associativity : (x, y, z : a) -> (mappend x (mappend y z) = mappend (mappend x y) z) |
This file contains hidden or 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._ | |
| import Scalaz._ | |
| object Main extends App { | |
| // two lists we'll be traversing | |
| val nonRepeating = List(1,2,3,4) | |
| val repeating = List(1,2,3,3,4) | |
| // so we can use state to traverse a list |
This file contains hidden or 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._ | |
| import Scalaz._ | |
| object Main extends App { | |
| def foo[A](list: List[Option[Int]]): Int = { | |
| implicit def plus[A] = new ApplicativePlus[({type λ[A]=Int})#λ] { | |
| def empty[A] = 0 | |
| def plus[A](a: Int, b: ⇒ Int) = a + b | |
| def point[A](a: ⇒ A) = a.asInstanceOf[Int] | |
| def ap[A, B](fa: => Int)(f: => Int): Int = 0 |
This file contains hidden or 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
| java.lang.StackOverflowError | |
| at scalaz.syntax.ShowOps.<init>(ShowSyntax.scala:5) | |
| at scalaz.syntax.ToShowOps$class.ToShowOps(ShowSyntax.scala:16) | |
| at scalaz.Scalaz$.ToShowOps(Scalaz.scala:3) | |
| at scalaz.example.CABRunLengthEncoder$.writeOutput(ReaderWriterStateTUsage.scala:143) | |
| at scalaz.example.CABRunLengthEncoder$$anonfun$emit$1$$anonfun$apply$7$$anonfun$4.apply(ReaderWriterStateTUsage.scala:154) | |
| at scalaz.example.CABRunLengthEncoder$$anonfun$emit$1$$anonfun$apply$7$$anonfun$4.apply(ReaderWriterStateTUsage.scala:154) | |
| at scalaz.std.OptionFunctions$class.cata(Option.scala:179) | |
| at scalaz.std.option$.cata(Option.scala:231) | |
| at scalaz.syntax.std.OptionOps.cata(OptionOps.scala:9) |