Created
April 2, 2017 22:11
-
-
Save AlgorithmsAreCool/870e7220a27f49fba60e11af886eb1c0 to your computer and use it in GitHub Desktop.
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
type Layout = | |
| Ukn | |
| Studio | |
| Roomed of Beds:int * Baths:float | |
type Listing = { | |
Apt : Property | |
Layout : Layout | |
Size : float | |
Price : float | |
Segs : string [] | |
} with member this.Rate = this.Price / this.Size | |
let parseLine prop (line:string) = | |
let splits = line.Split '\t' | |
let parseNum conveter = (Char.IsDigit) |> String.filter >> conveter | |
{ | |
Apt = prop; | |
Segs = splits; | |
Size = splits.[1] |> parseNum float | |
Price = splits.[2] |> parseNum float | |
Layout = | |
match splits.[0] with | |
| "Studio" -> Studio | |
| config -> | |
config.Split(',') | |
|> function | |
| [| a; b|] -> Roomed ( parseNum int a, parseNum float b ) | |
| _ -> Ukn | |
} | |
let parseData (prop, (strRaw:string)) = | |
strRaw.Split('\n') | |
|> Seq.map (parseLine prop) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment