-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathclasses.fsx
37 lines (28 loc) · 966 Bytes
/
classes.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(** CLASSES **)
type Repo(name: string, stars: int) =
// Private properties
let baseUrl = "https://github.com"
// Private method
let incrementStarsBy stars n = stars + n
// Additional Constructors
new() = Repo("", 0)
// Instance properties
member this.Name = name //read-only (immutable)
member val Stars = stars with get, set //mutable
// Static Methods
static member PrintHelp() = "Class that contains repo information"
// Methods
member _.GetBaseUrl() = $"{baseUrl}"
member this.GetRepoUrl() = $"{baseUrl}/{this.Name}"
member this.IncrementStarsBy(n) = this.Stars <- incrementStarsBy this.Stars n //takes parameters
// Static members
Repo.PrintHelp()
// Create instance
let fsharpRepo = Repo("dotnet/fsharp", 2800)
let blankRepo = Repo()
(** ACCESS MEMBERS / PROPERTIES **)
fsharpRepo.Name
fsharpRepo.GetRepoUrl()
fsharpRepo.Stars <- 3000
fsharpRepo.IncrementStarsBy 2
fsharpRepo.Stars