Questions tagged [lambda]
Use this tag if you would like to discuss the appropriateness of a lambda (anonymous) function in your code.
219 questions
3
votes
1
answer
106
views
Adding Lambda to Path
Previously I wrote a very generic HTTP handler.
But in real life the server needs to be able to handle different functions on different paths. i.e. /rest/addUser ...
5
votes
0
answers
101
views
Excel Lambdas for Filtration Lookup
Background
I have an ongoing challenge in Excel, where I must match differing descriptions of the same object. Originally, there were only two alternatives:
Use a dropdown list in Excel, which pulls ...
2
votes
0
answers
50
views
A recursive_replace_copy_if Template Function with Unwrap Level Implementation in C++
This is a follow-up question for A recursive_replace_copy_if Template Function Implementation in C++. I am trying to implement recursive_replace_copy_if template ...
3
votes
1
answer
131
views
In Java, replace for loop with condition with lambdas [closed]
I want to replace a for loop with a break/return condition inside with a lambda.
I think I have a good replacement, but I want ...
1
vote
1
answer
132
views
Find Method Implementation for Multidimensional Array in C#
I found that Array.Find(T[], Predicate) Method is only support one dimensional array. I am trying to generalize it to multi-dimensional array in this post.
The experimental implementation
The ...
3
votes
1
answer
136
views
Portable lambda emulation in C
For fun I decided to try to emulate lambda functions in plain old C. It turns out it can be easily done with a bit of macro abuse.
CLambda struct stores function ...
2
votes
2
answers
156
views
Find all line numbers of prefix duplicates with streams
All line indices of lines from a text that begin with the same line prefix should be found. The prefixes and the corresponding line numbers should be returned. Streams and lambdas should be used as ...
3
votes
2
answers
217
views
Add offset to all filenames
From all the files in a directory, the method shiftFilenamesOffset is to increment the numeric part (int) of the alphanumeric filename by offset each time, and ...
2
votes
1
answer
94
views
Lazy evaluation vs strict one applied to fib
I have this OCaml problem:
Recall the polymorphic type lazy seen in class, the function delay which transforms a ...
4
votes
0
answers
111
views
Print columns of text without hard coding the width (attempt 5)
If you'd like to print this:
...
0
votes
3
answers
329
views
Print columns of text without hard coding the width (attempt 4)
If you'd like to print this:
One Two Three Four
1 2 3 4
using this:
...
4
votes
1
answer
313
views
Print columns of text without hard coding the width (attempt 2)
If you'd like to print this:
One Two Three Four
1 2 3 4
using this:
...
4
votes
2
answers
578
views
2D Matrix in C++
I wanted to play with a two-dimensional generic data container in C++ and explore different methods of traversals: using closures and iterators. I'd like a review of it.
...
3
votes
1
answer
249
views
Finger Exercise: Update book cipher by creating new book
I'm working my way through the finger exercises in John Guttag's book Introduction to Python Programming, third edition. The following finger exercise on page 143 describes encryption/decryption with ...
0
votes
1
answer
606
views
Compute the goals scored by football teams in their matches in a season, from json data
Please look at the Java Stream methods in the for each loop.
This method totals the score for when the your desired team is playing during the football season - input param teamKey - it is either ...
3
votes
4
answers
199
views
Print sums of pairs from 1 to 10
This takes the sum of pairs of numbers from 1 to 10 and outputs the sum, the original numbers, and some connecting text. Output:
intArray.length 10
{Sum of + 1 and 2 =3, Sum of + 3 and 4 =7, Sum of +...
2
votes
1
answer
108
views
Meta Collatz Sequence
Context
Chapter 6 of Learn You A Haskell contains a function called chain, which outputs the Collatz sequence of a given input.
(In short, it takes a natural number....
0
votes
1
answer
90
views
Class accepting data input by variable, function pointer or lambda
Background
I am writing a library that takes some data from the user and works with it. I was experimenting with ways to allow users to provide the data by the following methods:
As a (global) ...
0
votes
1
answer
121
views
Avoiding Java stream repeated code using lambdas
This is the code for adding addon product to carts. Suppose the cart has a cake so a candle would be an addon. I see this ...
0
votes
1
answer
60
views
Is using except TypeError the right way to do this? [closed]
I have some code that uses a lambda to enhance the functionality. For backward compatibility reasons, this lambda can take one or two arguments. To handle these ...
2
votes
2
answers
195
views
Radio with channels
Realize the Radio and Channel classes that represent radio and a radio station. The radio class offers an argumentless constructor and the following methods:
addChannel: stores and returns a new ...
0
votes
1
answer
113
views
Simplify this code that adds string representation of class members to a List [closed]
I have a bunch of code that adds the string representation of members in a class to a List.
...
2
votes
1
answer
803
views
=PRINTF("{1} - {2}", ... ) in Excel without VBA - LAMBDA functions with variable number of arguments
The TEXTJOIN function has a really nice interface:
=TEXTJOIN(delimiter, ignore_empty, text1, [text2], …, [text252])
... where ...
7
votes
2
answers
600
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 ...
2
votes
1
answer
517
views
splitting a tuple into N-element tuples
This nice hack should allow you to split a tuple into N-element tuples, thereby effectively splitting a tuple into pairs, triples, ... For example, this allows you to split an input parameter pack, ...
1
vote
1
answer
141
views
Image pixelwise operation function with multiple inputs in C++
This is a follow-up question for Tests for the operators of image template class in C++ and A recursive_transform template function for the multiple parameters cases in C++. I appreciated G. Sliepen's ...
3
votes
1
answer
394
views
Delete older EBS Volume snapshots except few with certain tags using Python, Lambda
I am learning Python and managed to accomplish the above. But my script doesn't seem optimal. Could someone help to take a review and suggest for betterment?
...
2
votes
1
answer
155
views
A recursive_transform template function for the multiple parameters cases in C++
This is a follow-up question for A recursive_transform template function for the binary operation cases in C++. Thanks for G. Sliepen's answer. Based on the mentioned suggestion, I am attempting to ...
2
votes
1
answer
147
views
A recursive_transform template function for the binary operation cases in C++
This is a follow-up question for A recursive_transform Template Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++ and A recursive_print Function For Various ...
1
vote
1
answer
557
views
An implementation of Uber's "Fare Estimator" [CodeSignal]
CodeSignal put out a challenge by Uber that involves writing a "fare estimator" that involves a function dependent on cost per minute, cost per mile, ride time and ride distance.
The formula ...
1
vote
1
answer
1k
views
How to make this nested lambda expression readable?
This is the code that joins the list with another one. Also makes use of a static utility to makes use of hashmap for id and name.
I've added null checks to safeguard the code with NPE.
The key ...
6
votes
0
answers
321
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 ...
0
votes
1
answer
218
views
Correct use of Serializable with lambda functions
I'm practicing saving and reading serializable objects when a friend told me serializable objects have no use in real life, that I'd better focus on JSON or XML to serialize my objects when I came ...
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 ...
26
votes
5
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 ...
5
votes
1
answer
2k
views
Emplace a lambda which captured a unique_ptr into container like queue
I'd like to emplace a lambda which captured a unique-pointer into a container, but it failed to compile under GCC 7.3.0 as C++17. From the error messages, it's calling the copy constructor of ...
-1
votes
2
answers
339
views
Using a lambda to generically create an arbitrary class wrapper around some object of type T [closed]
While experimenting with some of C++'s language features, I was able to successfully design an invokable nameless function call through the use of a lambda that generically creates an arbitrary class ...
0
votes
0
answers
134
views
A Generic Two Dimensional Data Plane with Common Math Calculation Build-in Methods in C#
This is a follow-up question for A Generic Two Dimensional Data Plane with SubPlane Method in C#. Thanks to aepot's answer.
I am trying to implement a series methods to enhance the ability and ...
0
votes
1
answer
2k
views
Is this the right way to do lambda method chaining in python? [closed]
I come from java background and I am trying to implement lambda chaining in Python. Below is my code
...
1
vote
1
answer
357
views
ConvertAll Methods Implementation for Jagged Arrays in C#
This is a follow-up question for ConvertAll Methods Implementation for Multidimensional Array in C# and ConvertAll Methods Implementation for Multidimensional Array in C# - follow-up. Besides the ...
1
vote
1
answer
115
views
ConvertAll Methods Implementation for Multidimensional Array in C# - follow-up
This is a follow-up question for ConvertAll Methods Implementation for Multidimensional Array in C#. Thanks to aepot's answer and Olivier's answer. In order to match the usage of the build-in API <...
10
votes
2
answers
737
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 ...
1
vote
1
answer
136
views
A Function Applier for Applying Various Algorithms on Nested Container Things in C++
This is a follow-up question for A recursive_replace_if Template Function Implementation in C++, A recursive_copy_if Template Function Implementation in C++, A recursive_count_if Function with Unwrap ...
2
votes
1
answer
137
views
A recursive_replace_copy_if Template Function Implementation in C++
This is a follow-up question for A recursive_copy_if Template Function Implementation in C++. Besides the recursive version std::ranges::copy_if, I am trying to ...
2
votes
1
answer
96
views
A recursive_copy_if Template Function Implementation in C++
This is a follow-up question for A recursive_transform for std::vector with various return type and A recursive_transform Template Function Implementation with std::invocable concept in C++. Besides ...
1
vote
1
answer
132
views
A recursive_transform Template Function Implementation with recursive_invoke_result_t and std::ranges::transform in C++
This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++, A recursive_transform Template Function Implementation with std::invocable ...
5
votes
2
answers
406
views
Nested std::deque and std::vector Type Test Cases for recursive_transform Template Function in C++
This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++, A recursive_transform Template Function ...
2
votes
1
answer
149
views
A recursive_transform Template Function Implementation with std::invocable Concept and Execution Policy in C++
This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++ and A recursive_transform Template ...
3
votes
1
answer
286
views
A recursive_transform Template Function Implementation with std::invocable concept in C++
This is a follow-up question for A recursive_transform for std::vector with various return type, A recursive_transform Template Function with Execution Policy, A recursive_count_if Template Function ...
4
votes
1
answer
456
views
Recursive LAMBDA() function to create a formula that adds internal separators to a string in Excel
I have created a named function with signature PadInternal(base, width, paddingStr) where:
base is a string you want to add ...