Skip to content

Instantly share code, notes, and snippets.

@AlgorithmsAreCool
Created April 2, 2017 22:11
Show Gist options
  • Save AlgorithmsAreCool/870e7220a27f49fba60e11af886eb1c0 to your computer and use it in GitHub Desktop.
Save AlgorithmsAreCool/870e7220a27f49fba60e11af886eb1c0 to your computer and use it in GitHub Desktop.
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