I hereby claim:
- I am eamelink on github.
- I am eamelink (https://keybase.io/eamelink) on keybase.
- I have a public key whose fingerprint is 038D FFCD 9C91 3710 F92A 909D 1358 5D54 8BCA 0616
To claim this, I am signing this object:
import scala.annotation.tailrec | |
object Trampolines { | |
// This is the regular one, and it stack overflows at a couple of 100k input. | |
object Stack { | |
def even(i: Int): Boolean = i match { | |
case 0 => true | |
case other => odd(i - 1) | |
} |
object MyApp extends App { | |
// The type class we use in all examples | |
trait Show[A] { | |
def show(a: A): String | |
} | |
implicit val StringShow = new Show[String] { def show(a: String) = "String(" + a + ")" } | |
implicit val IntShow = new Show[Int] { def show(a: Int) = "Int(" + a.toString + ")" } |
import scala.concurrent.Future | |
object either { | |
// Scala standard library Either is sometimes used to distinguish between 'failure' and 'success' state. Like these two methods: | |
def getUser(id: String): Either[String, User] = ??? | |
def getPreferences(user: User): Either[String, Preferences] = ??? | |
// The Right side contains the success value by convention, because right is right, right? |
// Sane implementation of findAndModify: | |
findAndModify(update: Record => Record, new: Record) { | |
getOld match { | |
case None => save(new) | |
case Some(oldRecord) => save(update(oldRecord)) | |
} | |
} | |
// MongodDb implementation of findAndModify: | |
findAndModify(update: Record => Record, new: Record, always: Record) { |
module Main where | |
import Debug.Trace | |
import Control.Monad.RWS | |
import Control.Monad.RWS.Class | |
import Control.Monad.RWS.Trans | |
import Control.Monad.Identity | |
import Data.Monoid | |
import Data.Tuple |
val a, b, c: Future[Try[String]] = ??? | |
val out = for { | |
_ <- a.map(t => \/.fromTryCatch(t.get).leftMap(ex => "Error!")) |> EitherT.apply | |
_ <- b.map(t => \/.fromTryCatch(t.get).leftMap(ex => "Error 2!")) |> EitherT.apply | |
_ <- c.map(t => \/.fromTryCatch(t.get).leftMap(ex => "Error 3!")) |> EitherT.apply | |
} yield () | |
val result: Future[String \/ Unit] = out.run |
I hereby claim:
To claim this, I am signing this object:
// Ruby | |
def test | |
yield 5 | |
puts "You are in the method test" | |
yield 100 | |
end | |
test {|i| puts "You are in the block #{i}"} | |
// Scala | |
def test(fn: (Int) => ()) { |
class SimpleFile | |
class ExtendedFile extends SimpleFile | |
implicit class Predicate[-A](val fn: A => Boolean) { | |
def &&[B <: A](other: Predicate[B]): Predicate[B] = Predicate { (x: B) => | |
fn(x) && other.fn(x) | |
} | |
} |
module HelloWorld where | |
import Data.Either | |
import Prelude | |
import Data.Foreign | |
import Control.Monad.Eff | |
import qualified Control.Monad.JQuery as J | |
import Debug.Trace | |
main = J.ready $ do |