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
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. ...
3 votes
1 answer
93 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
80 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
92 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 ...
1 vote
1 answer
495 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 ...
2 votes
2 answers
104 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
183 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
0 answers
41 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
80 views

Print columns of text without hard coding the width (attempt 5)

If you'd like to print this: ...
0 votes
3 answers
232 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: ...
5 votes
2 answers
9k 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 <...
4 votes
1 answer
265 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: ...
1 vote
1 answer
89 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 ...
3 votes
2 answers
522 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. ...
2 votes
1 answer
206 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
528 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
164 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 +...
1 vote
1 answer
75 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....
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 ...
0 votes
1 answer
185 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 ...
2 votes
1 answer
196 views

Using std::function to write a function that returns a function

Our C++ professor told us to practise the use of std::function, lambda and pointers to functions. He asked us to: Write the function ...
0 votes
1 answer
62 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) ...
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 ...
0 votes
1 answer
85 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 ...
2 votes
1 answer
684 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 ...
0 votes
1 answer
38 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 ...
1 vote
0 answers
77 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 ...
3 votes
1 answer
370 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
2 answers
147 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
95 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. ...
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 ...
2 votes
1 answer
465 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, ...
0 votes
1 answer
98 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 ...
1 vote
0 answers
71 views

A recursive_transform template function for the binary operation cases with execution policy in C++

This is a follow-up question for A recursive_transform template function for the binary operation cases in C++, A recursive_transform Template Function with Unwrap Level for Various Type Arbitrary ...
2 votes
1 answer
117 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
106 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
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 ...
1 vote
0 answers
45 views

Fetch the nearest city, optimised with Redis on a Lambda

I have a lambda function which returns the nearest city from a latitude and longitude. My algorithm for this is resource heavy and time consuming. To optimise this, I hash the coordinates into a 6 ...
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 ...
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
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 ...
4 votes
1 answer
411 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 ...
1 vote
0 answers
111 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 ...
1 vote
0 answers
125 views

A Bspline module for AMO

Here is a (reduced version of) a module for Bsplines, which I have used multiple times for my work on Atomic, Molecular, and Optical physics (AMO, in the trade lingo, a.k.a. "I love", in ...
-1 votes
2 answers
268 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 ...
1 vote
1 answer
325 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 ...
0 votes
1 answer
1k 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
91 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 <...
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 ...
2 votes
1 answer
65 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
2 3 4 5