### Project Euler - problem 1

``let projectEulerProblemOne = [1 .. 999] |> List.filter(fun x -> x % 3 = 0 || x % 5 = 0) |> List.sum``

### Female or male?

``````type Person = { Name : string; Gender : string }

let alice = { Name = "Alice"; Gender = "Female" }
let bob = { Name = "Bob"; Gender = "Male" }

let femaleOrMale p =
match p with
| { Gender = "Female" } -> p.Name + " is female."
| { Gender = "Male" } -> p.Name + " is male."
| _ -> "???"``````

### Computation Expression example

``````type SafeStringNumbers() =

member this.Bind(x, f) =
match System.Int32.TryParse(x) with
| (true, v) -> f v
| _ -> f 0

member this.Return(x) =
x

let safeStringNumbers = new SafeStringNumbers()

let v1 = safeStringNumbers {
let! a = "1"
let! b = "2"
let! c = "3"
return a + b + c
}

let v2 = safeStringNumbers {
let! a = "1"
let! b = "foo"
let! c = "3"
return a + b + c
}``````

### Sequence creation

``````let sq = seq {
yield 1
yield! seq { 2 .. 6 }
yield 7
yield! seq [8; 9; 10]
}

let count = Seq.length sq
let list = List.ofSeq sq``````
Failed Tests

### List comprehensions

``````let evens = [2 .. 2 .. 10]
let odds = [for i in evens -> i - 1]
let fizzBuzzNumbers = [for i in 1 .. 100 do if i % 3 = 0 && i % 5 = 0 then yield i]

printfn "%A" evens
printfn "%A" odds
printfn "%A" fizzBuzzNumbers``````
Failed Tests

### If else one liner

``````let getSign x = if x > 0 then "+" elif x < 0 then "-" else "0"
let foo = [-3..3] |> List.map getSign |> String.concat(" ")

printfn "%s" foo``````
Failed Tests

### Pattern matching with guard

``````let areEqualsIgnoreCase (s : string * string) =
match s with
| (s1, s2) when s1.ToUpper() = s2.ToUpper() -> true
| _ -> false

printfn "%b" (areEqualsIgnoreCase ("Hello", "hello"))
printfn "%b" (areEqualsIgnoreCase ("hello", "HELLO"))
printfn "%b" (areEqualsIgnoreCase ("hello", "ello"))``````
Failed Tests

### Type detection

``````let detectType v =
match box v with
| :? int -> printfn "int"
| :? string -> printfn "string"
| _ -> printfn "?"

detectType 1
detectType "1"
detectType 1.0``````
Failed Tests

### tryParseInt

``````let tryParseInt s =
try
let i = System.Int32.Parse s
Some i
with _ -> None

let v1 = tryParseInt "1"
printfn "%O" v1
printfn "%O" v1.Value
printfn "%O" v1.IsSome
printfn "%O" v1.IsNone

printfn ""

let v2 = tryParseInt "?"
printfn "%O" v2
printfn "%O" v2.IsSome
printfn "%O" v2.IsNone``````
Failed Tests

### FizzBuzz inline

``[for i in 1 .. 30 -> if i % 3 = 0 && i % 5 = 0 then "FizzBuzz" elif i % 3 = 0 then "Fizz" elif i % 5 = 0 then "Buzz" else i.ToString()] |> List.map(fun v -> printfn "%s" v)``
Failed Tests

### Function Composition 2

``````let add n x = x + n
let times n x = x * n

let f1 = add 1 >> times 2
let f2 = add 1 << times 2

printfn "%i" (f1 2) // (2+1)*2
printfn "%i" (f2 2) // 2*2+1``````
Failed Tests

### Function Composition

``````let add x y = x + y

Failed Tests

### Partial Application

``````let add x y = x + y

Failed Tests

### Dynamic printfn

``````printfn "%*s" 5 "*"
printfn "%*s" 6 "***"
printfn "%*s" 7 "*****"
printfn "%*s" 8 "*******"
printfn "%*s" 9 "*********"``````
Failed Tests

### Active patterns and parsing

``````let (|Int|_|) str = match System.Int32.TryParse(str) with | (true, int) -> Some(int) | _ -> None
let (|Bool|_|) str = match System.Boolean.TryParse(str) with | (true, bool) -> Some(bool) | _ -> None

let parse s =
match s with
| Bool b -> printfn "%-10s%b" "Bool" b
| Int i -> printfn "%-10s%i" "Int" i
| _ -> printfn "%-10s%O" "???" s

parse "0"
parse "1"
parse "2"
parse "3"
parse "123"
parse "-123"
parse "True"
parse "true"
parse "False"
parse "False"
parse "hello"``````