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
let fizzBuzz = | |
function | |
| Fizz -> "Fizz" | |
| Buzz -> "Buzz" | |
| FizzBuzz -> "FizzBuzz" | |
| Other n -> n.ToString() |
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
let (|Fizz|Buzz|FizzBuzz|Other|) input = | |
match (input % 3, input % 5) with | |
| 0,0 -> FizzBuzz | |
| 0,_ -> Fizz | |
| _,0 -> Buzz | |
| _,_ -> Other input |
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
let (|Even|Odd|) input = if input % 2 = 0 then Even else Odd | |
let TestNumber input = | |
match input with | |
| Even -> printfn "%d is even" input | |
| Odd -> printfn "%d is odd" input |
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
let (|>>) result f = | |
match result with | |
| Success(value) -> f value | |
| Failure(error) -> Failure(error) |
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
let withdraw amount currency {Amount = (oldAmount, _)} = | |
match oldAmount - amount with | |
| newAmount when newAmount < 0 -> Failure("This bank account cannot be overdrawn.") | |
| newAmount -> Success {Amount = (oldAmount - amount, USD)} |
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
let deposit amount currency {Amount = (oldAmount, _)} = | |
{Amount = (oldAmount + amount, USD)} |
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 Point = { x : float; y: float; z: float; } |
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
let printValue opt = | |
match opt with | |
| Some x -> printfn "%A" x | |
| None -> printfn "No value." |
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
let myOption1 = Some(10.0) | |
let myOption2 = Some("string") | |
let myOption3 = None |
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 Option<'a> = | |
| Some of 'a | |
| None |