Questions tagged [lambda]

DO NOT USE FOR THE AWS SERVICE (use [aws-lambda] for those questions!) Lambdas are anonymous functions or closures in programming languages such as Lisp, C#, C++, Lua, Python, Ruby, JavaScript, or Java. (Also, lambda expression.)

This term originated with the lambda calculus, a Turing-complete model of computation which uses only functions, called lambda expressions. They are of the form λ<argument name(s)>.<expression>; the point is that occurrences of the argument <argument name(s)> inside the expression <expression> are substituted with the values of the arguments. An example is λx.x, the identity function.

In programming languages such as , , , and , lambda is an operator used to denote anonymous functions or closures, following the usage of lambda calculus. An anonymous function enables definition of a function without binding to an identifier. Lambda expressions are supported in since version 8, in since version 11.

Android does not currently use Java 8, but Android Studio and other IDEs (IntelliJ Idea, etc.) automagically collapses "Closures" (anonymous classes implementing one method) into lambda expressions.

References

26400 questions
13
votes
2 answers

Non-capturing lambda seems to nevertheless capture the enclosing instance

I wrote this code: import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.function.Supplier; public class Main { public static void main(String[] args) throws Exception { new Main(); } private Main()…
William F. Jameson
  • 1,803
  • 6
  • 14
13
votes
1 answer

Getting NullPointerException when trying to stream().filter().collect(Collectors.toList())) on Java list

I got a problem while trying to search a specific Java object in a list. Actually i got the search function i want working for another Java class. Now i tried it for a different one but instead of returning a list of results i get a…
Elias Johannes
  • 606
  • 2
  • 7
  • 24
13
votes
2 answers

Performance enhancement of ranking function by replacement of lambda x with vectorization

I have a ranking function that I apply to a large number of columns of several million rows which takes minutes to run. By removing all of the logic preparing the data for application of the .rank( method, i.e., by doing this: ranked =…
Carl
  • 468
  • 1
  • 10
  • 22
13
votes
3 answers

The proper way to end a BeginInvoke?

I recently read this thread on MSDN. So I was thinking of using a lambda expression as a way of calling EndInvoke just as a way to make sure everything is nice and tidy. Which would be more correct? example 1: Action method =…
Mike_G
  • 14,627
  • 11
  • 63
  • 93
13
votes
2 answers

Why can't a generic lambda call itself, but wrapping it in a class allows it?

Here is the full example: auto callSelf = [](auto& func) {func(func);}; class wrapper : public decltype(callSelf) { using base = decltype(callSelf); public: wrapper() : base(callSelf) {} template void operator()(T& func)…
xinaiz
  • 6,915
  • 3
  • 26
  • 67
13
votes
1 answer

Java8 Transform list of object to list of one attribute of object

I want to use Java 8 tricks to do the following in one line. Given this object definition: @Getter @Setter @NoArgsConstructor @AllArgsConstructor public class MyObj { private String id; private Double value; } and a List objects, I…
Nik
  • 4,345
  • 10
  • 38
  • 63
13
votes
4 answers

How to implement RowMapper using java lambda expression

I had a working RowMapper code that maps database table row in to a java object. I wanted to change the implementation using lambda expression. However, I am always getting error; Code snippet as follows; String queryString = "select * from person…
nwGCham
  • 243
  • 1
  • 2
  • 14
13
votes
3 answers

Finding a Java lambda from its mangled name in a heap dump

I'm hunting a memory leak, and the heap dump shows me a number of lambda instances are holding the offending objects. The name of the lambda is the surrounding class name with $$lambda$107 at the end. I can also see that it has a single field (it…
ExMathGuy
  • 168
  • 8
13
votes
1 answer

VC++ 15 calls the wrong copy constructor for lambda capture?

Consider the following program: #include struct X { X () = default; X (X &) { std::cout << "non-const called" << std::endl; } X (X const &) { std::cout << "const called" << std::endl; } int i () const { return 7; } }; auto f ()…
JohnB
  • 12,033
  • 4
  • 34
  • 63
13
votes
3 answers

Comparing Java's lambda expression with Swift's function type

In Swift, function types are treated as first class citizens, and can be used anywhere, as any other types. Its syntax is straightforward, and can be easily understood and used. On the other hand, Java does support function programming via lambda…
Thor
  • 8,608
  • 10
  • 43
  • 113
13
votes
2 answers

Comparison : LINQ vs LAMBDA Expression

I need a discussion regarding the Performance of LINQ and Lambda Expression. Which one is better?
Thomas Anderson
  • 1,747
  • 5
  • 16
  • 22
13
votes
3 answers

Java 8 streams "ifPresent"

I am trying to learn about streams and encountered a problem: I want to get the minimal value of a list and assign it to an int variable. For that I did the following: List list = new ArrayList<>(); list.add(1); list.add(2); …
Stefan B
  • 461
  • 2
  • 6
  • 12
13
votes
1 answer

Why does an empty lambda and constructor with an explicit return cause a compiler error (Java Bug?)

I have a reproducible test case: public class TestCase { private final java.util.function.Consumer emptyCallback = result -> {}; public TestCase() { return; } public static void main(String... args) { new…
Rogue
  • 9,871
  • 4
  • 37
  • 66
13
votes
3 answers

Return value by lambda in Java

Till now I manage to find all answers I need but this one confusing me. Let's say we have example code: public class Animal { private String species; private boolean canHop; private boolean canSwim; public Animal(String speciesName,…
Freeman
  • 202
  • 1
  • 2
  • 11
13
votes
2 answers

Can I change my AWS Lambda's public IP on every request?

I would love to get a new public IP every time I make a request. Is it possible to purposefully trigger my IP to be reprovisioned?
ZECTBynmo
  • 2,838
  • 2
  • 20
  • 33
1 2 3
99
100