I can find lots of stuff showing me what a lambda function is, and how the syntax works and what not. But other than the "coolness factor" (I can make a function in middle a call to another function, neat!) I haven't seen something that's overwelmingly compelling to say why I really need/want to use them.
It seems to be more of a styli...
Hello,
Can you see downsides to this one-liner other than the fact that multiple uses of it would violate the DRY principle? It seems straightforward but the fact that I haven't seen others propose it makes me wonder if there's a downside to it.
This bit of code creates a WeakReference to a method and then registers an event handler th...
I'm trying to inject some inline work as a Statement Lambda into a LINQ query select like so...
// NOTE: mcontext.Gettype() == System.Data.Linq.DataContext
// Okay - compiles, nothing unusual
var qPeople1 = from ME.tblPeople person in mcontext.tblPeoples
select person;
// ERROR - see below compile Error - Can I retrofit ...
I have finally finished reading Pro ASP.NET MVC 2 Framework Chapter 3: Pre-requisites but still a little confused about lambda expressions.
Where could I watch a video on it or read a guide about Lambda expressions with diagrams and pictures to help me better visualize it?
/* Thanks */
...
This has been driving me nuts, I'm posting here after a lot of looking around.
I'd like to know if two variables pointing to the same Proc are the pointing to the same Proc.
I'm sure it must be something I'm not getting so for example why do all of these return false?
class LambdaFunctions
def self.LambdaFunction1
lambda { |t| t...
Hello, I have a problem that has been nagging me for some time now and I can't find the answer.
I need to obtain the name of the property that is being referenced in a Lambda Expression. I would provide the lambda expression to a method that would return a string. For example if I have:
x => x.WeirdPropertyName
then the method would...
This is from a category that I'm using to modify UIView. The code works, but in the first method (setFrameHeight) I'm using a block and in the second method (setFrameWidth) I'm not. Is there any way to use blocks more efficiently in this example?
typedef CGRect (^modifyFrameBlock)(CGRect);
- (void) modifyFrame:(modifyFrameBlock) block ...
I'm using python, and I want a function that takes a string containing a mathematical expression of one variable (x) and returns a function that evaluates that expression using lambdas. Syntax should be such:
f = f_of_x("sin(pi*x)/(1+x**2)")
print f(0.5)
0.8
syntax should allow ( ) as well as [ ] and use standard operator precedence. ...
Hi,
i have a data structure like this
public class Employee
{
public string Name { get; set; }
public IEnumerable<Employee> Employees { get; private set; }
// ...
}
Now i need to loop through the complete structure and execute a method on each item.
How can i create an extension on IEnumerable for such a traverse functio...
I have been trying to figure this out for quite sometime (reading online blogs and articlaes), but so far unsuccessful.
What are delegates? What are Lambda Expressions? Advantages and disadvantages of both? Possible best practice of when to use one or the other?
Thanks in advance.
...
How can I combine two lambda expressions into one using an OR ?
I have tried the following but merging them requires me to pass parameters into the Expression.Invoke calls, however I want the value passed into the new lambda to be passed onto each child-lambda..
Expression<Func<int, bool>> func1 = (x) => x > 5;
Expression<Func<int, boo...
I'd like to know how to get a subset of data from a table using Linq To SQl Lambda expressions...
Let's say I have a table tbl_Product, with fields ProductId, ProductCode, ProductName, Description, WhyBuyCopy, how do I get only the first three fields when the others are not needed given that retrieving all data takes a second longer (ch...
Is there any reason that will make you use:
add2 = lambda n: n+2
instead of :
def add2(n): return n+2
I tend to prefer the DEF way but every now and then I see the LAMBDA way being used.
EDIT :
The question is not about lambda as unamed function, but about lambda as NAMED function.
There is a good answer to the same question he...
Behaviour of a lambda expression used in static initializers
magically depends on local variables initialized inside lambda body
int static_1 =
[=]() -> int {
int k_=7;// if this statement presents, the lambda doesn't work (static_1 remains uninitialized)
return 5;
} ();
int static_2=
[=]() -> int {
//Ok wi...
Hello stack,
there have been quite some posts about this, all trying to serialize a Func delegate.
But could someone think of an alternative, when the use of the delegate is always clear?
We have a generic create command, which takes a delegate as paramater in the constructor. This delegate will create the Item for the create command:...
I have functions that take SQL where clauses, and I'm wondering if there's a way to make them all strongly typed. Is there a way to take a lambda expression like a => a.AgencyID == id and convert it to a string where clause? Like "AgencyID = 'idValue'"?
Thanks!
...
I created a strongly-typed dataset in the dataset designer. The DataSet has a Table called FocusOffsetsTable and that table has four colums; SerialNumber, Filter, Wheel and Offset. I use the ReadXml() method of the DataSet class to load the strongly typed data from the xml file into the dataset. That seems to be working just fine.
I am ...
Reading this article I found several ways to call a method.
Method to call:
public static void SendData(string value) { }
Calls:
delegate void MyDelegate(string value);
//Slow method - NOT RECOMMENDED IN PRODUCTION!
SendData("Update");
// Fast method - STRONGLY RECOMMENDED FOR PRODUCTION!
MyDelegate d = new MyDelegate(Send...
Want to extract the text value from a lookup table's column in a db. EL is the entity for my db. Current code :
var QTypes = EL.ElogQueryType.Where<ElogQueryType>( eqt=> eqt.ID == queryTypeID);
string qType = QTypes.First().QueryType;
I get a list when I just pull .Select(... so something is wrong.
...
I'm trying to write a dynamic sort of command line processor where I have a dictionary with keys being possible parameters, and the member being an Action where the string is the text between the parameters passed on the command line. Want to be able to add parameters just by adding the params array, and writing the action in the diction...