Skip to main content

Questions tagged [lambda]

Use this tag if you would like to discuss the appropriateness of a lambda (anonymous) function in your code.

Filter by
Sorted by
Tagged with
31 votes
2 answers
1k views

Dynamically call lambda based on stream input

Some context: I have code that looks like this (minor issue noted here): ...
Loki Astari's user avatar
  • 95.3k
26 votes
4 answers
5k views

Poor man's JIT using nested lambdas

While answering this code review question, I came up with a way to convert an equation given at runtime to a std::function<double(double)> that would evaluate ...
G. Sliepen's user avatar
  • 58.3k
23 votes
6 answers
5k views

Implementing any_of in C++

I've decided to implement Python's any in C++. I've gone about this using templates to allow multiple types of data to be passed, instead of overloading the ...
Linny's user avatar
  • 10.2k
19 votes
6 answers
15k views

Increment up the build number in AssemblyInfo.cs on every build

I just wrote this short little program to increment up the build number for my projects every time I build them. After compiling this exe, I just call it in the pre-build command line. I did take ...
BenVlodgi's user avatar
  • 4,278
18 votes
3 answers
27k views

Effective use of multiple streams

I am experimenting with streams and lambdas in Java 8. This is my first serious foray using functional programming concepts; I'd like a critique on this code. This code finds the Cartesian product of ...
MonkeyWithDarts's user avatar
17 votes
1 answer
623 views

Python Dictionary Black Magic

I am defining a subclass of a the python dictionary object mpCmd where every item is converted to a lambda. The intended usage is that every item in the dictionary ...
cheezsteak's user avatar
  • 2,401
16 votes
8 answers
4k views

Long function as a lambda, right or wrong? [closed]

I have been reviewing the code of a new co-worker and, although in general I think it's OK, there's a thing that causes me mixed feelings: ...
raven's user avatar
  • 293
15 votes
3 answers
1k views

Basic Rock-Paper-Scissors implementation

I decided to try to make a simple RPS implementation in Java 8, the following notes should be said first: At a later point it should support RPSLS aswell, as any other Gesture-game variant. At a ...
skiwi's user avatar
  • 10.6k
14 votes
2 answers
913 views

Collatz conjecture using Java lambdas

