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
3 votes
1 answer
241 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
  • 5,214
2 votes
1 answer
167 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
  • 5,214
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
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
3 votes
1 answer
220 views

A recursive_transform Function For Various Type Nested Iterable With std::variant Implementation in C++

This is a follow-up question for A TransformAll Function For Various Type Arbitrary Nested Iterable Implementation in C++. The following code is the improved version based on G. Sliepen's answer. In ...
JimmyHu's user avatar
  • 5,214
2 votes
1 answer
110 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
  • 5,214
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
4 votes
2 answers
2k views

Platform independant thread pool v3

This is a continuation of this question, v4 can be found here Taking the advise given previously, the deadlock was fixed in the non-yielding code. The next problem comes from the suggestion to make ...
Tom Myles's user avatar
  • 432
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: ...
candied_orange's user avatar
3 votes
1 answer
96 views

A recursive_transform for std::array with various return type

This is a follow-up question for A recursive_transform for std::vector with various return type. Thanks to G. Sliepen provide further review suggestions. After digging into the topic of achieving a ...
JimmyHu's user avatar
  • 5,214
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: ...
candied_orange's user avatar
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
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
4 votes
0 answers
80 views

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

If you'd like to print this: ...
candied_orange's user avatar
3 votes
1 answer
110 views

A recursive_transform Template Function for BoostMultiArray

This is a follow-up question for A Sine Template Function For Boost.MultiArray in C++, A recursive_transform for std::array with various return type, A recursive_transform for std::vector with various ...
JimmyHu's user avatar
  • 5,214
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 ...
JimmyHu's user avatar
  • 5,214
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 ...
JimmyHu's user avatar
  • 5,214
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
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
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
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
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
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
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
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
5 votes
1 answer
75 views

A less limited Python Lambda

I've often wanted an anonymous function that would do more than return the result of an expression. So I developed one around the exec function that supports assignments and multiline lambdas but ...
John 9631's user avatar
  • 195
5 votes
2 answers
3k views

Parallel for loop in Java 8

This is my first attempt to provide some syntactic sugar for doing mutually independent loop iterations in parallel. Thanks to Java 8 lambdas, I can write the parallel loops in pretty elegant fashion ...
coderodde's user avatar
  • 28.7k
4 votes
2 answers
127 views

Extension on Python Lambda capability

I asked for assistance creating a Python Lambda function capable of assignments and multi-line lambdas in this post. Following @l0b0's suggestions, I realized that it was better constructed as a ...
John 9631's user avatar
  • 195
2 votes
1 answer
134 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
  • 5,214
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 ...
JimmyHu's user avatar
  • 5,214
2 votes
1 answer
682 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,395
2 votes
1 answer
3k 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 ...
Bassem Reda Zohdy's user avatar
2 votes
1 answer
10k views

Parallel for loop in Java 8 - follow-up

The previous and initial iteration at Parallel for loop in Java 8. Changes are as follows: ParallelLoopBody removed; ...
coderodde's user avatar
  • 28.7k
1 vote
1 answer
98 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
  • 5,214
1 vote
1 answer
86 views

An Element-wise Increment and Decrement Operator For Boost.MultiArray in C++

This is a follow-up question for A recursive_transform Template Function for BoostMultiArray and An Add/Minus Operator For Boost.MultiArray in C++. Besides the add / minus operator for Boost....
JimmyHu's user avatar
  • 5,214
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 <...
JimmyHu's user avatar
  • 5,214
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 ...
JimmyHu's user avatar
  • 5,214
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 ...
JimmyHu's user avatar
  • 5,214
1 vote
1 answer
494 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
  • 173
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 ...
JimmyHu's user avatar
  • 5,214