473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Predicate methods like TrueForAll() for IEnumberable<T>?

Hi! It's great that Arrays and List<Tsupport functions that use
predicates like TrueForAll(), ConvertAll(), Foreach() and so on.

But why are there no such methods for IEnumerable<T>?
The guidelines say that we should not work with implementations like
List<Tbut instead only with interfaces like IList<Tso theoretically
we never could use this handy methods..
Nov 5 '07 #1
3 4488
On Nov 5, 10:04 am, cody <deutron...@gmx.dewrote:
Hi! It's great that Arrays and List<Tsupport functions that use
predicates like TrueForAll(), ConvertAll(), Foreach() and so on.

But why are there no such methods for IEnumerable<T>?
The guidelines say that we should not work with implementations like
List<Tbut instead only with interfaces like IList<Tso theoretically
we never could use this handy methods..
If you defined them in IEnumerable<Tthen *every* implementation
would have to provide code to do this - which would be pretty dire.

Instead, use a static method which takes an IEnumerable<Tand a
predicate, and returns true or false. This is exactly what LINQ does -
except that it provides extension methods to make it *look* like the
method is actually provided by IEnumerable<T>.

Jon

Nov 5 '07 #2
Jon Skeet [C# MVP] wrote:
On Nov 5, 10:04 am, cody <deutron...@gmx.dewrote:
>Hi! It's great that Arrays and List<Tsupport functions that use
predicates like TrueForAll(), ConvertAll(), Foreach() and so on.

But why are there no such methods for IEnumerable<T>?
The guidelines say that we should not work with implementations like
List<Tbut instead only with interfaces like IList<Tso theoretically
we never could use this handy methods..

If you defined them in IEnumerable<Tthen *every* implementation
would have to provide code to do this - which would be pretty dire.

Instead, use a static method which takes an IEnumerable<Tand a
predicate, and returns true or false. This is exactly what LINQ does -
except that it provides extension methods to make it *look* like the
method is actually provided by IEnumerable<T>.

Jon
Yes that is what I would have suggested, that for all these predicate
helper methods extension methods should be provided, instead of binding
them to a special implementation like List<Tclass, although *every*
possible collection should be able to benefit of them.

Who do I have to beat to get this cool stuff included into .NET
framework 4.0 :)

public static class EnumerableExtensions
{
public static bool TrueforAll(this IEnumerable<Tenumerable)
{
..
}

..
}
Nov 5 '07 #3
cody <de********@gmx.dewrote:
Yes that is what I would have suggested, that for all these predicate
helper methods extension methods should be provided, instead of binding
them to a special implementation like List<Tclass, although *every*
possible collection should be able to benefit of them.

Who do I have to beat to get this cool stuff included into .NET
framework 4.0 :)
Um, you don't - it's all in .NET 3.5.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: red floyd | last post by:
I have a suggestion for the standard library.... This is sort of a combination of std::transform() and std::for_each(). It applies the binary function to each iterator in ...
4
by: PASQUALE | last post by:
Hi I have a question: do the both statements below give the same result? If yes then does somebody know something about preformance differencies using these joins? SELECT A.* FROM Table1 A...
5
by: Andrew Robinson | last post by:
Any easy answer what is wrong here? private List<string> BodyWords = new List<string>(); string word = "Andrew"; the following causes a compilation error:
10
by: Dia | last post by:
At the company I work job applicants are required to do a little test. The human resource manager recently had a candidate who claimed one of the questions was ambiguous. Dependent upon the...
0
by: adebaene | last post by:
Hello all, Has everyone tried to use the functions taking a Predicate in Generics container in C++/CLI? Say I have a List<MyClass^>^ my_array, and I want to call RemoveAll on it. How would...
4
by: Anastasios Hatzis | last post by:
I'm looking for a pattern where different client implementations can use the same commands of some fictive tool ("foo") by accessing some kind of API. Actually I have the need for such pattern for...
56
by: Zytan | last post by:
Obviously you can't just use a simple for loop, since you may skip over elements. You could modify the loop counter each time an element is deleted. But, the loop ending condition must be...
6
by: A | last post by:
Hi, I don't get this method... Could someone please explain it? I have a number generator where I want to add the numbers to a List<long>. Before I add each number, I want to make sure that the...
6
by: Juha Nieminen | last post by:
joseph cook wrote: Not always. By default, yes, but you can specify other comparators, eg: std::map<int, int, std::greaterreversedMap;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.