Skip to content

Instantly share code, notes, and snippets.

@TheAngryByrd
Created June 17, 2025 14:13
Show Gist options
  • Save TheAngryByrd/8b7d02f8835482e17fd53230fea1fa9e to your computer and use it in GitHub Desktop.
Save TheAngryByrd/8b7d02f8835482e17fd53230fea1fa9e to your computer and use it in GitHub Desktop.
F# TryGetNonEnumeratedCount helper
module Seq =
open System.Linq
/// Attempts to determine the number of elements in a sequence without forcing an enumeration.
let inline tryLength (xs : seq<_>) =
match Enumerable.TryGetNonEnumeratedCount xs with
| true, count -> ValueSome count
| _ -> ValueNone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment