In the ContainsIngredients method in the following code, is it possible to cache the p.Ingredients value instead of explicitly referencing it several times? This is a fairly trivial example that I just cooked up for illustrative purposes, but the code I'm working on references values deep inside p eg. p.InnerObject.ExpensiveMethod().Val...
I wanted to derive a class from Predicate<IMyInterface>, but it appears as if Predicate<> is sealed. In my case I wanted to simply return the inverted (!) result of the designated function. I have other ways to accomplish the goal. My question is what might the MS designers have been thinking when deciding to seal Predicate<>?
Without m...
After looking on MSDN, it's still unclear to me how I should form a proper predicate to use the Find() method in List using a member variable of T (where T is a class)
For example:
public class Car
{
public string Make;
public string Model;
public int Year;
}
{ // somewhere in my code
List<Car> carList = new List<Car>();...
You can pass a function pointer, function object (or boost lambda) to std::sort to define a strict weak ordering of the elements of the container you want sorted.
However, sometimes (enough that I've hit this several times), you want to be able to chain "primitive" comparisons.
A trivial example would be if you were sorting a collectio...
How would I convert the following to a VB.NET predicate using Array.Find?
Private Function FindCulture(ByVal Code As String) As Globalization.CultureInfo
'
Dim AllCultures As Globalization.CultureInfo() = Globalization.CultureInfo.GetCultures(Globalization.CultureTypes.AllCultures)
'
For Each Culture As Globalization.Cul...
The problem statement:
Given a set of integers that is known in advance, generate code to test if a single integer is in the set. The domain of the testing function is the integers in some consecutive range.
Nothing in particular is known now about the range or the set to be tested. The range could be small or huge (but a solution ca...
Hi,
I got into problem of predicate And operator. Code is :
SQLDBDataContext sqlDS = new SQLDBDataContext();
Expression<Func<User,bool>> pred = null; //delcare the predicate to start with.
if (Request["Name"] != null && ! Request["Name"].Equals(string.Empty))
{
pred = c => ( c.ContactFirst.Contains(Request["Name"]) || c.ContactLa...
Today we faced a quite simple problem that were made even simpler by the dear predicates. We had a kind of event log and wanted to filter it client side (Windows Forms) using a list of criterias. We began by implementing to filter by a number of categories.
private List<Events> FilterEventsByCategory(List<Events> events,
...
are there any good tutorials online for learning about the c# 2.0 language feature "predicates"?
i'm trying to learn how to use predicates along with linq to sql to modify my queries
what i am trying to do is query a table of customers and filter it based on changing criteria. for example
find all customers who have zipcode = 90210
f...
I need to test that a DateTime is at the beginning of a some unit of time for various units. This is the code I'm using right now:
/// ignoring milliseconds all the way down
bool IsMinute(DateTime dt)
{
return dt.Second == 0;
}
bool IsHour(DateTime dt)
{
return dt.Second == 0 && dt.Minute == 0;
}
bool IsDay(DateTime dt)
{
r...
Is there any way that you can combine predicates?
Lets say I have something like this:
class MatchBeginning : public binary_function<CStdString, CStdString, bool>
{ public:
bool operator()(const CStdString &inputOne, const CStdString &inputTwo) const
{ return inputOne.substr(0, inputTwo.length()).compare(inputTwo) == 0; }
};...
Lets say I have something called Stuff in my database, with a property called Id. From the user I get a sequence of selected Range objects (or rather I create them from their input) with the Ids they want. A stripped down version of that struct looks like this:
public struct Range<T> : IEquatable<Range<T>>, IEqualityComparer<Range<T>>
{...
Can you explain me;
What is Predicate Delegate ?
Where should we use predicates ?
Any best practices about predicates ?
Descriptive source code will be appreciated,
Thanks for all replies !
...
I am having a problem with a Core Data model in Cocoa. It's probably a fairly basic problem. A section of my Core Data model is shown below. Given the value of a cell property in the OutputCell entity, I want to return the relevant HistogramBar.
I'm using the following Predicate but it just returns an empty array. I've managed to ge...
I am using an interface called Predicate which is used for sifting through Collections. For example, I can define
public class BlackCatPredicate implements Predicate<Cat> {
public boolean evaluate( Cat c ) {
return c.isBlack();
}
}
and then use some utility findAll( Collection<T> coll, Predicate<T> pred) method to apply th...
I know this may sound crazy, but I swear that on two separate ocassions via intellisense I've seen an overload for the DataView constructor that took in a DataTable and either Predicate or Func, I don't remember what T was, either DataRow or DataRowView. But now I can't find it. It also took in another parameter, I want to say it was a C...
I'm creating a simple code generator with delegates.
Why am I getting this error at runtime:
Error while binding the target method.
on the following code?
XAML:
<Window x:Class="Parser.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
...
I have a list of objects that I want to filter by an integer parameter
List<testObject> objectList = new List<testObject>();
// populate objectList with testObjects
objectList.FindAll(GroupLevel0);
private static bool GroupLevel0(testObject item)
{ return item._groupLevel == 0; }
private class testObject
{
public string _FieldS...
I'm trying out Coq, but I'm not completely sure what I'm doing. Is:
Theorem new_theorem : forall x, P:Prop /\ Q:Prop
Equivalent to:
Ax ( P(x) and Q(x) )
(where A is supposed to be the universal quantifier).
Edit: I think they are.
...
Specifically, I'm looking for similarly clean notation to the Collection<T>.TrueForAll / Exists, etc.
It feels smelly to have to write a foreach loop to inspect the return of a method on each object, so I'm hoping there's a better Java idiom for it.
...