Overview
Common Fβ― collections
Array
'T array
β‘
Array<T>
β
β
List
'T list
β
ImmutableList<T>
β
β
Seq
seq<'T>
β‘
IEnumerable<T>
β
β
Set
Set<'T>
β
ImmutableHashSet<T>
β
β
Map
Map<'K, 'V>
β
ImmutableDictionary<K,V>
β
β
β
dict
β‘
IDictionary<K,V>
βοΈ β
β
β
readOnlyDict
β‘
IReadOnlyDictionary<K,V>
βοΈ
β
β
ResizeArray
β‘
List<T>
β
β
Functions consistency π
Common to all 5 modules:
empty
/isEmpty
,exists
/forall
find
/tryFind
,pick
/tryPick
,contains
(containsKey
forMap
)map
/iter
,filter
,fold
Common to Array
, List
, Seq
:
append
/concat
,choose
,collect
item
,head
,last
take
,skip
... a hundred functions altogether!
Syntax consistency π
Array
[β£ 1; 2 β£]
[β£ 1..5 β£]
β
List
[ 1; 2 ]
[ 1..5 ]
β
Seq
seq { 1; 2 }
seq { 1..5 }
β
Set
set [ 1; 2 ]
set [ 1..5 ]
β
Syntax trap β οΈ
Square brackets []
are used both for:
Value: instance of a list
[ 1; 2 ]
(of typeint list
)Type: array
int []
, e.g. of[| 1; 2 |]
β Recommendations
Distinguish between type vs value β
Write
int array
rather thanint[]
Comprehension
Purpose: syntactic sugar to construct collection
Handy, succinct, powerful
Syntax includes
for
loops,if
condition
Same principle as generators in Cβ―, JS
yield
keyword but often optional (since Fβ― 4.7)yield!
keyword (pronounce "yield bang") β‘yield*
in JSWorks for all collections π
Examples:
Flattening:
Last updated
Was this helpful?