This file contains hidden or 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
{ | |
"resultCount":1, | |
"results": [ | |
{"isGameCenterEnabled":false, | |
"screenshotUrls":["http://a4.mzstatic.com/us/r30/Purple7/v4/8d/94/3a/8d943ac7-77de-2011-d920-ccf1c0eb0cd2/screen1136x1136.jpeg", "http://a4.mzstatic.com/us/r30/Purple7/v4/ca/cd/1c/cacd1ca9-987c-9ad5-1861-67a9ff0653e7/screen1136x1136.jpeg", "http://a5.mzstatic.com/us/r30/Purple7/v4/30/26/af/3026af60-9efd-771c-8a42-5183fdc74df2/screen1136x1136.jpeg", "http://a5.mzstatic.com/us/r30/Purple7/v4/d6/4d/2f/d64d2f39-da72-cc1e-35bd-f52623d1a5a0/screen1136x1136.jpeg"], | |
"ipadScreenshotUrls":["http://a5.mzstatic.com/us/r30/Purple5/v4/ad/23/12/ad2312c5-a5b1-bc75-3e84-523981013388/screen480x480.jpeg", "http://a4.mzstatic.com/us/r30/Purple1/v4/14/6b/cd/146bcde2-8461-604b-0722-f8744b28dac9/screen480x480.jpeg", "http://a4.mzstatic.com/us/r30/Purple5/v4/c5/a1/48/c5a14861-13fb-18bb-0752-e0d13b4d2c3c/screen480x480.jpeg", "http://a4.mzstatic.com/us/r30/Purple7/v4/c2/36/25/c2362536-f6fc-4ef6-2a03-9b899ca00af9/screen480x480.jpeg"], "artworkUrl60":"http://i |
This file contains hidden or 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
/* | |
Pipe forward operator: | |
Applies the function on the right to the value on the left | |
*/ | |
infix operator |> {associativity left precedence 95} | |
func |> <A,B>(x:A, f:A -> B) -> B { | |
return f(x) | |
} | |
/* |
This file contains hidden or 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
func pure<A>(x:A) -> [A] { | |
return [x] | |
} | |
func filterM<A>(xs:[A], predicate: A -> [Bool]) -> [[A]] { | |
return reduce(xs, pure([])) { acc, x in | |
predicate(x).flatMap { b in b ? (acc.flatMap { pure($0 + [x]) }) : acc } | |
} | |
} |
This file contains hidden or 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
-- data structure for RGBA, RGB & CMYK colors | |
data Color = RGBA Float Float Float Float | |
| RGB Float Float Float | |
| CMYK Float Float Float Float | |
deriving (Eq, Ord, Show) | |
-- list of colors | |
colors = [ RGBA 0.1 0.1 0.5 0.2 | |
, RGBA 1 1 0 0.9 | |
, RGB 0.5 0.5 0 |
This file contains hidden or 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 | |
import Data.Maybe | |
letters :: [(Char, String)] | |
letters = [ | |
('A', "Alpha"), ('B', "Bravo"), ('C', "Charlie"), | |
('D', "Delta"), ('E', "Echo"), ('F', "Foxtrot"), | |
('G', "Golf"), ('H', "Hotel"), ('I', "India"), | |
('J', "Juliett"),('K', "Kilo"), ('L', "Lima"), | |
('M', "Mike"), ('N', "November"),('O', "Oscar"), |
This file contains hidden or 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
/* | |
This is a demonstration of how to implement the Optional type in Swift. | |
The name 'Maybe' is taken from Haskell, but the two cases 'None' & 'Some' | |
are the same as Swift's Optional type (Haskell uses 'Nothing' & 'Just'). | |
The Maybe type conforms to NilLiteralConvertible, as does Swift's | |
Optional type. This allows a Maybe value to be constructed from 'nil'. | |
One aspect of Swift's Optional type which can't be reproduced is | |
'implicit Optional wrapping'. Here's an example: |
This file contains hidden or 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 MilliLitresWaterPerGram = Double | |
type CaloriesPerGram = Double | |
type Grams = Double | |
data Food = Dry CaloriesPerGram | |
| Wet CaloriesPerGram MilliLitresWaterPerGram | |
deriving (Show, Eq) | |
data Animal = Cat { clawLength :: Double, calorieCount :: Double, hydrationLevel :: Double } | |
| Dog { barkVolume :: Double, calorieCount :: Double, hydrationLevel :: Double } |
This file contains hidden or 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 Peg = String | |
type Move = (Peg, Peg) | |
hanoi :: Integer -> Peg -> Peg -> Peg -> [Move] | |
hanoi 0 _ _ _ = [] | |
hanoi n a b c = hanoi (n-1) a c b ++ [(a,b)] ++ hanoi (n-1) c b a | |
{- | |
Usage: | |
hanoi 3 "a" "b" "c" |
This file contains hidden or 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
// Swift 2.0 | |
/* Function composition operator */ | |
infix operator •> { associativity left precedence 150 } | |
func •> <A,B,C> (f:A -> B, g:B -> C ) -> A -> C { | |
return { g(f($0)) } | |
} | |
extension Array where T: IntegerType { | |
func sum() -> T { |
This file contains hidden or 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 Foundation | |
extension Character { | |
func utf8() -> UInt8 { | |
let utf8 = String(self).utf8 | |
return utf8[utf8.startIndex] | |
} | |
} | |
func encrypt(c:Character, key:Character) -> String { |