As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [lambda]

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.

Filter by
Sorted by
Tagged with
2 votes
0 answers
38 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 ...
V_head's user avatar
  • 515
4 votes
0 answers
65 views

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

If you'd like to print this: ...
candied_orange's user avatar
0 votes
3 answers
215 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: ...
candied_orange's user avatar
0 votes
0 answers
48 views

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

If you'd like to print this: One Two Three Four 1 2 3 4 using this: ...
candied_orange's user avatar
4 votes
1 answer
246 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: ...
candied_orange's user avatar
3 votes
2 answers
205 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. ...
nowox's user avatar
  • 975
2 votes
1 answer
159 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 ...
Wolric's user avatar
  • 123
0 votes
1 answer
190 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 ...
user2102346's user avatar
3 votes
4 answers
138 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 +...
Tathagat Pandey's user avatar
1 vote
1 answer
63 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....
Jessica's user avatar
  • 818
0 votes
1 answer
58 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) ...
Armandas's user avatar
  • 103
0 votes
1 answer
82 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 ...
diaop's user avatar
  • 1
0 votes
1 answer
37 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 ...
Bart Friederichs's user avatar
2 votes
2 answers
122 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 ...
Giuseppe's user avatar
0 votes
1 answer
76 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. ...
John Evans Solachuk's user avatar
2 votes
1 answer
379 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 ...
Greedo's user avatar
  • 2,335
7 votes
2 answers
496 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
  • 875
2 votes
1 answer
286 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, ...
user1095108's user avatar
  • 1,404
0 votes
1 answer
91 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 ...
JimmyHu's user avatar
  • 3,830
3 votes
1 answer
241 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? ...
Vidarbha Yalagadde's user avatar
2 votes
1 answer
103 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 ...
JimmyHu's user avatar
  • 3,830
1 vote
0 answers
68 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 ...
JimmyHu's user avatar
  • 3,830
2 votes
1 answer
104 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 ...
JimmyHu's user avatar
  • 3,830
1 vote
1 answer
330 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 ...
Aleksey's user avatar
  • 101
1 vote
1 answer
608 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 ...
user244048's user avatar
1 vote
0 answers
37 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 ...
Will's user avatar
  • 111
6 votes
0 answers
185 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
0 votes
1 answer
133 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 ...
Miguel Murcia's user avatar
5 votes
1 answer
5k 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
  • 300
25 votes
4 answers
4k 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
  • 44.8k
5 votes
1 answer
978 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 ...
Yanyu Peng's user avatar
-1 votes
2 answers
103 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 ...
Francis Cugler's user avatar
1 vote
0 answers
109 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 ...
JimmyHu's user avatar
  • 3,830
0 votes
1 answer
879 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 ...
amol's user avatar
  • 43
1 vote
1 answer
233 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 ...
JimmyHu's user avatar
  • 3,830
1 vote
1 answer
81 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 <...
JimmyHu's user avatar
  • 3,830
9 votes
2 answers
469 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
  • 3,830
1 vote
0 answers
104 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 ...
Luca Argenti's user avatar
1 vote
1 answer
87 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 ...
JimmyHu's user avatar
  • 3,830
1 vote
0 answers
75 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 ...
JimmyHu's user avatar
  • 3,830
2 votes
1 answer
60 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 ...
JimmyHu's user avatar
  • 3,830
1 vote
1 answer
90 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 ...
JimmyHu's user avatar
  • 3,830
4 votes
2 answers
291 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 ...
JimmyHu's user avatar
  • 3,830
2 votes
1 answer
96 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 ...
JimmyHu's user avatar
  • 3,830
3 votes
1 answer
208 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 ...
JimmyHu's user avatar
  • 3,830
4 votes
1 answer
368 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 ...
Greedo's user avatar
  • 2,335
2 votes
1 answer
76 views

Building a list from the Catresian square of an array

The code generates a list containing all possible combinations of the items of an array. Every triplet of items contains two operands and the third item containing ...
m. vokhm's user avatar
  • 123
2 votes
1 answer
140 views

A recursive_transform Template Function with Execution Policy

This is a follow-up question for A recursive_transform for std::vector with various return type, A recursive_transform Function For Various Type Nested Iterable With std::variant Implementation in C++ ...
JimmyHu's user avatar
  • 3,830
2 votes
1 answer
123 views

A ones Function for Boost.MultiArray in C++

This is a follow-up question for An Element-wise Increment and Decrement Operator For Boost.MultiArray in C++ and A recursive_transform Template Function for BoostMultiArray. I am trying to implement ...
JimmyHu's user avatar
  • 3,830
3 votes
2 answers
1k views

Create dummy variables in dataframe using for loop and apply lambda

I like to compute dummy variables based on the existing values in a dataframe and a dictionary with certain "cut off" points. I wonder whether I need to get rid of the for loop in the ...
Rens's user avatar
  • 133

1
2 3 4 5