linq - VB.NET - Combine TakeWhile and SkipWhile to get both partitions -


is there way combine takewhile , skipwhile on same list using same predicate both partitions, or premature optimization? done automatically behind scenes?

note list sorted property

here's how both halves of partition without optimization:

dim parta = list.takewhile(function(e) e.property = true) dim partb = list.skipwhile(function(e) e.property = true) 

i in 1 shot ienumerator, there point if won't have more several hundred items in collection?

edit: better since iterates through collection once?

dim parta list(of mytype) dim partb list(of mytype) dim iter = list.getenumerator() while iter.movenext()     if iter.current.property = true         parta.add(iter.current)     else         partb.add(iter.current)     end if end while 

your edit not equivalent first 2 lines of code in question, unless trues occur before falses. if want built-in way doing in edit, can do

dim itemsbyproperty = list.tolookup(function(e) e.property) 

now equivalent of parta itemsbyproperty(true), , partb's equivalent itemsbyproperty(false).


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -