My previous post F# - Refactoring to Functional - Part 1 garnered some attention for my use of the struct data type.
Tobias Burger pointed me at the correct implementation of F# records for my data passing. He suggested using ordinary records as my data type instead of structs since they are a more idiomatic approach to F#. It's taken me a little while to get back to the code, but I modified my data types to be records. The code is below:
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 Endpoint = | |
{ Name: string | |
Url: string | |
Body: string | |
Verb: string } | |
let endpoint = | |
{ Name = "Google Test" | |
Url = "https://www.google.com" | |
Body = "" | |
Verb = "GET" } |
I have to say "Thank you" to Tobias. His criticism helped me better understand F# records, and it made my code shorter and cleaner!
No comments:
Post a Comment