This file contains 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
(defn fib [n] | |
(if (< n 2) | |
n | |
(+ (fib (- n 1)) | |
(fib (- n 2))))) | |
(time | |
(doseq [n (range 40)] | |
(prn (format "Fib(%s) = %s" n (fib n))))) |
This file contains 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
public static IProcessorWithContext<TInputData, TOutputData, TContext> Combine | |
<TInputData, TIntermediateData, TOutputData, TContext>( | |
this IProcessorWithContext<TInputData, TIntermediateData, TContext> first, | |
IProcessorWithContext<TIntermediateData, TOutputData, TContext> second) | |
{ | |
return new ProcessorWithContextCombinator<TInputData, TIntermediateData, TOutputData, TContext>(first, second); | |
} |
This file contains 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
(defrecord Order [price]) | |
;; protocol | |
(defprotocol Calculable | |
(p-total [this])) | |
(extend-protocol Calculable | |
Order | |
(p-total [order] (:price order)) |
This file contains 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
created 20000000 orders. | |
Elapsed time: 363.78375 msecs | |
protocol done. | |
Elapsed time: 1280.251512 msecs | |
multimethod done. |
This file contains 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
(defmacro >> [& [first-expr & rest-exprs]] | |
(if (empty? rest-exprs) | |
first-expr | |
`(let [~'it ~first-expr] | |
(thread-it ~@rest-exprs)))) | |
(>> | |
[jay john mike chris] | |
(filter (comp (partial = "new york") :current-city) it) | |
(group-by :employer it) |
This file contains 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
(defmacro thread-it [& [first-expr & rest-exprs]] | |
(if (empty? rest-exprs) | |
first-expr | |
`(let [~'it ~first-expr] | |
(thread-it ~@rest-exprs)))) | |
(def jay {:name "jay fields" :employer "drw.com" :current-city "new york"}) | |
(def john {:name "john dydo" :employer "drw.com" :current-city "new york"}) | |
(def mike {:name "mike ward" :employer "drw.com" :current-city "chicago"}) | |
(def chris {:name "chris george" :employer "thoughtworks.com" :current-city "new york"}) |
This file contains 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
type Maybe() = | |
member __.Bind(value, rest) = | |
if value = null then null else rest value | |
member __.Return(value) = | |
value | |
let maybe = new Maybe() | |
let substring (str: string) (from: int) = |
This file contains 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
type StatefulFunc<'state, 'result> = StatefulFunc of ('state -> 'result * 'state) | |
let Run (StatefulFunc f) initialState = f initialState | |
// what the hell (StatefulFunc f) means here?.. |
This file contains 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
let makeChange amount = | |
let rec doChange amount soFar coins = | |
match coins with | |
|coin :: _ when amount >= coin -> | |
doChange (amount - coin) (coin :: soFar) coins | |
|_ :: rest -> | |
doChange amount soFar rest | |
|[] -> soFar | |
doChange amount [] [25; 10; 5; 1] |
This file contains 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 FoqTest | |
open System | |
open Xunit | |
open Swensen.Unquote | |
open Foq | |
type ILogger = abstract Log: exn -> unit | |
type IService = abstract Translate: string -> string | |
type Translator(logger: ILogger, service: IService) = |