lambda

How to pass Lambda expression parameter by Reference for C++0x

Hello, I am using a C++0x lambda expression to modify values of a map. However, having difficulty passing the map iterator by reference. If I just pass the iterator, by value such as: [](std::pair<TCHAR, int > iter) it compiles fine, but the values does not get updated in the map. If I try to pass the iterator by reference, such as []...

what is a lambda language?

I was reading "javascript good parts" author mentions that javascript is first of the lambda languages to be launched. JavaScript's functions are first class objects with (mostly) lexical scoping. JavaScript is the first lambda language to go mainstream. Deep down, JavaScript has more in common with Lisp and Scheme than with Java. I...

Avoid or embrace C# constructs which break edit-and-continue?

I develop and maintain a large (500k+ LOC) WinForms app written in C# 2.0. It's multi-user and is currently deployed on about 15 machines. The development of the system is ongoing (can be thought of as a perpetual beta), and there's very little done to shield users from potential new bugs that might be introduced in a weekly build. For ...

Self Executing functions in PHP5.3?

I was trying to borrow some programing paradigms from JS to PHP (just for fun). Is there a way of doing: $a = (function(){ return 'a'; })(); I was thinking that with the combination of use this can be a nice way to hide variables JS style $a = (function(){ $hidden = 'a'; return function($new) use (&$hidden){ $hidden...

Lazy evaluation of linq expressions

Hi, Im trying to build a expression evaluator with Linq expressions. Im trying to make It so that all function arguments are lazy evaluated but can't quite get there. I'm writing in psuedo here but the real thing is linq expressions. Example expression: Func1(Func2(10) + 1, Func3(10)) Update Expression.Call(Func1, Expression.A...

Can the 'type' of a lambda expression be expressed?

Thinking of lambda expressions as 'syntactic sugar' for callable objects, can the unnamed underlying type be expressed? An example: struct gt { bool operator() (int l, int r) { return l > r; } } ; Now, [](int l, int r) { return l > r; } is an elegant replacement for the above code (plus the necessary creation of c...

C#/Lambda: What does param in the following refer to?

I am looking at the code from here /// <summary> /// Returns the command that, when invoked, attempts /// to remove this workspace from the user interface. /// </summary> public ICommand CloseCommand { get { if (_closeCommand == null) _closeCommand = new RelayCommand(param => this.OnRequestClose()); ...

Working with nullable types in Expression Trees

I have an extension method to dynamically filter Linq to Entities results using string values. It works fine until I use it to filter nullable columns. Here's my code: public static IOrderedQueryable<T> OrderingHelperWhere<T>(this IQueryable<T> source, string columnName, object value) { ParameterExpression table = Expression.Paramet...

Linq repository and GetTable<T>()

I'm following the fairly standard L2S repository pattern, using the following as one of the methods public IEnumerable<T> GetAllByFilter(Func<T, bool> expression) { return _dataContext.GetTable<T>().Where(expression); } I'm a bit miffed to see that the call to GetTable appears to literally get the table, with the Where expressi...

Is there a way, using LINQ/EF, to get the top most item in a parent/child hierarchy?

I have a class called Structure: public class Structure { public int StructureId { get; set; } public Structure Parent { get; set; } } As you can see, Structure has a parent Structure. There can be an indefinite number of structures within this hierarchy. Is there any way, using LINQ (with Entity Framework), to get the top-mo...

MethodCallExpression with IObservable throws access denied exception to System.CoreEx

I have a MethodCallExpression object from which I'm trying to return a IObservable<Thing> instance using the Reactive Extensions framework. private IObservable<Thing> GetThing(Expression<Func<Thing>> expression) { Func<Thing> method = expression.Compile() var observable = Observable.FromAsyncPattern<Thing>(method.BeginInvoke, meth...

Grouping lambda.

if I have a structure like this: Batch Amount 76 495.4 76 975.75 76 25 76 442.46 77 1335.12 77 2272.37 77 34.5 77 496.99 77 360 77 13 77 594.6 And I want to get something like Batch Amount 76 1938.61 77 5106.58 How the expression should be? I started with something like: batches.GroupBy(x => new { Batch = x.Ba...

How can I use linq to check if an flags/bitwise enumeration contains a type?

Hi folks, the following lambda statemement returns null, when i was hoping it would return a string value. var countryCode = AddressComponents .Where(x => x.AddressType == AddressType.Country) .Select(x => x.ShortName) .SingleOrDefault(); now the AddressType property of the current instance i'm interrigating contains the ...

Should I expose Actions instead of events?

Hi, while working with WF 4.0 I noticed that the WorkflowApplication class exposes action properties (Aborted, Complete, etc...) instead of events. Is there a specific reason? When should I prefer action properties instead of events? Thank you ...

Book recommendation for C# + Generics + Lambda Expression

Can somebody recommend me book for C# 4.0 which covers Generics and Lambda Expression (scary things) I seen this but I am not sure which one covers Generics and Lambda in depth. Thanks, ...

Applying like filter to an IQueryable

I'm trying to write a custom filter for Dynamic data that will allow me to run like type queries on entity columns. For example searching for john on name field to returen johnson, johns etc. I'm trying to override the IQueryable GetQueryable(IQueryable source) method on the QueryableFilterUserControl class. To filter my results. Does a...

Passing arguments inside Scrapy spider through lambda callbacks

HI, I'm have this short spider code: class TestSpider(CrawlSpider): name = "test" allowed_domains = ["google.com", "yahoo.com"] start_urls = [ "http://google.com" ] def parse2(self, response, i): print "page2, i: ", i # traceback.print_stack() def parse(self, response): for i ...

When does a lambda in an extension method do too much?

I realize this is partially subjective, but I'm generally curious as to community opinion and have not been able to successfully find an existing question that tackles this issue. I am in a somewhat religious debate with a fellow coworker about a particular Select statement in a L2EF query. .Select(r => { r.foo.Bar = r.bar; r.f...

ExpressionTree - GetSetMethod Error: Method 'System.String get_Name()' is not defined for type 'System.String'

Here is my method: public static MethodCallExpression ClonePropertyAssignmentLambda<T>(Expression source, string property) { var targetExp = Expression.Parameter(typeof (T), "target"); var propertyInfo = typeof (T).GetProperty(property); var targetProperty = Expression.Property(targetExp, propertyInfo); ...

How to create and return an Expression<Func ...

I Use entity Framework 4. I would like to be able to create a function that return an Expression func that will be use in a lambda expression. var ViewModel = _db.Suppliers.Select(model => new { model,SupType = model.SupplierType.SupplierTypeTexts.Where( st => st.LangID == 1) }); I would like to mak...