Questions tagged [lambda]

Lambdas are anonymous functions (i.e. not having an identifier, like methods in a class) which can be used in a wide range of programming languages.

88 questions
116
votes
14 answers

What triggered the popularity of lambda functions in modern mainstream programming languages?

In the last few years anonymous functions (AKA lambda functions) have become a very popular language construct and almost every major / mainstream programming language has introduced them or is planned to introduce them in an upcoming revision of…
Giorgio
  • 19,486
  • 16
  • 84
  • 135
71
votes
3 answers

Is there a performance benefit to using the method reference syntax instead of lambda syntax in Java 8?

Do method references skip the overhead of the lambda wrapper? Might they in the future? According to the Java Tutorial on Method References: Sometimes... a lambda expression does nothing but call an existing method. In those cases, it's often…
GlenPeterson
  • 14,890
  • 6
  • 47
  • 75
61
votes
5 answers

Why doesn't Python allow multi-line lambdas?

Can someone explain the concrete reasons why BDFL choose to make Python lambdas single line? This is good: lambda x: x**x This results in an error: lambda x: x**x I understand that making lambda multi-line would somehow "disturb" the normal…
treecoder
  • 9,475
  • 10
  • 47
  • 84
58
votes
6 answers

What is the difference between a function and a lambda?

I'm a little bit confused about 'function' and 'lambda'. I've seen some examples showing that the scheme keyword lambda works very similarly to the JavaScript keyword function, but I really don't know how they are related. I'm told that 'function'…
Vivian River
  • 2,397
  • 5
  • 21
  • 32
55
votes
6 answers

Is using Lambda expressions whenever possible in java good practice?

I have recently mastered the Lambda expression that was introduced in java 8. I find that whenever I am using a functional interface, I tend to always use a Lambda expression instead of creating a class that implements the functional interface. Is…
SteelToe
  • 1,539
  • 3
  • 13
  • 22
55
votes
3 answers

What is a lambda, and why would it be useful?

So far I heard about : Lambda calculus Lambda programming Lambda expressions Lambda functions Which all seems to be related to functional programming... Apparently it will be integrated into C++1x, so I might better understand it…
jokoon
  • 2,262
  • 3
  • 19
  • 27
54
votes
3 answers

What is the origin and meaning of the phrase “Lambda the ultimate?”

I've been messing around with functional programming languages for a few years, and I keep encountering this phrase. For example, it is a chapter of "The Little Schemer, which certainly predates the blog by this name. (No, the chapter doesn't help…
Eric Wilson
  • 12,071
  • 9
  • 50
  • 77
50
votes
4 answers

Why should I use "functional operations" instead of a for loop?

for (Canvas canvas : list) { } NetBeans suggests me to use "functional operations": list.stream().forEach((canvas) -> { }); But why is this preferred? If anything, it is harder to read and understand. You are calling stream(), then forEach() using…
Saturn
  • 3,887
  • 9
  • 30
  • 40
47
votes
4 answers

C is written in C, how is this possible?

Possible Duplicate: How could the first C++ compiler be written in C++? I know my question goes to the underground galaxy cave where languages are born and involves some lambda math and light-years of google-studying. But what kind of knowledge…
H_7
  • 559
  • 1
  • 4
  • 12
43
votes
10 answers

Does the usage of LINQ and Lambda Expressions lead to less readable code?

I'm having a discussion with a co-worker on Linq, I'll copy here: Co-Worker: Lets be honest here. Linq syntax sucks. It's confusing and non-intuitive. Me: oh come on, more confusing than T-SQL? Co-Worker: uh, yes. Me: it has the same basic parts,…
BlackICE
  • 2,425
  • 1
  • 18
  • 24
41
votes
5 answers

Is a lambda expression something more than an anonymous inner class with a single method?

There is a new hype with the long awaited lambda expressions in Java 8; every 3 day another article appears with them about how cool they are. As far as I have understood a lambda expression is nothing more than an anonymous inner class with a…
Random42
  • 10,370
  • 10
  • 48
  • 65
31
votes
1 answer

Type inference in Java 8

Is the introduction of the new lambda notation (see e.g. this article) in Java 8 going to require some kind of type inference? If so, how will the new type system impact the Java language as a whole?
Giorgio
  • 19,486
  • 16
  • 84
  • 135
31
votes
3 answers

What are the benefits and disadvantages in the approaches of C#, Java and Scala to Closures/Lambdas/...?

I wonder what the technical implementation differences between C# and Scala are and how both solutions compare to the implementation ideas and concerns voiced in the email Peek Past lambda by Brian Goetz, sent to the mailing list of Project Lambda…
soc
  • 381
  • 4
  • 10
26
votes
11 answers

Is it acceptable to use lambda functions\methods in business software?

I've noticed posts on here demonstrating the use of delegates\lambda functions to solve the hole in the middle idea without a lot of repetition: http://www.markhneedham.com/blog/2009/04/04/functional-c-the-hole-in-the-middle-pattern/ The problem…
Peter Smith
  • 2,587
  • 19
  • 21
24
votes
8 answers

Is using lambdas to express intent not pythonic?

PEP 8 states the following about using anonymous functions (lambdas) Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier: # Correct: def f(x): return 2*x # Wrong: f = lambda x:…
N3buchadnezzar
  • 351
  • 2
  • 5
1
2 3 4 5 6