Table of Contents....3
Preface....7
Contents....8
F# Software Foundation....10
About the author....10
Acknowledgments....11
Getting Started....12
Setting up your environment....12
One Last Thing....13
1 - An Introductory Domain Modelling Exercise....14
The Problem....14
Getting Started....15
Making the Implicit Explicit....22
Going Further....24
Alternative Approaches (1 of 2)....27
Alternative Approaches (2 of 2)....28
Summary....30
Postscript....31
2 - Functions....32
Getting Started....32
Theory....32
In Practice....33
Unit....36
Anonymous Functions....37
Multiple Parameters....38
Partial Application (Part 1)....39
The Forward Pipe Operator....39
Partial Application (Part 2)....42
Summary....44
3 - Null and Exception Handling....45
Null Handling....45
Interop With .NET....48
Handling Exceptions....49
Function Composition With Result....51
Summary....57
4 - Organising Code and Testing....58
Getting Started....58
Solutions and Projects....58
Adding a Source File....58
Namespaces and Modules....59
Writing Tests....62
Writing Real Tests....63
Using FsUnit for Assertions....67
Summary....68
5 - Introduction to Collections....69
Before We Start....69
The Basics....69
Core Functionality....69
Folding....74
Grouping Data and Uniqueness....75
Solving a Problem in Many Ways....76
Working Through a Practical Example....77
Summary....85
6 - Reading Data From a File....86
Setting Up....86
Loading Data....86
Parsing Data....89
Testing the Code....91
Final Code....93
Summary....95
7 - Active Patterns....96
Setting Up....96
Partial Active Patterns....96
Parameterized Partial Active Patterns....98
Multi-Case Active Patterns....102
Single-Case Active Patterns....103
Using Active Patterns in a Practical Example....105
Summary....108
8 - Functional Validation....109
Setting Up....109
Solving the Problem....111
Where are we now?....116
Functional Validation the F# Way....120
Summary....123
9 - Single-Case Discriminated Union....124
Setting Up....124
Solving the Problem....124
Using Modules....131
A Few Minor Improvements....133
Using a Record Type....135
Summary....135
10 - Object Programming....136
Setting Up....136
Class Types....136
Interfaces....138
Object Expressions....140
Encapsulation....142
Equality....144
Summary....146
11 - Recursion....147
Setting Up....147
Solving The Problem....147
Tail Call Optimisation....148
Expanding the Accumulator....149
Using Recursion to Solve FizzBuzz....150
Quicksort using recursion....151
Recursion with Hierarchical Data....152
Other Uses Of Recursion....158
Summary....158
12 - Computation Expressions....159
Setting Up....159
Introduction....159
The Result Computation Expression....162
Introduction to Async....164
Compound Computation Expressions....165
Debugging Code....170
Further Reading....170
Summary....171
13 - Introduction to Web Programming with Giraffe....172
Getting Started....172
Using Giraffe....173
Creating an API Route....176
Creating a Custom HttpHandler....177
Creating a View....178
Adding Subroutes....179
Reviewing the Code....181
Summary....183
14 - Creating an API with Giraffe....184
Getting Started....184
Our Task....184
Sample Data....184
Routes....185
Handlers....187
Using the API....189
Summary....190
15 - Creating Web Pages with Giraffe....191
Getting Started....191
Configuration....191
Adding a Master Page....192
Creating the Todo List View....193
Loading Data on Startup....195
Summary....197
Summary....198
F# Software Foundation....199
Resources....199
And Finally....200
Appendix 1....201
Creating Solutions and Projects in VS Code....201
Appendix 2....203
CSS and JavaScript for Chapter 15....203
Everywhere you look, programming languages are gaining functional features. The problem is that it's not the individual features that make functional programmers happy, it's the way that your approach to writing software and the features work together to help you write simple code to solve interesting problems. This book will help you to discover why F# is such a popular language with those who have spent time learning its secrets.
This book started life as a series of blog posts I wrote for the Trustbit website (https://trustbit.tech/blog). The sum of the content is the core of what a developer needs to know to be able to work on one of their F# Line of Business codebases. I have improved and extended the content, upgraded the code to F# 5, and ensured that the code would run in VS Code with the free ionide extension.
This book is FREE. If someone feels that they want to pay money for it, the author's royalties (80%) will continue to go to the F# Software Foundation.