Recursive List Flattening

后端 未结 13 1359
既然无缘
既然无缘 2020-11-27 04:25

I could probably write this myself, but the specific way I\'m trying to accomplish it is throwing me off. I\'m trying to write a generic extension method similar to the oth

13条回答
  •  生来不讨喜
    2020-11-27 05:20

    Since yield is not available in VB and LINQ provides both deferred execution and a concise syntax, you can also use.

    
    Public Function Flatten(Of T)(ByVal objects As Generic.IEnumerable(Of T), ByVal selector As Func(Of T, Generic.IEnumerable(Of T))) As Generic.IEnumerable(Of T)
        Return objects.Union(objects.SelectMany(selector).Flatten(selector))
    End Function
    

提交回复
热议问题