lambda

Filtering two arrays to avoid Inf/NaN values

I have two arrays of doubles of the same size, containg X and Y values for some plots. I need to create some kind of protection against Inf/NaN values. I need to find all that pairs of values (X, Y) for which both, X and Y are not Inf nor NaN If I have one array, I can do it using lambdas: var filteredValues = someValues.Where(d=> !(d...

Role of Combinators in Concatenative/Tacit Programming Languages.

Hi! I have a question about what exact role do higher-order combinators (or function producers) hold in concatenative/tacit programming. Additionally I would like to ask if there is another way to implement concatenative programming language rather than directly manipulating the stack. This might look like a newbie question, so if yo...

Mutating the expression tree of a predicate to target another type

Intro In the application I 'm currently working on, there are two kinds of each business object: the "ActiveRecord" type, and the "DataContract" type. So for example, we have: namespace ActiveRecord { class Widget { public int Id { get; set; } } } namespace DataContract { class Widget { public int Id { get;...

linq expression in vb.net

Hi, Can any body translate the following c# code to vb. I have tried telarik code converter but I got problem at expression.call and it won't compile at all. private static IOrderedQueryable<T> OrderingHelper<T>(IQueryable<T> source, string propertyName, bool descending, bool anotherLevel) { ParameterExpression param = Expressio...

Call asp.net mvc Html Helper within custom html helper with expression parameter

I am trying to write an html helper extension within the asp.net mvc framework. public static MvcHtmlString PlatformNumericTextBoxFor<TModel>(this HtmlHelper instance, TModel model, Expression<Func<TModel,double>> selector) where TModel : TableServiceEntity { var viewModel = new PlatformNumericTextBox(); var...

passing Func<TSource, TKey> keySelector error

static void Main() { string[] a = { "a", "asd", "bdfsd", "we" }; a = a.OrderBy(fun).ToArray(); } private static int fun(string s) { return s.Length; } its is giving compile time error . I know that we can do this with Lambda expression like this. a.OrderBy(s=>s.Length).ToArray(); but i ...

Simple way of finding the index of an item in a generic list

I'm trying to get the next item in a list of strings (postal codes). Normally I'd just foreach till I find it and then get the next in the list but I'm trying to be a bit more intuitive and compact than that (more of an exercise than anything). I can find it easily with a lambda: List<string> postalCodes = new List<string> { "A1B", "A2...

Does lamda in List.ForEach leads to memory leaks and performance problems ?

I have a problem which I could solve using something like this sortedElements.ForEach((XElement el) => PrintXElementName(el,i++)); And this means that I have in ForEach a lambda which permits using parameters like int i. I like that way of doing it, but i read somewhere that anonymous methods and delegates with lambda leads to a lot ...

Creating a property setter delegate

I have created methods for converting a property lambda to a delegate: public static Delegate MakeGetter<T>(Expression<Func<T>> propertyLambda) { var result = Expression.Lambda(propertyLambda.Body).Compile(); return result; } public static Delegate MakeSetter<T>(Expression<Action<T>> propertyLambda) { var result = Expressio...

Dictionary<string,string> to Dictionary<Control,object> using IEnumerable<T>.Select()

I have a System.Collections.Generic.Dictionary<string, string> containing control ID and appropriate data column to data bind: var dic = new Dictionary<string, string> { { "Label1", "FooCount" }, { "Label2", "BarCount" } }; I use it that way: protected void FormView1_DataBound(object sender, EventArgs e) { var row = ((Dat...

custom C++ boost::lambda expression help

hello. A little bit of background: I have some strange multiple nested loops which I converted to flat work queue (basically collapse single index loops to single multi-index loop). right now each loop is hand coded. I am trying to generalized approach to work with any bounds using lambda expressions: For example: // RANGE(i,I,N) is ...

C++0x lambda capture by value always const?

Is there any way to capture by value, and make the captured value non-const? I have a library functor that I would like to capture & call a method that is non-const but should be. The following doesn't compile but making foo::operator() const fixes it. struct foo { bool operator () ( const bool & a ) { return a; } }; int _...

Lambda returning another lambda

Hello, is there any way how to return lambda from another lambda recursively? All I want to do is finite state machine, implemented as lambda, which returns lambda implementing another state (or null). nesting Func<> won't work as I want. C#, .NET 3.5 Example: machine, 3 states, pseudolanguage private Lambda State1() { if (S...

Create lambda action from function expression

It is relatively easy to create a lambda function that will return the value of a property from an object, even including deep properties... Func<Category, string> getCategoryName = new Func<Category, string>(c => c.Name); and this can be called as follows... string categoryName = getCategoryName(this.category); But, given only the...

How can I make this work with deep properties

Given the following code... class Program { static void Main(string[] args) { Foo foo = new Foo { Bar = new Bar { Description= "Martin" }, Name = "Martin" }; DoLambdaStuff(foo, f => f.Name); DoLambdaStuff(foo, f => f.Bar.Description); } static void DoLambdaStuff<TObject, TValue>(TObject obj, Expr...

What is the easiest way to get the property value from a passed lambda expression in an extension method for HtmlHelper?

I am writing a dirty little extension method for HtmlHelper so that I can say something like HtmlHelper.WysiwygFor(lambda) and display the CKEditor. I have this working currently but it seems a bit more cumbersome than I would prefer. I am hoping that there is a more straight forward way of doing this. Here is what I have so far. pub...

Strongly typed API for ASP.NET MVC 2 async actions

Hi guys, Have anybody tried to create strongly typed API for ASP.NET MVC 2 async actions? Best regards, Alexey Zakharov ...

Calling a Generic Method using Lambda Expressions (and a Type only known at runtime)

You can use Lambda Expression Objects to represent a lambda as an expression. How do you create a Lambda Expression Object representing a generic method call, if you only know the type -that you use for the generic method signature- at runtime? For example: I want to create a Lambda Expression Objects to call: public static TSource L...

Lambda Expressions and Stored Procedures

Hi Everyone. I'm trying to mimic the LINQ Where extension method for my ADO.NET DAL methods. Bascially, my aim is to have a single method that I can call. Such as: Product p = Dal.GetProduct(x => x.ProductId == 32); Product p2 = Dal.GetProduct(x => x.ProductName.Contains("Soap")); I then want to dissect those Predicates and send th...

Autoproperty failing in IronPython works in Python?

I have this following python code, it works fine in python but fails with the following error in IronPython 2.6 any ideas as to why? ====================================================================== ERROR: testAutoProp (__main__.testProperty) ---------------------------------------------------------------------- Traceback (most...