Tag Info

New answers tagged

4

My most common use of lambda is for key functions: list_of_foos.sort(key = lambda foo: foo.bar) max(list_of_foos, key = lambda foo: foo.bar) min(list_of_foos, key = lambda foo: foo.bar)


3

You can use a lambda expression anywhere you need to have a piece of executable code passed along like data (ie, as a parameter). In Python, there's little difference between using a lambda expression and a one-line function, except that the lambda doesn't clutter up the namespace, and you don't have to go hunting for where it is defined in the code. In ...


2

Laziness in Java 8 Streams works the same as it used to for Iterables in Guava: you have to pass on the Iterable to stay lazy and evaluation happens, once you build a Collection from the Iterator. Both Streams and Iterators can only be consumed once. So for your method interfaces, the more general way (permitting laziness) is to use the Stream interface ...


1

First of all, you should copy the reference of action delegate instance before invoking it to prevent threading issues, like this: private void ExecutionAction(Action action) { var handler = action; if (handler == null) { return; } try { handler(); } catch (System.Data.SqlTypes.SqlTypeException e) { ...



Top 50 recent answers are included