Created
November 30, 2016 00:07
-
-
Save smallgeek/ebd83f7010658cf220a9112faf983368 to your computer and use it in GitHub Desktop.
効率のよくない List.partition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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