lambda

Passing a lambda to a secondary AppDomain as a stream of IL and assembling it back using DynamicMethod

Is it possible to pass a lambda expression to a secondary AppDomain as a stream of IL bytes and then assemble it back there using DynamicMethod so it can be called? I'm not too sure this is the right way to go in the first place, so here's the (detailed) reason I ask this question... In my applications, there are a lot of cases when I ...

Efficient way to use python's lambda, map

I need to store a big list of integers in Bigtable(db). For efficiency I am storing them as diff between 2 consecutive items. for eg: original_list = [1005, 1004, 1003, 1004, 1006] Storing the above list(which actually contains more than 1000k items) as start = 1005 diff = [-1, -1, 1, 2] The closest I could manage is, ltp = [st...

How do I set arbitrary number of properties on generic object?

I want to be able to call a method that creates an object and sets properties of the object based on the parameters passed into the method. The number of parameters is arbitrary, but the catch is I don't want to use strings. I want to use the actual properties sort of like you do in lambda expressions. I want to be able to call the me...

Cannot use ref or out parameter in lambda expressions

Why can't you use a ref or out parameter in a lambda expression? I came across the error today and found a workaround but I was still curious why this is a compile-time error. Here's a simple example: private void Foo() { int value; Bar(out value); } private void Bar(out int value) { value ...

Adding a method call to a Linq Expression whilst remaining an full expression

How I do extend an linq expression whilst keeping it an expression? I've simplified this quite a bit (to avoid pasting pages) - .e.g I working with Queryable rather than Enumerable, but the solution for this will suffice, ultimately I need to keep it as an expression whilst adding a method call to it. For exampleL var p1 = new...

linker problem a list of const reference::push_back in boost::lambda::if_then

Hi experts, The following codes compiled and linked fine with g++-4.0 on a Mac OSX for_each(As.begin(), As.end(), boost::lambda::if_then( boost::lambda::bind(&A::get_string, boost::lambda::_1)==" CA ", boost::lambda::bind(&std::list<A>::push_back, &As_copy, boost::lambda::_1) ) ); But when I try to populate a conta...

Where is boost::lambda::ll?

Hi all, I can't seem to find boost::lambda::ll for a nested ll::for_each() invocations in any header file in the boost_1_39_0 distribution. Could someone point me to the right direction? Thanks. ...

What does SomeMethod(() => x.Something) mean in C#

(Note the code is an example) I have the following syntax: SomeMethod(() => x.Something) What do the first brackets mean in the expression? I'm also curious how you can get the property name from argument that is being passed in. Is this posssible? ...

Confusion over `Action` delegate and lambda expressions

private void StringAction(string aString) // method to be called { return; } private void TestDelegateStatement1() // doesn't work { var stringAction = new System.Action(StringAction("a string")); // Error: "Method expected" } private void TestDelegateStatement2() // doesn't work { var stringAction = new System.Action(p...

Convert an Expression Tree to Source Code string

I have a function that has the following signature... public string DoJunk(Expression<Func<bool>> expression) I'm trying to find a way to convert the "expression" parameter back to something resembling the original source code (or at least a c# representation of the original souce code). So, if someone calls the function like this... ...

c#, using lambdas with collection initialization

Is it possible to use a lambda expression inside an object initialization expression? Please look at the code below: XDocument doc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XElement("data", new XElement("album", new XElement("slide1"), new XElement("slide2"), ...

LINQ to Lambda Expressions

Is there an application or utility that will convert LINQ to Lambda Expressions? (or an add-on to LINQPad) ...

Listing expressions for OrderBy

I would like to be able to store a list of expressions to execute with IQueryable.OrderBy at a later time, something like: List<Expression<Func<MyType, object>>> list = new List<Expression<Func<MyType, object>>>(); list.Add(x => x.Date); list.Add(x => x.ID); IOrderedQueryable<MyType> qry = query.OrderBy(list[0]).ThenBy(list[1]); ...

C# enum display on Expression.ToString()

Hello, When I call the ToString() methods on an expression, the enum value are printed as integers. Is there some format overload ? Maybe I can create an derviedclass from expression and override some ToString Method. Any thoughts ? Here is a sample : public enum LengthUnits { METRES, FEET }; Expression<Func<LengthUnits, bo...

What is the purpose of `@ins << lambda` in this code?

In the first method listed below, the use method, it looks to me like :ins is an instance variable and attr is a method that provides getters and setters for :ins. What I'm not sure is what the @ins << lambda does. module Rack class Builder attr :ins def use(middleware, *args, &block) middleware.instance_variable_set "@r...

Problem with Generic Linq OrderBy function

I saw the following function in a posting which allows one to order data using a generic expression: public static IOrderedQueryable<T> OrderBy<T, TKey>( this IQueryable<T> source, Expression<Func<T, TKey>> func, bool isDescending) { return isDescending ? source.OrderByDescending(func) : source.OrderBy(func); } When I try to use t...

Linq - pulling a value from a null query result

I have a linq query that needs to pull a date column out of a row. The expression currently looks like this myObject.OrderByDescending(s=> s.MyDate).Where(s => s.CRAStatus.Description == "CheckedOut").FirstOrDefault().MyDate) The problem is that if there are no rows that are "CheckedOut", the query will return a null and attempting to...

Linq expression to set all values of an array to a given value

I have a bit of code that i'd like to turn into a linq expression (preferably with lambdas) to make it easier to use as a delegate. The code looks like this: List<DateTime[]> changes = new List<DateTime[]>(); changes = PopulateChanges(); for (int i = 0; i < changes.Count; i++) { for(int j = 0; j < changes[i].Length; j++) { ...

Nested Lambda for use with Fluent Interface

Given the following types: class Parent { List<Child> Children {get;set;}} class Child {List<Child> GrandChildren {get;set;}} class Helper<TEntity> {List<string> Properties {get;set;}} And given the following methods on Helper... public Helper AddProps<TEntity, TProp>(Expression<Func<TEntity, TProp>> exp) { this.Properties.Add(...

Why use lambda here instead of two predefined methods?

def divideset(rows, column, value) split_function = nil if value.is_a?(Fixnum) || value.is_a?(Float) split_function = lambda{|row| row[column] >= value} else split_function = lambda{|row| row[column] == value} end set1 = rows.select{|row| split_function.call(row)} set2 = rows.reject{|row| split_function.call(row)} [set1, set2] end ...