F# Training
F# Training
F# Training
  • Presentation
  • Fundamentals
    • Introduction
    • Syntax
      • Bases
      • Functions
      • Rules
      • Exceptions
    • First concepts
    • šŸ”Quiz
  • Functions
    • Signature
    • Concepts
    • Syntax
    • Standard functions
    • Operators
    • Addendum
    • šŸ”Quiz
    • šŸ“œSummary
  • Types
    • Overview
    • Tuples
    • Records
    • Unions
    • Enums
    • Anonymous records
    • Value types
    • šŸ“œRecap
    • Addendum
  • Monadic types
    • Intro
    • Option type
    • Result type
    • Smart constructor
    • šŸš€Computation expression (CE)
    • šŸš€CE theoretical basements
    • šŸ“œRecap
  • Pattern matching
    • Patterns
    • Match expression
    • Active patterns
    • šŸš€Fold function
    • šŸ“œRecap
    • šŸ•¹ļøExercises
  • Collections
    • Overview
    • Types
    • Common functions
    • Dedicated functions
    • šŸ”Quiz
    • šŸ“œRecap
  • Asynchronous programming
    • Asynchronous workflow
    • Interop with .NET TPL
    • šŸ“œRecap
  • Module and Namespace
    • Overview
    • Namespace
    • Module
    • šŸ”Quiz
    • šŸ“œRecap
  • Object-oriented
    • Introduction
    • Members
    • Type extensions
    • Class, Struct
    • Interface
    • Object expression
    • Recommendations
Powered by GitBook
On this page
  • Types
  • API
  • Comparison C♯, F♯, JavaScript
  • BCL types
  • šŸ•¹ļø Exercises
  • šŸ”— Additional resources

Was this helpful?

Edit on GitHub
  1. Collections

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# List

  • Dictionaries: dict, readOnlyDict

For interop or performance

šŸ•¹ļø Exercises

Exercise
Level
Topics

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

PreviousQuizNextAsynchronous workflow

Last updated 1 month ago

Was this helpful?

On

, F# for fun and profit (2015)

, 2020

šŸ“œ
Exercism.io / F# track
All functions, with their cost in O(?)
Choosing between collection functions
An F# Primer for curious C# developers - Work with collections
Formatage des collections