A lambda is an expression that acts as an anonymous function. Use this tag if you would like to discuss the appropriateness of a lambda or anonymous function in your code.

learn more… | top users | synonyms

-5
votes
0answers
23 views

Optimise async functions with nested callbacks while using retry pattern [on hold]

I am currently reading some really annoying code. It's basically some weird asynchronous functions with nested lambda/callbacks, and there are some retry pattern involved too. Although I can ...
5
votes
2answers
525 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 ...
0
votes
0answers
30 views

Node AWS lambda with pg-promise

I've written a lambda to perform simple steps to a redshift database. It runs multiple queries with transaction. I use pg-promise. ...
3
votes
1answer
51 views

Numerical streams example

I am reading "Java 8 In Action" (by Raoul-Gabriel Urma, Mario Fusco and Alan Mycroft), section 5.6.3, pages 116 and 117. The code that is presented handles calculating so-called "Pythagorean Triples". ...
6
votes
2answers
141 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, ...
2
votes
0answers
64 views

unordered_multimap approach to adjacency list and graph search

I'm looking for suggestions on how to improve the usage of modern C++ features with this simple graph search algorithm, particularly with regard to the use of STL containers and lambda expressions. ...
3
votes
0answers
48 views

Generic Factory using Function library

Here's my implementation of Generic Factory using Function library. It was created using Function library because I understand that the newInstance method is ...
12
votes
1answer
569 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 ...
1
vote
1answer
60 views

Template binary heap with lambda function comparator C++

