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 com.jamesmaggs.monads | |
trait Identity[A] { self => | |
def run: A | |
def map[B](f: A => B): Identity[B] = | |
new Identity[B] { def run = f(self.run) } | |
def flatMap[B](f: A => Identity[B]): Identity[B] = |
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
case class Foo[+A](p: A => Boolean) { | |
def contains[B >: A](b: B): Boolean = p(b) | |
} |
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 org.example | |
case class PimpMyPredicate[A](f: A => Boolean) { | |
def &&(g: A => Boolean): A => Boolean = a => g(a) && f(a) | |
} | |
object PimpMyPredicate { | |
implicit def enrichPredicate[A](f: A => Boolean): PimpMyPredicate[A] = PimpMyPredicate(f) | |
} |
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
object CPS { | |
def chainCps[A, B, R](f: ((A => R) => R), g: (A => ((B => R) => R))): (B => R) => R = | |
(h: B => R) => f(a => g(a)(h)) | |
} |
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 org.example | |
import scala.annotation.tailrec | |
object Mapper { | |
@tailrec | |
def foldLeft[A, B](as: List[A], z: B)(f: (B, A) => B): B = as match { | |
case Nil => z | |
case a :: as => foldLeft(as, f(z, a))(f) |
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 com.example | |
class GrandParent | |
class Parent extends GrandParent | |
class Child extends Parent | |
/* | |
* contravariant parameter p | |
* covariant result r | |
*/ |
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
require 'sinatra' | |
require 'warden' | |
class User | |
def initialize(id = nil) | |
@id = id | |
end | |
def self.find_by_username(username) |
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
<html> | |
<head> | |
<title>Random Colors</title> | |
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script> | |
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script> | |
<style type="text/css"> | |
body { | |
margin: 0; | |
} |