Skip to content

Instantly share code, notes, and snippets.

@smallgeek
Created November 30, 2016 00:07
Show Gist options
  • Save smallgeek/ebd83f7010658cf220a9112faf983368 to your computer and use it in GitHub Desktop.
Save smallgeek/ebd83f7010658cf220a9112faf983368 to your computer and use it in GitHub Desktop.
効率のよくない List.partition
public static Tuple<IList<T>, IList<T>> Partition<T>(this IList<T> source, Func<T, bool> predicate)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
var list = source.ToList();
return new Tuple<IList<T>, IList<T>>(
list.Where(x => predicate(x)).ToList(),
list.Where(x => predicate(x) == false).ToList());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment