33
votes
Accepted
Implementing any_of in C++
The algorithm looks correct.
Regarding the function signature, I'd make three changes:
You're not modifying elements, so take it by constant reference rather than reference.
You don't need to ...
20
votes
Accepted
Poor man's JIT using nested lambdas
Is there a better way to do this?
Well, you have dynamic dispatch and yet another scattered island of memory for every single token. That is massively inefficient.
A simple way to more efficiency is ...
18
votes
Implementing any_of in C++
I think you did a pretty good job as a beginner. In addition to what Errorsatz said:
Consider making element a const reference to prevent unnecessary copying: ...
7
votes
How to make this nested lambda expression readable?
One giant stream with nested streams with nested streams is very difficult to read. Streams are not a hammer, and not all problems are nails. Code should not try to ram things into streams when they ...
7
votes
A Hit Counter For AWS Python Lambda powered with DynamoDB
[Edited following discussion in the comments]
A few brief notes on your code:
Your type hints could be more complete/descriptive. You don't have any return annotations; the ...
6
votes
Accepted
Attempt at the Most dynamic FizzBuzz possible in Java
The most important problem I have with your code is, that it totally fails to achieve the goal you set yourself. This is not dynamic at all. Basically, you take the "normal" method body and put it ...
6
votes
ConvertAll Methods Implementation for Multidimensional Array in C#
Your code is repetitive. To solve that I'll show some array-related easy cheats.
As @Olivier said, Array implements IEnumerable....
5
votes
Attempt at the Most dynamic FizzBuzz possible in Java
This is suboptimal, and kind of buggy:
String result = tester.test(i);
if(result != "")
System.out.println(tester.test(i));
else
System.out.println(i);
...
5
votes
Accepted
A less limited Python Lambda
Naming:
λ is not a standard Python function name ([a-z] followed by [a-z0-9_]+) and will ...
5
votes
Accepted
Examples of lambda functions, std::for_each / max_element / remove_if etc
For such a simple case this Makefile is a waste.
It can be replaced with:
> rm Makefile
> export CXXFLAGS ="-std=c++17 -Wall -Werror"
> make lambdas
...
5
votes
Python: Function to Find 2 Closest Points Among [x,y] Coordinates
If there are duplicate points in your list, and the closest point turns out to be one of these points, this line of code will remove all of the duplicates:
...
5
votes
Finding the string from the list of array objects
Because the question is about performance and efficiency that's why some sort of benchmarking would be essential to compare different implementations. I have found BenckmarkDotNet really useful for ...
5
votes
Accepted
Regex - Input Checker Class - Lambda with two lists
I would tackle this problem by not adding the last regex to the list but to have this as a separate regex. Using a little "trick" by using ...
5
votes
Accepted
ConvertAll Methods Implementation for Multidimensional Array in C#
I want to present an alternative solution. In .NET, arrays implement IEnumerable. This allows us to iterate multi dimensional arrays as if they were flat. The ...
5
votes
Poor man's JIT using nested lambdas
I will not try to investigate all different kinds of alternatives, but just try to illuminate what your implementation does.
Your code is definitely fine for a quick implementation of something. I ...
5
votes
A Hit Counter For AWS Python Lambda powered with DynamoDB
For your date format,
datetime.datetime.now().strftime("%Y-%m-%d")
is more directly expressed as
...
5
votes
Accepted
2D Matrix in C++
Enable compiler warnings and fix all warnings
When developing code, make it a habit of enabling strict compiler warnings, and fix all the warnings the compiler finds. My compiler complains about ...
5
votes
Accepted
Add offset to all filenames
Reusing function
You can create a constant with Comparator function and reuse it in method.
...
4
votes
Accepted
Reach C++ policy-based common interface with different template parameters from one container
Few minor notes.
You have deliberately assigned -1 to represent undef, correct? The question whether you'll ever need to store -1 aside, you should probably define a named constant to get rid of magic ...
4
votes
Accepted
Simplifying minimum search of two dimensional vector with complex struct
Simplifying isn't enough. I mean, your function is already quite simple, and complexity isn't what's questionable about it. To improve it, I'd suggest to:
handle empty input better
The way you ...
4
votes
Accepted
Extension on Python Lambda capability
I highly recommend that you adopt some sort of testing framework for your tests instead of having a stand alone script. There are quite a few options out there. For instance, ...
4
votes
Accepted
4
votes
On tkinter: scrolling multiple widgets simultaneously in different frames
Remove unnecessary imports
You're importing parts of tkinter twice, Remove this line:
from tkinter import Frame, Canvas, Scrollbar, Button
Then, whenever you ...
4
votes
Accepted
Using lock with value type (multithread context)
Thread safety
I've not tested this, but it looks solid enough, since the only non-trivial logic is held in lock statements. Encapsulation is accordingly good.
...
4
votes
Java - Functional interface for merging two lists
The thing is that the merge function is never called in your case, because all you are doing is reordering an existing map, so IMO you don't really need to worry about it.
Personally in such cases I ...
4
votes
Accepted
Nested std::deque and std::vector Type Test Cases for recursive_transform Template Function in C++
You are correct in your intuition that this isn’t really the best way to do this with Boost.Test. In fact, Boost.Test has about a half-dozen better ways to handle this, but I’ll focus on the one that ...
4
votes
Poor man's JIT using nested lambdas
Technically isdigit(token[0]):
Needs #include <cctype>.
Should be ...
4
votes
Poor man's JIT using nested lambdas
You can do better. But this is a deep rabbit hole.
How about we start with a purely compile-time sublanguage.
...
4
votes
Print sums of pairs from 1 to 10
The code you have provided seems a bit convoluted for such a simple task.
The interface defined is named SumPrinter, but the implementation is storing the result, ...
4
votes
Accepted
Print columns of text without hard coding the width (attempt 2)
Those are some interesting and inventive changes. Here are some thoughs (some new, some of which I missed - or just left out - last time):
First off, a bug: You are assuming that ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
lambda × 219java × 77
c++ × 55
c# × 44
python × 26
c++20 × 20
performance × 16
recursion × 16
stream × 15
functional-programming × 14
generics × 14
template × 13
linq × 11
c++11 × 10
array × 8
entity-framework × 8
hash-map × 7
python-3.x × 6
sorting × 6
comparative-review × 6
boost × 6
beginner × 5
programming-challenge × 5
multithreading × 5
object-oriented × 4