πRecap
Types
5 collections including 4 functional/immutable
List: default choice / Versatile, Practical
β [ ], Operators: Cons ::, Append @, Pattern matching
Array: fixed-size, mutable, performance-oriented (e.g. indexer)
β [| |] less handy to write than [ ]
Seq: deferred evaluation (Lazy), infinite sequence
Set: unique elements
Map: values by unique key
API
Rich β Hundreds of functions >> Fifty for LINQ
Consistency
β Common syntax and functions
β Functions preserve the collection type (β LINQ sticked to IEnumerable<>)
Semantic β Function names closer to JS
Comparison Cβ―, Fβ―, JavaScript
Cβ― LINQ
Fβ―
JS Array
Select(), SelectMany()
map, collect
map(), flatMap()
Any(predicate), All()
exists, forall
some(), every()
Where(), Γ
filter, choose
filter(), Γ
First(), FirstOrDefault()
find, tryFind
Γ, find()
Γ
pick, tryPick
Γ
Aggregate([seed]])
fold, reduce
reduce()
Average(), Sum()
average, sum
Γ
ToList(), AsEnumerable()
List.ofSeq, toSeq
Γ
Zip()
zip
Γ
BCL types
ArrayResizeArrayfor C# ListDictionaries:
dict,readOnlyDict
For interop or performance
πΉοΈ Exercises
High Scores
Easy
List
Protein Translation
Medium+
Seq/List π‘
ETL
Medium
Map of List, Tuple
Grade School
Medium+
Map of List
β Pre-requisites: β Create an account, with GitHub for instance β Solve the first exercises to unlock the access to the one above
π‘ Tips:
β string is a Seq<char>
β What about Seq.chunkBySize?
π Additional resources
Choosing between collection functions, F# for fun and profit (2015)
Last updated
Was this helpful?