Skip to content

Commit 83c809b

Browse files
author
Kevin Logan
committed
updates during the presentation
1 parent cf94670 commit 83c809b

5 files changed

Lines changed: 29 additions & 19 deletions

File tree

examples/03PipingFunctions.fs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ module fSharpExamples.Piping
44
printfn "03PipingFunctions"
55

66
// simple example of functions and piping
7-
let list = [4; 3; 1]
7+
let myList = [4; 3; 1]
8+
let myListLetters = ["a"; "b"; "c"]
89
let sort (list: int list) = List.sort list
9-
let print (list: int list)= List.iter(fun x-> printfn "item %i" x) list
10+
let print (list)= List.iter(fun x-> printfn $"item {x}") list
11+
let listSortPrint = myList |> sort |> print
1012

11-
let listSortPrint = list |> sort |> print
13+
// typing of int list stops this
14+
// let listSortPrint2 = myListLetters |> sort |> print
1215

1316
open Cards.Shuffle
1417
cards |> shuffle |> take 3 |> printAll
1518

1619
open Cards.Draw
17-
printfn "Deck: %A Hand: %A" d h
20+
printfn "Deck: %A Hand: %A" deckAfter handAfter
1821

1922

2023
// function composition example

examples/04TypesAndObjects.fs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
module fSharpExamples.TypesAndObjects
66

7+
type Animal = {
8+
name: string
9+
noises: string list
10+
}
11+
712
type Person =
813
{
914
name : string
@@ -16,13 +21,15 @@ type Person =
1621
hobbies = []
1722
}
1823

19-
let Kevin2 =
24+
25+
let Kevin =
2026
{
2127
Person.Empty with
2228
name = "Kevin"
2329
hobbies = ["guitar"; "biking"; "reading"]
2430
}
25-
let Kevin3 = {
31+
32+
let Kevin2 = {
2633
name = "Kevin"
2734
hobbies = ["guitar"; "biking"; "reading"]
2835
}
@@ -32,6 +39,14 @@ let Joey = {
3239
name = "Joey"
3340
}
3441

42+
let dog =
43+
{
44+
name = "Toto"
45+
noises = ["bark"]
46+
}
47+
48+
// if you only have name, it takes the type that is closest above.
49+
// let d = { name = "K" } // Person, until Animal is moved down
3550

3651
// classes are different
3752
// https://fsharpforfunandprofit.com/posts/classes/
@@ -44,7 +59,8 @@ type CustomerName(firstName:string, middleInitial, lastName) =
4459
member _.AddOne x = x + 1
4560

4661
let customer = CustomerName("Kurt", "M", "Woolworth")
47-
// immutable customer.LastName <- "kjkl";
62+
// immutable
63+
// customer.LastName <- "kjkl";
4864

4965
// "F# classes which are defined outside a module are generated as normal top-level .NET classes, which is probably what you want." modules are a static class
5066
// https://fsharpforfunandprofit.com/posts/type-extensions/#downsides-of-methods

examples/06JsonNetSerialization.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module fSharpExamples.Json
66
type Person = { name : string; hobbies : string[] }
77

88
let loadData(fileName: string) = System.IO.File.ReadAllText(fileName)
9-
let toPersonModel(json: string) = Newtonsoft.Json.JsonConvert.DeserializeObject<Person>(json)
9+
let toPersonModel(json: string) = Newtonsoft.Json.JsonConvert.DeserializeObject<Person list>(json)
1010

1111

1212

13-
let blendReportModel =
13+
let people =
1414
loadData("people.json")
1515
|> (fun json -> toPersonModel(json))

examples/cards/DrawCards.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ let drawCardToHand (deck: list<int>, draw: list<int>) =
1919
|> List.append [firstCard]
2020
(deck.Tail, hand)
2121

22-
let d, h = (cards, hand) |> drawCardToHand |> drawCardToHand
22+
let deckAfter, handAfter = (cards, hand) |> drawCardToHand |> drawCardToHand

examples/cards/Program.fs

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)