Skip to content

Instantly share code, notes, and snippets.

View cyberzac's full-sized avatar

Martin Zachrison cyberzac

View GitHub Profile
@tlockney
tlockney / ImplicitExample.scala
Created February 23, 2011 03:49
Here's a very simplified example of hiding an implicit in a companion object
// initial version
import scala.collection.immutable.TreeSet
class TreeMember[A] {
// some really important stuff here, of course! ;~)
}
class Main {
implicit val treeOrder = new Ordering[TreeMember[A]] {
def compare(a: TreeMember[A], b: TreeMember[A]) = {
// elided for simplicity's sake
}
@unclebob
unclebob / prime_factors_test.clj
Created October 18, 2010 14:34
Prime factors Kata in Clojure
(ns prime-factors-test
(:use clojure.test midje.sweet))
(defn factors-starting-at [f n]
(cond
(> f (Math/sqrt n)) (if (= n 1) [] [n])
(= 0 (mod n f)) (cons f (factors-starting-at f (/ n f)))
:else (recur (inc f) n)))
(defn prime-factors-of [n]
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}