This heap will be used for A* search pathfinding in my 2D isometric game engine. It uses lambda functions (instead of std::less or ...
5
votes
2answers
69 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 ...
3
votes
2answers
74 views

Plotting a 2D iso-probability curve

I have a library function that returns a pair of two numbers like this def library_function(x0, x1): return x0**2 + x1**2, 10*x0*x1 + 1 (Actually, it is a ...
2
votes
4answers
188 views

Calling a function on an object if not null

Here is code for check null in object: ...
-1
votes
1answer
34 views

Filled data structure with unique objects that does not have same member variables [closed]

I have in-house template like QList which creates a list of all objects of, say, Book. This list contains many objects of <...
0
votes
1answer
44 views

ConditionalActions through std::function Lambdas

So I just experimented with some code to make a huge if-else construct more human readable, extendable and configurable (switch positions of conditions). The idea was to have a vector that contains ...
0
votes
1answer
71 views

Lambda expression to check even numbers

I wrote this code to check the even numbers from the List. After finding even number I twice the even numbers with the help of <...
1
vote
1answer
77 views

Java Stream - Collections - remove duplicates based on string and presence/absence of local date value

I have a list of objects with a string (name) and a local date (date of deletion). I wish to implement uniqueness on these objects based on: If two objects have the same name, then I wish the one ...
3
votes
1answer
48 views

Memory allocation tracking using anonymous lambda wrapper

I had this idea to exploit anonymous lambdas that are immediately executed that wrap around an allocation function to track those allocations in a statically created Stats object. This is the code I ...
1
vote
0answers
34 views

Producer Consumer With Multiple Dependents

I put together a ProducerConsumer class that wraps the C#'s BlockingCollection class with some bells and whistles (producers can have multiple consumers, consumers can have lambdas, built in parallel ...
3
votes
1answer
75 views

Church Numerals

Here is exercise 2.6 from SICP: Exercise 2.6: In case representing pairs as procedures wasn’t mind-boggling enough, consider that, in a language that can manipulate procedures, we can get by ...
4
votes
1answer
53 views

Lambda to obtain a new merged object

The requirement is to iterate over a list of Foos, and when 2 Foos have the same id merge ...
4
votes
1answer
67 views

Credit card / IMEI check digit in Kotlin

I recently had the need to implement Luhn's Algorithm in a Java/Kotlin application. I needed a function that would add the check digit to the string of a number like a credit card or IMEI. It could be ...
2
votes
1answer
66 views

Finding vowels, digits, whitespaces and consonants

I am creating a simple app to find vowels, digits, whitespaces and consonants. the basic idea is to practice multi-threading and writing readable code. ...
6
votes
1answer
44 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 ...
1
vote
1answer
43 views

What is the best way to extract method?

The code snippet is what I want to do. Previously I use a different version of my code. But it is out of joint according to Python coding guidelines because I was assigned my lambda function to a ...
0
votes
2answers
135 views

Validating input values in C#

I began studying C# 5.0 a few days ago and am trying to avoid duplicated code for validation of input values. ...
3
votes
2answers
638 views

Calculate GS1 / SSCC / UPC check digit

I try to write a function which calculates the check digit for shipping label based on the algorithm provided by GS1 http://www.gs1.org/how-calculate-check-digit-manually Version 1: my first try <...
1
vote
2answers
22 views

advfind() template

This code basically allows you to provide a collection and a lambda and have the lambda operate on each value iterated even allowing modification of the data if you wish. I would like to be able to ...
1
vote
1answer
751 views

Python Pandas Apply with a Lambda Function

I have a table in pandas that has two columns, QuarterHourDimID and StartDateDimID ; these columns give me an ID for each date / ...
4
votes
2answers
77 views

Custom key class for .NET 3.5 framework

I use .NET 3.5 framework, so no tuples. I have many use cases where I have to create a custom key for a dictionary. How can I make this better? ...
3
votes
2answers
168 views

Most efficient dict filter on key tuple?

I have a dict wherein a value needs to be retrievable by any one of several keys. It seemed that making multiple dictionaries or multiple entries in a single ...
2
votes
1answer
96 views

Return most recent DateTime C# Entity Framework

Job -> Many Quotes Quote -> EmailLogList EmailLogList -> Many EmailLogs I want to return a CreatedDate from an EmailLog which has been created most ...
4
votes
1answer
362 views

(C++14) Handling state in C-style function pointer callbacks

I'm having some issues coming up with a sensible solution for using shared state in a C-style function pointer. I am using GLFW to handle my OpenGL context and have created a thin wrapper around all ...
5
votes
2answers
984 views

Custom sorting of dates

I have implemented a class which implements a list of my custom DateObj. I have sorted the list in a peculiar manner based on the current month. I achieved my ...
3
votes
1answer
65 views

Updating all members of a struct in database

This function is part of our company's project code. The following function updates six members of struct CpGSMTimeDelayQuery -- ...
2
votes
1answer
73 views

Writing strings to the screen over time

The following methods just write strings to the screen over time to make it look like a typing effect, instead of all at once. The only difference is the argument in the ...
1
vote
1answer
108 views

JavaFX await implementation

I'm debating trying to take a crack at getting something similar to C#'s async-co-routine like nature over on JavaFX. This is technically feasible since the Quantem toolkit exposes the ...
4
votes
1answer
55 views

Write Once Use Everywhere: Multidimensional array traversal

I have a structure that is organized much like a Sudoku board, where individual cells reside in an n x n region, and those regions reside in an n x n area. I need to be able to address both the ...
1
vote
2answers
197 views

Read a txt file and split into 2 csvs based on regex

So I have been told that my code is not good and needs refactoring. I'm struggling to see what I need to do. How do I specify the success and failure conditions for lambda? Also don't get what the ...
1
vote
1answer
39 views

Use an optionally passed-in block without repeating yourself

I need to open and read several files for a project. Some of them are plain text files, and I just want a standard File.open to read from. One of them is an XML ...
3
votes
4answers
2k views

Checking whether a list is sorted, ascending or descending

What is the best way to conditionally use an operator? All 3 methods seemed acceptable to me, and the last 2 better. If you're curious: I've got a list which is unsorted, and many other lists which ...
1
vote
1answer
478 views

Lambda to collect properties in a child object

I have a class: public class ProductInvoice { //Some other properties. private List<ProductEntry> productEntries = newArrayList(); //otherMethods } ...
5
votes
3answers
423 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. ...
2
votes
1answer
322 views

Routing Java objects using conditional consumers

As per a previous question here and answers I got, I used it to get a new implementation. I found that I have to make two implementations match once "to ignore other consumers after matching once" and ...
12
votes
1answer
250 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 ...
4
votes
2answers
211 views

Function for timing executions (inspired by MATLAB tic toc)

Inspired by MATLAB's tic/toc I've written a short helper function for calculating execution time. ...
10
votes
2answers
2k 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. ...
5
votes
3answers
625 views

Duplicate words in a text

Here is a simplified implementation to obtain the duplicate words in a text using lambda expressions. ...
4
votes
1answer
2k 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 ...
2
votes
1answer
147 views

Sort files by the type of file

I need to sort files by the type of the File. To accomplish the task I first wrote the code below: ...
11
votes
6answers
3k views

Writing the condition x <= y AND x > 0

My current condition is written as follows: ...