Introduction
Welcome to the fifth post in this introductory series on Functional Programming in F#. In this post we will be building upon some of the concepts we have learned in previous posts whilst investigating functional collections.
Before We Start
We are going to use the solution we created in the last post of this series: https://trustbit.tech/blog/2019/10/01/introduction-to-functional-programming-in-f-sharp-part-4.
Add Orders.fs, OrderTests.fsx and lists.fsx to the code project and OrderTests.fs to the test project.
The Basics
F# has a hugely deserved reputation for being great for data-centric use cases like finance and data science due in a large part to the power of it's support for data structures and collection handling. In this post we will look at how we can harness some of this power in normal line of business apps.
There are a number of collections in F# that we can make use of but the three primary ones are:
Sequence (Seq) - Lazily evaluated - Equivalent to IEnumerable.
Array - Great for numerics/data science. There are built-in modules for 2d, 3d and 4d arrays.
List - Eagerly evaluated and immutable structure and data. F# specific, not same as List.
Each of these types has a module that contains a wide range of functions including some to convert to/from each other.
In this post we are going to concentrate on the List type and module.
Core Functionality
We will be using lists.fsx for this section. Remember to highlight the code and run it in F# Interactive (FSI).
Create an empty list: