Can lambda expressions only be used as conditional judgments and return bool?
See original GitHub issueTo implement the mocked foreach, I use an extension method:
public static class Extend
{
public static void All<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (var item in source)
action(item);
}
}
I want to change the money field of each npc in List<Npc> NearNpcs
to 10, so I wrote a Lambda string:
"NearNpcs.All(n=>n.money=10)"
(The InterpreterOptions.LambdaExpressions
setting is already turned on, and the Extend
class and associated required variables are registered.)
It reported the error:
DynamicExpresso.Exceptions.ParseException: A value of type ‘Int32’ cannot be converted to type ‘Boolean’ (at index 0).
Does Lambda parsing currently only support conditional parsing that can return bool?
Issue Analytics
- State:
- Created 2 months ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Python Lambda With Conditional
Conditional statements help you make decisions that are based on a set of circumstances. ... The lambda expression is used to store two...
Read more >c++ - Lambda Expression returning a bool flag not stopping ...
Here the lambda returning true is not the condition to stop waiting, rather the lambda is to account for spurious wake ups. The...
Read more >Lambda expressions and anonymous functions
A lambda expression can't directly capture an in, ref, or out parameter from the enclosing method. A return statement in a lambda expression ......
Read more >Trying Out Lambda Expressions in the Eclipse IDE
Lambda expressions can be used in ternary conditional expressions, which evaluate one of the two operands based on whether a boolean condition is...
Read more >Lambda Expressions (The Java™ Tutorials > Learning ...
This method takes one parameter and returns a boolean value. The method is so simple that it might not be worth it to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve reproduced with a simpler example that doesn’t require registering the extension method (using
List.ForEach
):Exception:
Yes, that’s the issue I suspect: we probably find the
ActionToAll
method, but can’t use it because the lambda parser expects the lambda to have a return value. I’ll have a look, thanks for posting the code!