Skip to content

Instantly share code, notes, and snippets.

View tonymorris's full-sized avatar

Tony Morris tonymorris

View GitHub Profile
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
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) {
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?
@tonymorris
tonymorris / WaaWaa
Created July 20, 2012 04:46
nairb having a big fucking cry
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?
trait Functor[F[_]]
object Functor {
implicit val OptionFunctor: Functor[Option] =
error("")
}
case class OptionT[F[+_], +A]
@tonymorris
tonymorris / gist:3162693
Created July 23, 2012 08:55
gcs function using a while loop in haskell
import Control.Monad
import Control.Monad.ST
import Data.STRef
gcd ::
Integer
-> Integer
-> Integer
gcd a b =
runST $
@tonymorris
tonymorris / Applicative.scala
Created July 28, 2012 03:24
Applicative exercise
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
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/)
$ 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
$ 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 ':'