Ben is a co-organiser of the Brisbane Functional Programming Group (bfpg.org) and a web app developer that is lucky enough to get to use Scala in his day job. Loves how static types and pure functional programming help to create code that is beautiful, concise and yet still can be reasoned about with minimal profanities.
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
import java.util.Calendar; | |
def sieve(primes:List[Int], possible:List[Int]):List[Int] = | |
possible match { | |
case Nil => primes | |
case firstPrime :: xs => { | |
sieve(firstPrime :: primes , xs.filter( _ % firstPrime != 0) ) | |
} | |
} |
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
import Test.QuickCheck | |
fizzBuzzinator a | |
| (mod a 15) == 0 = "fizzbuzz" | |
| (mod a 3) == 0 = "fizz" | |
| (mod a 5) == 0 = "buzz" | |
| otherwise = show a | |
fizzBuzz xs = unlines (map fizzBuzzinator xs) | |
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
import Data.Char | |
validateCC :: [Char] -> Bool | |
validateCC ccString = | |
let sum = luhnSum $ ccDigits ccString | |
in 0 == mod sum 10 | |
ccDigits digits = reverse $ map digitToInt digits | |
luhnSum digits = |
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
use MooseX::Declare; | |
use 5.10.1; | |
class Egg {} | |
class Coup { | |
has chook => ( is => 'ro' , isa => 'Chook' , required => 0); | |
} | |
class Chook { |
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
import qualified Data.Map as Map | |
import Data.List | |
import Control.Applicative | |
englishTranslator = ("ENGLISH: " ++) | |
germanTranslator = ("GERMAN: " ++) | |
windowsUnlines = intercalate "\r\n" | |
unixUnlines = intercalate "\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
prettyPrintDBInfo :: DBInfo -> String | |
prettyPrintDBInfo (DBInfo dbName (DBOptions useBString _ ) tbls) = unlines [ | |
"DBInfo { ", | |
" dbName = \"" ++ dbName ++ "\"", | |
" , opts = DBOpts { useBString = " ++ (show useBString) ++ " }", | |
" , tbls = [" , | |
(map prettyPrintTableInfo tbls) , | |
" ] ", | |
"}" | |
] |
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
{-# LANGUAGE TemplateHaskell #-} | |
import Data.Aeson (decode) | |
import Data.Aeson.TH (deriveFromJSON) | |
import Data.ByteString.Char8 (pack,unpack) | |
import Network.HTTP.Types (renderQuery) | |
import Data.Conduit.Binary (sinkFile) | |
import Control.Monad.IO.Class (liftIO) | |
import qualified Data.Conduit as C | |
import qualified Data.ByteString.Lazy as LBS |
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
import dispatch._ , Defaults._ | |
import com.ning.http.client.{Request,AsyncHandler} | |
object Overloads { | |
def getWebPage(): Future[Res] = { | |
Http(url("http://www.google.com")) | |
} |
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
import scalaz._ | |
import std.option._ | |
import syntax.monad._ | |
import scala.xml.Node | |
object S { | |
// We stack OptionT on top of state to keep track of our state regardless | |
// of whether we find what we are looking for or not. | |
// Using OptionT has the awesome property that the monad will stop traversing |
OlderNewer