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
Array
ResizeArray
for 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
Last updated
Was this helpful?