My efforts to port http://www.youtube.com/watch?v=f6kdp27TYZs to Clojure.
func boring(msg string) {
for i := 0; ; i++ {
fmt.Println(msg, i)
time.Sleep(time.Second)
}
var Maybe = function(val){ | |
this.val = val; | |
}; | |
Maybe.prototype.map = function(f){ | |
return this.val ? Maybe(f(this.val)) : Maybe(null); | |
}; |
module Main where | |
import Data.Monoid (mappend) | |
import Data.Maybe (fromMaybe, listToMaybe, maybe) | |
import System.Environment (getArgs) | |
fizzbuzz i = fromMaybe (show i) $ mappend ["fizz" | i `rem` 3 == 0] | |
["buzz" | i `rem` 5 == 0] | |
main = mapM_ putStrLn [ fizzbuzz i | i <- [1..100] ] |
/* | |
turns a binary function into a variadic function via reduction | |
*/ | |
var reducify = function(fn){ | |
return function(){ | |
var args = [].slice.call(arguments) | |
return args.reduce(fn) | |
} |
var Either = function(left, right){ | |
this.left = left; | |
this.right = right; | |
}; | |
Either.prototype.map = function(f){ | |
return this.right ? | |
Either(this.left, f(this.right)) : | |
Either(f(this.left), this.left); | |
} |
My efforts to port http://www.youtube.com/watch?v=f6kdp27TYZs to Clojure.
func boring(msg string) {
for i := 0; ; i++ {
fmt.Println(msg, i)
time.Sleep(time.Second)
}
// splat is an abstraction that wraps around _.map, | |
// turning a function into a mapping | |
// NB: we're using Underscore/Lodash here because we | |
// want our mapping to work everywhere. You could | |
// easily replace this implementation with one | |
// that uses the native Array#map | |
function splat(fn){ | |
return function(list){ | |
_.map(list, fn); | |
} |
As software becomes more and more complex, it is more and more important to structure it well. Well-structured software is easy to write, easy to debug, and provides a collection of modules that can be re-used to reduce future programming costs. Functional programming is a paradigm shift away from how we normally think about constructing our programs and writing our abstractions. In this talk, I'd like to introduce the style of functional programming, discuss what it has to offer versus other programming metholodies (and how functional programming can complement paradigms such as OOP) and provide "real-world" examples of functional techniques such as:
As software becomes more and more complex, it is more and more important to structure it well. Well-structured software is easy to write, easy to debug, and provides a collection of modules that can be re-used to reduce future programming costs. Functional programming is a paradigm shift away from how we normally think about constructing our programs and writing our abstractions. In this talk, I'd like to introduce the style of functional programming in JavaScript, discuss what it has to offer and provide some "real-world" examples to show how it can help you write cleaner, more disciplined code that's easier to reason about, easier to test and easier to maintain.
When watching David Nolen's excellent Lambda Jam keynote on InfoQ, the references to interesting reading came a little too fast and furious for me to jot down, so I went through the slides and put this gist together.
#! /usr/bin/env sh | |
RUBY_VERSION="1.9.1" | |
SERVER="${HOME}/.gem/ruby/${RUBY_VERSION}/bin/camper_van" | |
PIDFILE="/tmp/camper_van.pid" | |
if [ ! -e ${SERVER} ]; then | |
echo "CamperVan server not found at '${SERVER}'." | |
fi |