I have an extension method with the following signature:
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> first, Expression<Func<T, bool>> second)
{
...
}
I have written a test-case for it that makes sure the two expressions are in fact combined. At least so that the new expression I get works.
Now I ...
I am using the below statement with the intent of getting all of the machine objects from the MachineList collection (type IEnumerable) that have a MachineStatus of i. The MachineList collection will not always contain machines with a status of i.
At times when no machines have a MachineStatus of i I'd like to return an empty collection...
For this question, I'll use the standard structure of Products (with an IsActive flag) and OrderItems (that each reference a Product). I also have a query builder that generates Linq expressions used to query products. A sample filter would let the user find active/inactive products, generating a Linq expression like:
Expression<Func<...
Hi,
I have just started learning lambda expressions.
Is it possible to simplify the following code down further:
Customer customer = Customers.FirstOrDefault(c => c.ID == 3);
if (customer == null)
{
customer = new Customer() { FirstName = "Ben", LastName = "Foster", ID = 3 };
Customers.A...
Is there any best practice with respect to coding style with respect to explicit use of the delegate keyword instead of using a lambda?
e.g.
new Thread(() =>
{
// work item 1
// work item 2
}).Start();
new Thread(delegate()
{
// work item 1
// work item 2
}).Start();
I think the lambda looks better. If the lambda is better style...
Suppose I have this wonderful function foo
[92]> (defun foo () (lambda() 42))
FOO
[93]> (foo)
#<FUNCTION :LAMBDA NIL 42>
[94]>
Now, suppose I want to actually use foo and return 42.
How do I do that? I've been scrounging around google and I can't seem to come up with the correct syntax.
...
I have seen some code which uses the <= operator. Can you explain what is the use of having lambda in reverse direction?
...
I have a function that wraps a call to one of my socket types. If there is an error, I want to be able to print a warning and retry. In the warning, I want to have the method name. However, it was declared as a lambda. Is this even possible?
How I call the function (assume in function called myMain):
SafeSocketCommand(() => this.mySock...
ok guys, bare with me. I'll summarize first, then go into detail.
I've written a number of methods (.WhereOr, .WhereAnd) which basically allow me to "stack up" a bunch of lambda queries, and then apply them to a collection. For example, the usage with datasets would be a little like this (although it works with any class by using generi...
SELECT ulcch.ID, ulcch.UserLoginHistoryID, ulcch.StatusID,
ulcch.ClientModuleID, ulcch.DeviceState, ulcch.UpdatedAt, ulcch.CreatedAt
FROM UserLoginClientConnectionHistory AS ulcch INNER JOIN
(SELECT MAX(CreatedAt) AS maxCreatedAt
FROM UserLoginClientConnectionHistory AS ulcch1
GROUP BY UserLoginHistory...
I have this code:
String temp = txtForm.Rtf;
foreach (ReplaceStrut rs in replaceArray) {
temp = temp.Replace(rs.getNeedle(), rs.getReplacement());
}
if (this.InvokeRequired) {
this.Invoke(temp => txtForm.Rtf = temp);
} else {
txtForm.Rtf = temp;
}
But...
I've created a lambda expression at runtime, and want to evaluate it - how do I do that? I just want to run the expression by itself, not against any collection or other values.
At this stage, once it's created, I can see that it is of type Expression<Func<bool>>, with a value of {() => "MyValue".StartsWith("MyV")}.
I thought at that ...
I can define an event like this(declared function):
MyElement.Keyup +=MyDeclaredFunction
I can also define it like this(anonymous delegate):
MyElement.Keyup+=new delegate(object sender, eventargs e) {};
I can also define it like this(lambda):
MyElement.Keyup += (sender, e) => myfunction
What is the best way to do this? One case...
Given a function as below, i can take a single table from my database and write a lambda using the Where extension method and pretty much build all the other cases using a simple wrapper method and supplying a filter.
public void getPeople(Expression<Func<tblPeople, bool>> filter, Action<List<tblPeople>> callback)
{
...
I have a collection of objects. One of the properties is "Type" which is an enum. I want to limit the collection by "type" using a lambda and haven't quite figured out how to do it.
Ideas?
...
I'm trying to make a function to get a delta between arrays, but right now just want to make a subset: get Nth element.
(defvar p1 #(1 2))
(defvar p2 #(3 4))
(mapcar '(lambda (x) (aref x 0)) '(p1 p2))
debugger invoked on a TYPE-ERROR in ...
The value P1 is not of type ARRAY.
The same error if I make it with make-array.
How do...
Is it possible to assign an Lambda Expression (action?) to a property of my View Model, then use that expression in a Partial? What should the model's property type be? Psuedo Code:
View Model
public class MyModel
{
public ????? MyAction {get;set;}
}
Controller
public ActionResult Index()
{
var model = new MyModel();
model...
I have a list of dictionaries that have the same keys within eg:
[{k1:'foo', k2:'bar', k3...k4....}, {k1:'foo2', k2:'bar2', k3...k4....}, ....]
I'm trying to delete k1 from all dictionaries within the list.
I tried
map(lambda x: del x['k1'], list)
but that gave me a syntax error. Where have I gone wrong?
...
In the Framework we are building we need the following pattern:
public class BaseRenderer
{
Func<string> renderer;
public BaseRenderer(Func<string> renderer)
{
this.renderer = renderer;
}
public string Render()
{
return renderer();
}
}
public class NameRenderer : BaseRenderer
{
public st...
I want to create a lambda function that takes two numpy arrays and sets a slice of the first to the second and returns the newly set numpy array.
Considering you can't assign things in lambda functions is there a way to do something similar to this?
The context of this is that I want to set the centre of a zeros array to another array ...