Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Module Program
Sub Main()
Dim list = New List(Of Integer) From {1, 2, 3, 4, 5}
Dim info = list.FirstAndRest()
If info.First IsNot Nothing Then
For Each other In info.Additional
Console.Write(", ")
End If
End Sub
Function FirstAndRest(Of T As Structure)(sequence As IEnumerable(Of T)) As (First As T?, Additional As IEnumerator(Of T))
Dim enumerator = sequence.GetEnumerator()
If enumerator.MoveNext() Then
Return (enumerator.Current, enumerator)
Return (Nothing, enumerator)
End If
End Function
Function GetEnumerator(Of T)(enumerator As IEnumerator(Of T)) As IEnumerator(Of T)
Return enumerator
End Function
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.