Take any natural number n. If n is even, divide it by 2 to get n / 2. If n is odd, multiply it by 3 and add 1 to obtain 3*n* + 1. Repeat the process (which has been called "Half Or Triple Plus One", ...
h.j.k.'s user avatar
  • 19.2k
13 votes
3 answers
5k views

The Beauty and the Strings

This originally appeared in Facebook's hacker cup 2013. Solving it was fun, though I find myself looping through similar data quite often. Challenge: Print the maximum beauty of strings. ...
Legato's user avatar
  • 9,829
12 votes
3 answers
17k views

Function to find a certificate in either the user or the machine store

I wanted a function that would return a certificate, given its serial number, regardless of which store it is in. It has to do almost the same exact thing but twice (once for each store). To keep it ...
John Wu's user avatar
  • 631
12 votes
1 answer
827 views

Mandelbrot Streams

A recent Mandelbrot question (Hi @EBrown) in C# inspired me to build my own using the Java 8 parallel streams to implement the parallelism that's useful for computing each pixel value. The intention ...
rolfl's user avatar
  • 97.4k
12 votes
2 answers
709 views

Printing removed items using lambdas and streams

I'm struggling to make my lambdas readable. I've seen various approaches. Below are three different examples that all do the same thing. Forgive the example: I suspect there are better actual ...
David Lavender's user avatar
11 votes
6 answers
3k views

Writing the condition x <= y AND x > 0

My current condition is written as follows: ...
barnacle.m's user avatar
11 votes
4 answers
200k views

Using LINQ or Lambda instead of nested and multiple foreach statements

I want to use a better syntax than nested foreach statements to overwrite the initial list with items from the second list. In the code below: I want to overwrite ...
ken1nil's user avatar
  • 221
11 votes
2 answers
209 views

Dynamically call lambda based on stream input: Try 2

Originally asked here: Dynamically call lambda based on stream input The following version is based heavily on the answer provided by @iavr, though I hope that I have done enough more to make it ...
Loki Astari's user avatar
  • 95.3k
11 votes
2 answers
698 views

A method that generates a Comparator<String> using lambda expression

Given below is an exercise from the book *Java SE 8 for the Really Impatient( by Cay S. Horstmann: Write a method that generates a Comparator that can be normal or reversed, case-sensitive or ...
Kiran Mohan's user avatar
11 votes
1 answer
609 views

Pokemon type evaluator - follow-up

I started anew and completely refactored the way I implemented Pokemon type evaluator. Also, first use of a lambda expression (Case of using it, but still don't fully grasp how it's working). I'm ...
Legato's user avatar
  • 9,829
11 votes
2 answers
19k views

Return lambda expression based on parameters

This function returns a lambda expression based on the parameters sent. I am sure there is a better way to do this. ...
Sean Thorburn's user avatar
11 votes
1 answer
8k views

Creating a pipeline operator in Java

I wrote the following as more of an experiment than anything else, but I thought it would be fun to share and maybe get some feedback! Motivation: I started looking at some functional languages and ...
flakes's user avatar
  • 1,925
10 votes
3 answers
949 views

Displaying information about people from a JSON file

I'm working with Python 2.7.5 and I have written the following code: ...
user2421117's user avatar
10 votes
2 answers
6k views

C-ifying a capturing lambda

What do you think of this code? ...
user1095108's user avatar
  • 1,434
10 votes
2 answers
6k views

Too much fun with EnumMap-related features and lambdas?

I have an utility class to handle EnumMap-related features, such as creating/converting between Object -> Enum and ...
h.j.k.'s user avatar
  • 19.2k
10 votes
3 answers
3k views

Converting between data and presentation types

Below is how I'm solving the problem of converting between data and presentation types, I'd like to know if that's a good way to go about it, and if not, what would be a better way to go about it. I ...
Mathieu Guindon's user avatar
10 votes
1 answer
113 views

Shady Characters

As part of my familiarization with the features of Java 8, and inspired by this question, I thought I would take the 'Shady Character' problem to 'the next level'. The basic problem is that you have ...
rolfl's user avatar
  • 97.4k
10 votes
1 answer
2k views

EF6-Lambda Expressions deep big-tree query

I am looking to improve the following query. We are using EF6 (CodeFirst) and C# Lambda Expressions, and Repository/Unit of Work patterns. Also, we needed to restrict the query in a way that we ...
beto_ve's user avatar
  • 103
9 votes
2 answers
669 views

ConvertAll Methods Implementation for Multidimensional Array in C#

I am trying to perform some conversions with multidimensional array in C# and I have checked the discussion ConvertAll and 2-dimensional arrays. I found that ...
JimmyHu's user avatar
  • 5,214
8 votes
3 answers
451 views

Sending duplicate to heaven with Java 8

Follow up to Duplicate like a weapon, arrays like heaven. @rolfl suggested in chat that I try to complete this challenge again in a Java 8 friendly way. I took the opportunity to also employ the ...
Legato's user avatar
  • 9,829
8 votes
2 answers
9k views

Accessing properties by name with compile-time typesafety

I've recently answered a question here, where the goal is to mimic some functions from System.Reflection in order to avoid it's direct usage as much as possible, ...
Denis's user avatar
  • 8,508
7 votes
2 answers
3k views

Simple calculator implemented with lambdas

I was searching for a way to exercise the Java 8 concepts I've been learning, especially pertaining to Lambdas. Incidentally, I hadn't used any swing in a while and wanted a refresher. This is the ...
Legato's user avatar
  • 9,829
7 votes
2 answers
550 views

A Hit Counter For AWS Python Lambda powered with DynamoDB

I'm learning how to use DynamoDB and various AWS services, so I decided to write a simple hit counter application for my education of how to use DynamoDB. This application deduplicates hits from the ...
HSchmale's user avatar
  • 895
7 votes
2 answers
6k views

Increment all values in a Map by 1

What's the neatest way to increment all values in a HashMap by 1? The map is <String, Integer>, but the key doesn't matter ...
rococo's user avatar
  • 287
7 votes
1 answer
30k views

Event-listener implementation

While writing a C++ GUI application more or less from scratch I needed some form of an event-listener system, preferably using lambdas. An event should be able to have multiple listeners and the user ...
Lars Melchior's user avatar
7 votes
1 answer
242 views

Effective use of branch prediction in terrain generator

I am trying to learn how branch optimization works. For an experiment, I have a recursive fractal terrain generation and I have moved all if statements to binary ...
MichaelMitchell's user avatar
7 votes
2 answers
16k views

A generic way to use LINQ to Entity with types and operations unknown until run time

A question was asked here about reflection and LINQ to entity. I'm trying to modify the code that was presented to fit my needs. Here's what I am trying to accomplish: I'm writing back-end support ...
David's user avatar
  • 171
7 votes
1 answer
810 views

Elixir pipes and anonymous functions

I recently got started with Elixir. I'm used to F#'s pipes, and Seq.map and LINQ's .Select statements. Things are different in ...
Frames Catherine White's user avatar
7 votes
1 answer
786 views

Proper checked exception handling with lambda functions

I'm having trouble finding a clean way to handle checked exceptions thrown by a lambda function passed as a parameter in Java. I'm writing a Client which will interact via RMI with a Server to play a ...
gcali's user avatar
  • 203
6 votes
3 answers
6k views

Ordering data by boolean

I have a bit of EF Lambda code which returns a list of data from the db table, then orders by a field called IsDefault At first, the code was ...
PurpleBeans's user avatar
6 votes
1 answer
58 views

Count how many times a value is referenced in a grid

I've got list of points: List<Point> seedPoints. Each Point contains x and ...
Tinki's user avatar
  • 161
6 votes
2 answers
173 views

Filtering a list of customers in Java based on three criteria

Let's assume that you need to filter customers based on 3 criteria: name tags assigned to customer customer's location For some reasons you have to do it directly in your program code, without ...
matvs's user avatar
  • 161
6 votes
2 answers
426 views

Beta Reducer in Haskell

This is my first Haskell application, so any non-name-calling tips will be taken extremely well! It is just a beta reducer: ...
MaiaVictor's user avatar
  • 1,101
6 votes
1 answer
135 views

Generic Timing Class

I have written a class which can time functions, and I'd like to have it reviewed. I'm interested in everything (better naming and commenting, accuracy of measurement, usability, structure, use of ...
tim's user avatar
  • 25.1k
6 votes
2 answers
104 views

Printing the max of groups of three random ints

I'm trying to teach myself streaming and lambda expressions. Here's the scenario: I have a collection of 10 Thing objects each containing an int[] of 3 random number. I've written code to print out ...
TotallyNotMoseying's user avatar
6 votes
2 answers
2k views

Fill a vector with uniformly distributed random complex numbers

I want to fill an array of complex numbers using a uniform generator. I thought up the next code. (Complex is a simple fixed-point complex data type.) ...
JHBonarius's user avatar
6 votes
1 answer
2k views

Fixed point combinator in C++1x

This has been tested and compiled under Visual Studio 2010. Are there any serious problems with this implementation? PS. This implementation is fully lambda expression based. If I can make ...
Earth Engine's user avatar
6 votes
1 answer
8k views

C++ event loop and thread signaling

Use case This is an event loop and signaling system I created for a piece of software which will have multiple asynchronous server/clients/event-emitters/ui, some of those components will have their ...
fededevi's user avatar
  • 320
6 votes
1 answer
914 views

Combining contents of files by reading them in a human ordering

This code review is inspired by the this StackOverflow question and written in Java 8. The code is supposed to: Order all files, with syntax jobXXX.script, where <...
skiwi's user avatar
  • 10.6k
6 votes
0 answers
297 views

Create 'classical' visitor from lambdas

I've watched a talk by Fedor Pikus on design patterns held at CppCon 2019. Motivated by this, I wrote my own visitor implementation and some helpers which allow me to create a visitor from a couple of ...
StefanKssmr's user avatar
5 votes
3 answers
2k views

Filtering units by a dynamic Lambda expression

I have a simple if statement which, based on user input, determines which expression is going to be utilized. It looks like it can be done better. ...
Vadims Samsinovs's user avatar
5 votes
4 answers
2k views

Duplicate words in a text

Here is a simplified implementation to obtain the duplicate words in a text using lambda expressions. ...
Thomas Mathew's user avatar

1
2 3 4 5