What would be the most readable way to apply the following to a sequence using linq:
TakeWhile elements are valid but always at least the first element
EDIT: I have updated the title, to be more precise. I’m sorry for any confusion, the answers below have definitely taught me something!
The expected behavior is this: Take while element are valid. If the result is an empty sequence, take the first element anyway.
It would be most efficiently implemented manually as far as I can tell to ensure that it isn’t enumerated over more than necessary.
And for the sake of completion, an overload that includes the index: