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 OResult._ | |
case class OResult[A](x: Option[Result[A]]) { | |
def map[B](f: A => B): OResult[B] = | |
OResult(x map (_.right map f)) | |
def flatMap[B](f: A => OResult[B]): OResult[B] = | |
OResult(x flatMap { | |
case Left(_) => None | |
case Right(a) => f(a).x |
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
package wibbs | |
import scalaz._, Scalaz._ | |
final case class OptionT2[F[+_], +A](run: F[Option[A]]) { | |
def map[B](f: A => B)(implicit F: Functor[F]): OptionT2[F, B] = error("") // new OptionT2[F, B](mapO(_ map f)) | |
def flatMap[B](f: A => OptionT2[F, B])(implicit F: Monad[F]): OptionT2[F, B] = error("") /* new OptionT2[F, B]( | |
F.bind(self.run) { |
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
Jul 02 14:15:48 <nairb> is there a way to use match { case ....} that matches strings in a case-insensitive manner ? | |
Jul 02 14:18:12 * eneiry has quit (Quit: eneiry) | |
Jul 02 14:18:58 * bossskag has quit (Ping timeout: 246 seconds) | |
Jul 02 14:19:07 <dibblego> why would you match strings? | |
Jul 02 14:19:33 <Madoka-Kaname> nairb, string.toLower match { ... } | |
Jul 02 14:19:38 <nairb> because I want some kind of case statement? should I be using if/else instead? | |
Jul 02 14:19:42 <nairb> Madoka-Kaname: thanks | |
Jul 02 14:19:51 <dibblego> sounds deadly | |
Jul 02 14:20:13 <nairb> dibblego: do you have a better suggestion? I'm all ears. | |
Jul 02 14:20:17 <Madoka-Kaname> nairb, why do you want to do it? |
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
Jul 02 14:15:48 <nairb> is there a way to use match { case ....} that matches strings in a case-insensitive manner ? | |
Jul 02 14:18:12 * eneiry has quit (Quit: eneiry) | |
Jul 02 14:18:58 * bossskag has quit (Ping timeout: 246 seconds) | |
Jul 02 14:19:07 <dibblego> why would you match strings? | |
Jul 02 14:19:33 <Madoka-Kaname> nairb, string.toLower match { ... } | |
Jul 02 14:19:38 <nairb> because I want some kind of case statement? should I be using if/else instead? | |
Jul 02 14:19:42 <nairb> Madoka-Kaname: thanks | |
Jul 02 14:19:51 <dibblego> sounds deadly | |
Jul 02 14:20:13 <nairb> dibblego: do you have a better suggestion? I'm all ears. | |
Jul 02 14:20:17 <Madoka-Kaname> nairb, why do you want to do it? |
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 Functor[F[_]] | |
object Functor { | |
implicit val OptionFunctor: Functor[Option] = | |
error("") | |
} | |
case class OptionT[F[+_], +A] |
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 Control.Monad | |
import Control.Monad.ST | |
import Data.STRef | |
gcd :: | |
Integer | |
-> Integer | |
-> Integer | |
gcd a b = | |
runST $ |
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
object Applicative { | |
// pick any monad, I have picked Option for you | |
type F[A] = Option[A] | |
// Applicative primitive given concrete | |
// AKA point, pure, return | |
def lift0[A](a: A): F[A] = | |
Some(a) | |
// Applicative primitive given concrete |
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
tmorris@moron:~/work/scalaz (scalaz-seven)$ cat /home/tmorris/.sbt/plugins/build.sbt | |
resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/" | |
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.0.0") | |
tmorris@moron:~/work/scalaz (scalaz-seven)$ ./sbt gen-idea | |
Detected sbt version 0.12.0-RC4 | |
Using /home/tmorris/.sbt/0.12.0-RC4 as sbt dir, -sbt-dir to override. | |
[info] Loading project definition from /home/unencrypted/work/scalaz/project | |
[info] Set current project to scalaz (in build file:/home/unencrypted/work/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
$ cat /home/tmorris/.sbt/plugins/plugins.sbt && ./sbt gen-idea | |
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/" | |
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0-SNAPSHOT") | |
Detected sbt version 0.12.0-RC4 | |
Using /home/tmorris/.sbt/0.12.0-RC4 as sbt dir, -sbt-dir to override. | |
[info] Loading project definition from /home/unencrypted/work/scalaz/project | |
[info] Set current project to scalaz (in build file:/home/unencrypted/work/scalaz/) | |
[error] Not a valid command: gen-idea |
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
$ cat /home/tmorris/.sbt/plugins/plugins.sbt && ./sbt gen-idea | |
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0-SNAPSHOT", sbtVersion = "0.12") | |
Detected sbt version 0.12.0-RC4 | |
Using /home/tmorris/.sbt/0.12.0-RC4 as sbt dir, -sbt-dir to override. | |
[info] Loading project definition from /home/unencrypted/work/scalaz/project | |
[info] Set current project to scalaz (in build file:/home/unencrypted/work/scalaz/) | |
[error] Not a valid command: gen-idea | |
[error] Not a valid project ID: gen-idea | |
[error] Expected ':' |