You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimize Seq.Last to behave like Seq.Length (incl. tests) (#7765)
* Optimize Seq.Last like Seq.Length
Add type check to Seq.Last and Seq.TryLast to avoid full iteration if not necessary. Like Seq.Length does it at
https://github.com/dotnet/fsharp/blob/c18e1780b3f3f345364cb1ad8e510ea9f4590d3a/src/fsharp/FSharp.Core/seq.fs#L709
* Add test for Optimized Seq.Last and Seq.TryLast
* style update
* style update 2
* update comments and fix build error
Github Build error was:
Check failure on line 132 in tests\FSharp.Core.UnitTests\FSharp.Core\Microsoft.FSharp.Collections\SeqModule2.fs
@azure-pipelines
azure-pipelines
/ fsharp-ci (Build Windows vs_release)
tests\FSharp.Core.UnitTests\FSharp.Core\Microsoft.FSharp.Collections\SeqModule2.fs#L132
tests\FSharp.Core.UnitTests\FSharp.Core\Microsoft.FSharp.Collections\SeqModule2.fs(132,58): error FS0064: This construct causes code to be less generic than indicated by the type annotations. The type variable 'a has been constrained to be type 'unit'.
* include List.last case
* include list in tests
* ensure same exception is raised on empty list
* typo
* Added implementation of List.last since it is not available at this point due to compilation error
The recursive function could also be defined inside but i guess then it would be reallocated on every call to Seq.Last (in case of list match).
An alternative would be to add .Last member on list type (like .Length member)
* inline List.last
reverting my previous attempt dotnet/fsharp@b329e23
tail rec functions should be inlined
* typo in tests(build failed)
* typo2 in test (Build failed)
* move implemnetation to internal module
as suggested by dsyme
* renamed internal tryLast to tryLastV
0 commit comments