Created
September 28, 2019 15:03
-
-
Save OnurGumus/8ef38f948e1d858f33181b0ad1d0cbe6 to your computer and use it in GitHub Desktop.
Kickstart functional programming
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
open Fable | |
open Fable.Core | |
open Fable.Core.JS | |
open System | |
[<Emit("prompt($0,'')")>] | |
let prompt (s1 : string) : string = jsNative | |
let input = prompt("hello") | |
type SpeedResult = OK | TooFast | |
type SpeedResultWithSlow = | |
| OldSpeedResult of SpeedResult | |
| TooSlow | |
let convertSpeedResultToString s = | |
match s with | |
| OK -> "OK" | |
| TooFast -> "Too Fast" | |
let convertSpeedResultWithSlowToString s = | |
match s with | |
| TooSlow-> "Too Slow" | |
| OldSpeedResult e -> convertSpeedResultToString e | |
let setSpeed i = | |
if i> 200 then SpeedResult.TooFast | |
else OK | |
let setSpeedWithSlow i = | |
if i< 100 then TooSlow | |
else | |
i |> setSpeed |> OldSpeedResult | |
let workflow = | |
Int32.Parse | |
>> setSpeedWithSlow | |
>> convertSpeedResultWithSlowToString | |
>> printf "%A" | |
let genericWorkflow parse setSpeed convertToString print = | |
parse >> setSpeed >> convertToString >> print | |
let tooslowflow = | |
genericWorkflow (Int32.Parse) setSpeedWithSlow convertSpeedResultWithSlowToString (printf "%A") | |
let flow = | |
genericWorkflow (Int32.Parse) setSpeed convertSpeedResultToString (printf "%A") | |
flow input | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment