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 pcustomer = pipe6 country fullname street city state postal optCustomer | |
| let customerRE = "[A-Z]{2}\s+[A-Za-z ]+[0-9A-Za-z ]+[A-Za-z ]+[A-Z]{2}\s[0-9 ]{5}" | |
| let genString xs l = | |
| Gen.elements xs | |
| |> Gen.map string | |
| |> Gen.listOfLength l | |
| |> Gen.map (List.reduce (+)) | |
| |> Gen.filter (String.length >> (>=) l) |
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 pheader = PO >>. pipe3 year_dash month_dash day datetime | |
| let exercise p x = | |
| match run p x with | |
| | Success _ -> true | |
| | Failure _ -> false | |
| let headerRE = "PO[0-9]{4}-[0-9]{2}-[0-9]{2}" | |
| let matchRegex pattrn input = Regex.IsMatch (input, pattrn) |
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 item i d q u n = | |
| { Id = i | |
| Description = d | |
| Quantity = q | |
| UnitPrice = u | |
| Notes = n } | |
| let optItem iOpt dOpt qOpt uOpt nOpt = | |
| let (<*>) = optApply | |
| let (<!>) = Option.map |
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 itemRE = "^ITEM[0-9]{3}-[A-Z]{2}$" | |
| type ItemId = Id of string | |
| let itemId = function | |
| | NotMatch itemRE -> None | |
| | s -> Some <| Id s | |
| type PosInt = PosInt of int | |
| let posInt i = | |
| if i >= 0 then Some <| PosInt i |
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 customer country name street city state postal = | |
| { Country = country | |
| FullName = name | |
| Street = street | |
| State = state | |
| City = city | |
| PostalCode = postal } | |
| let optApply fOpt xOpt = | |
| match fOpt, xOpt with |
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 country = countString 10 (caps <|> space) |>> cap2 | |
| let fullname = countString 20 (letter <|> space) |>> stringAZ | |
| let street = countString 20 (letter <|> space <|> digit) |>> stringAZ123 | |
| let city = countString 15 (letter <|> space) |>> stringAZ | |
| let state = countString 3 (caps <|> space) |>> cap2 | |
| let postal = countString 5 (caps <|> digit <|> space) |>> (int >> posint5) |
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 (|NotMatch|_|) pattern s = | |
| if Regex.IsMatch (s, pattern) then None | |
| else Some NotMatch | |
| type Cap2 = private Cap2 of string | |
| let cap2 = function | |
| | NotMatch "^[A-Z]{2}$" -> None | |
| | s -> Some <| Cap2 s | |
| type StringAZ = private StringAZ of string |
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 Customer = | |
| { Country : string | |
| FullName : string | |
| Street : string | |
| City : string | |
| State : string | |
| PostalCode : int } |
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 comma = pchar ',' | |
| let pitems = (skipString "ITEMS,") >>. (sepBy pitem comma) |
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 Item = | |
| { Id : string | |
| Description : string | |
| Quantity : int | |
| UnitPrice : float | |
| Notes : string } | |
| let item i d q u n = { Id = i; Description = d; Quantity = q; UnitPrice = u; Notes = n } | |
| let pipe = skipChar '|' |