a = [] a.append(lambda x:x**0)
a.append(lambda x:x**1)
a[0](2), a[1](2), a[2](2)... spits out 1, 2, 4, ...
b=[]
for i in range(4)
b.append(lambda x:x**i)
b[0](2), b[1](2), b[2](2)... spits out 8, 8, 8, ...
In the for loop, the i is being passed to lambda as a variable, so when I call it, the last value of i is used instead of t...
Is there anyway to determine if a value is passed as a reference, eg. x.Age or a specific value. eg. 20 like so.
value(x => x.Age)
or
value(x => 20)
Cheers
...
I've seen time and time again API (particularly in the .NET framework) that uses Func<TObject, bool> when Predicate<TObject> is seemingly a perfectly responsible option. What good reasons might an API designer have for doing so?
...
Brian's premise in his argument to the question "Are side effects a good thing?" is interesting:
computers are von-Neumann machines that are designed to work well with effects (rather than being designed to work well with lambdas)
I am confused by the juxtaposition of the approaches. I cannot see them as black and white. What is th...
So when I write something like this
Action action = new Action(()=>_myMessage = "hello");
Refactor Pro! Highlights this as a redundant delegate creation and allows me to to shorten it to
Action action = () => _myMessage="hello";
And this usually works great. Usually, but not always. For example, Rhino Mocks has an extension metho...
Can you elaborate on the current state of "blocks" (in the Ruby sense) in Python?
What are the language constructs that exist in python? How do they compare to other languages (like Ruby, Smalltalk, [insert more])? Or does python lack of such constructs?
I have so far understood the lambda thing; it is only one-line, but maybe it comes...
Going from a lambda to an Expression is easy using a method call...
public void GimmeExpression(Expression<Func<T>> expression)
{
((MemberExpression)expression.Body).Member.Name; // "DoStuff"
}
public void SomewhereElse()
{
GimmeExpression(() => thing.DoStuff());
}
But I would like to turn the Func in to an expression, only i...
Hi everyone!!
I have a lambda expression that has this:
Convert.ToDateTime(a.startTime).TimeOfDay >= Convert.ToDateTime(startTime).TimeOfDay
But, I have to create a procedure in SQL Server and how should be the statement above to SQL statement?
I've tried to use some kinda 'convert(startime, getdate(),8) but it didn't work.
And I f...
Imports System.Reflection
Public Class Test
Private Field As String
End Class
Module Module1
Sub Main()
Dim field = GetType(Test).GetField("Field", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance)
Dim test = New Test
Dim GetValue = New Func(Of Test, String)(Function(t As Test) fie...
Hello,
I have a method call expression and try to invoke the method. I figured out a way, but I have problems in retrieving the parameter values since not every argument is described with a ConstantExpression.
Expression<Action<T>> = t => t.DoSomething(Par0, Par1, Par2);
MethodCallExpression methodCallExpression = selector.Body as Meth...
I am looking for something like Action but I want it to be
delegate U ReturnAction<T,U>(T param);
Is there already a system delegate for this? I just don't want to reinvent the wheel. I did the same thing when I first needed a Predicate and then realized it existed.
...
Question: I have just wrote my first code using c# lamba expressions. It works, but I am not sure if this is the best way to do it. Any recommendations on a better way to do the lambda expression? It seems odd to have numerous lines of code in the expression like I do below.
Background: I have a generic list of delegates. Each delega...
I understand lambdas and the Func and Action delegates. But expressions stump me. In what circumstances would you use an Expression<Func<T>> rather than a plain old Func<T>?
...
I'm throwing this out there just as a question of curiosity...
Assuming you're only expecting/wanting one method to be provided, would this be frowned upon or bad practice?
public class Something {
public Action OnRemove = () => { };
public Action<object, EventArgs> OnFinishedLoading = (sender, e) => { };
}
// then used like....
I know
from f in list
where f.bar == someVar
select f
can be written as
list.Where( f => f.bar == someVar );
Can a similar expression be created from
from f in foo
from b in f.bar
where b.something == someVar
select b;
?
...
Thanks to the help with this.
Tried this, without luck..
I know
from f in list
where f.bar == someVar
select f
can be written as
list.Where( f => f.bar == someVar );
Can a similar expression be created from
from f in foo
from b in f.bar
where b.something == someVar
select f;
?
Edit:
Sorry, I forgot f.bar in the second exa...
I'm integrating an IronPython scritping engine into my C# raytracer which, so far, has been a breeze even though I'm completely new to Python. There is one particular thing, though, that I need help with. I have a C# class which defines a constructor like this:
public CameraAnimation(Action<Camera, float> animation)
In C#, I would ins...
I'm trying to make a part of my code more fluent.
I have a string extension that makes an HTTP request out of the string and returns the response as a string. So I can do something like...
string _html = "http://www.stackoverflow.com".Request();
I'm trying to write an extension that will keep trying the request until it succeeds. My ...
What is the VB.net syntax below for?
var list = xd.Descendants("product")
.Select(element =>new
{
Title = element.Attribute("title").Value,
Duration = element.Element("duration").Value
}).ToList();
...
I have the following code to let the GUI respond to a change in the collection.
myObservableCollection.CollectionChanged += ((sender, e) => UpdateMyUI());
First of all is this a good way to do this?
Second: what's the code to unsubscribe from this event? Is it the same but with -= (and then the complete anonymous method again)?
...