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 ExistentialTest { | |
case class Box[T]() | |
case class Pair[T](a: Box[T], b: Box[T]) | |
val pair: Pair[_] = ??? | |
val pair2 = Pair(pair.a, pair.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
module Main where | |
{- | |
Warning: This is not an example of something you should ever do. | |
This is an academic excercise to scratch an itch. | |
Every single line of this file is morally wrong and violates all that | |
is good and holy in the world. | |
-} |
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 IO { | |
// We construct the IO type with a thunk/callback that returns the value when called | |
constructor( fn ){ | |
this.fn = fn; | |
} | |
// IO doesn't do anything until we explicitly call it. | |
run(){ | |
return this.fn(); |
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
/* Very basic promise implementation */ | |
class Promise { | |
observers: []; | |
value: T; | |
resolved: Boolean; | |
constructor(){ | |
this.observers = []; |
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
Routing from east coast Australia to Softlayer... via Perth? (Wrong side of the country!) | |
traceroute to softlayer.com (66.228.119.72), 30 hops max, 60 byte packets | |
1 192.168.1.1 (192.168.1.1) 0.316 ms 0.300 ms 1.897 ms | |
2 gw101.cha24.brisbane.telstra.net (203.45.253.1) 3.279 ms 3.462 ms 3.583 ms | |
3 tengige0-8-0-2.woo-core1.brisbane.telstra.net (203.50.51.129) 12.150 ms 12.159 ms 12.197 ms | |
4 bundle-ether11.chw-core10.sydney.telstra.net (203.50.11.70) 17.636 ms 18.027 ms 18.152 ms | |
5 bundle-ether8.exi-core10.melbourne.telstra.net (203.50.11.125) 36.428 ms 36.436 ms 36.434 ms | |
6 bundle-ether5.way-core4.adelaide.telstra.net (203.50.11.92) 45.297 ms 58.743 ms 59.433 ms | |
7 bundle-ether5.pie-core1.perth.telstra.net (203.50.11.17) 86.472 ms 86.906 ms 86.907 ms |
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._ | |
sealed trait Action | |
case class Insert(ids:Seq[Int]) extends Action | |
case class Update(ids:Seq[Int]) extends Action | |
case class Delete(ids:Seq[Int]) extends Action | |
object Test extends App { |
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._ | |
def bench[T](fn: => T):(T,Long) = { | |
val start = System.currentTimeMillis() | |
val result = fn | |
val end = System.currentTimeMillis() | |
(result, end - start) | |
} | |
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
var bob = Bacon.Model({ | |
name: "Bob", | |
age: 30 | |
}); | |
console.log( bob.lens("name").get() ); // "Bob" as expected | |
Bacon.constant(1).onValue(function(){ | |
console.log( bob.lens("name").get() ); // Undefined | |
}); |
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
moment.parseInTz = function () { | |
var args = [], i, len = arguments.length - 1; | |
for (i = 0; i < len; i++) { | |
args[i] = arguments[i]; | |
} | |
var m = moment.apply(null, args); | |
var preTzOffset = m.zone(); | |
m.tz(arguments[len]); | |
return m.add('minutes', m.zone() - preTzOffset); | |
}; |
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
def fib( n: Long ):Long = { | |
def fib_tailrec( n:Long, a:Long, b:Long ):Long = { | |
n match { | |
case 0 => a | |
case _ => fib_tailrec( n - 1, b, a + b ) | |
} | |
} | |
fib_tailrec(n, 0, 1) | |
} |
NewerOlder