-
Notifications
You must be signed in to change notification settings - Fork 6k
Open
Labels
dotnet-fsharp/svchelp wantedGood for community contributors to help [up-for-grabs]Good for community contributors to help [up-for-grabs]

Description
[Enter feedback here]
sumSeq uses Seq.item to get to the item of interest in sequence -- this means it has to calculate all the intermediate items afresh every time. This makes it very slow and a bad example for someone just learning seqs/IEnumerables. A better implementation of sumSeq would be something like:
let sumSeq length sequence =
sequence
|> Seq.skip 1 // sumSeq uses Seq.item (index+1) -- so it always skips first item
|> Seq.truncate length // don't take more than length items
|> Seq.scan (+) 0.0 // generate running sums
|> Seq.skip 1 // skip the initial 0.0 from sequence of running sums
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 67fae525-473a-3072-b024-6d91d0e033b9
- Version Independent ID: 6e162795-52bd-f9df-4105-6919c1c72c88
- Content: Sequences - F#
- Content Source: docs/fsharp/language-reference/sequences.md
- Product: dotnet-fsharp
- GitHub Login: @cartermp
- Microsoft Alias: dotnetcontent
Metadata
Metadata
Assignees
Labels
dotnet-fsharp/svchelp wantedGood for community contributors to help [up-for-grabs]Good for community contributors to help [up-for-grabs]