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.List | |
-- | Splits the given list around a specific element. | |
-- Why isn't this included in the Haskell prelude??? | |
split :: Eq a => a -> [a] -> [[a]] | |
split sep [] = [[]] | |
split sep (a:as) | |
| sep == a = []:rest | |
| otherwise = (a : head rest) : tail rest |
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
largestPrimeFactor n = foldr1 (max) (primeFactors n 2) | |
where | |
primeFactors n s = | |
case [ m | m <- [s..(floor $ sqrt $ fromIntegral n)], n `mod` m == 0 ] of | |
[] -> [n] | |
(m:ms) -> m:(primeFactors (n `div` m) m) | |
solution3 = largestPrimeFactor 600851475143 |
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 Control.Monad | |
data Logger a = Logger [String] a deriving (Show) | |
instance Monad Logger where | |
return a = Logger [] a | |
(Logger alog ax) >>= b = | |
let (Logger blog bx) = b ax |
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
[[?[[?[[S1:first_name]]::Mary::T::]][[?[[S1:first_name]]::Misty::T::]] [[?[[S1:first_name]]::Janice::T::]]::T::Hello Ladies!::Hello]] |
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
<script src="http://etianen.github.com/html5media/html5media/html5media.min.js"></script> |
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
Dumping Object: PaymentInfo | |
Transaction ID = 9702 | |
Campaign ID = 1421 | |
Donation Type = 25 | |
Donation Type ID = 9642 | |
Payment Number = 1 | |
Transaction Value = 4 | |
Orig Transaction Value = 0 | |
Discount = 0 | |
Discount Codes = null |
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
// Create a dictionary of simulated raw data. This could come from a HTTP POST request. | |
val data = Map[String, String]("name" -> "David", "age" -> "26") | |
// Extract the required fields. | |
val name = data.field("name", StringField) | |
val age = data.field("age", IntField) | |
val happiness = data.field("happiness", IntField, default=6) | |
// Define a data model to create. | |
case class Person(name:String, age:Int, happiness: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
import scala.collection.immutable.ListMap | |
sealed abstract class Validated[+T] | |
case class Valid[+T](value:T) extends Validated[T] | |
case class Error(message:String) extends Validated[Nothing] | |
class ValidationException(s:String) extends Exception(s) |
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 scala.collection.immutable.ListMap | |
sealed abstract class Validated[+T] | |
case class Valid[+T](value:T) extends Validated[T] | |
case class Error(message:String) extends Validated[Nothing] | |
class ValidationException(s:String) extends Exception(s) |
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
// Define a new domain model. | |
case class Person(schema:Schema) { | |
val name = schema.field("name", StringField) | |
val age = schema.field("age", IntField) | |
val happiness = schema.field("happiness", IntField, default=5) | |
} | |
// Create an instance of the person from a map. | |
val david = Person(Map("name" -> "Dave", "age" -> 26)) |