Skip to main content
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 ...
Errorsatz's user avatar
  • 1,374
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 ...
Deduplicator's user avatar
  • 19.9k
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: ...
L. F.'s user avatar
  • 9,705
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 ...
Eric Stein's user avatar
  • 6,716
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 ...
Alex Waygood's user avatar
  • 1,037
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 ...
mtj's user avatar
  • 4,992
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....
aepot's user avatar
  • 2,119
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); ...
200_success's user avatar
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 ...
l0b0's user avatar
  • 9,117
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 ...
Loki Astari's user avatar
  • 97.7k
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: ...
AJNeufeld's user avatar
  • 35.3k
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 ...
Peter Csala's user avatar
  • 10.8k
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 ...
Heslacher's user avatar
  • 51k
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 ...
Olivier Jacot-Descombes's user avatar
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 ...
Carsten S's user avatar
  • 277
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 ...
Reinderien's user avatar
  • 71.1k
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 ...
G. Sliepen's user avatar
  • 69.3k
5 votes
Accepted

Add offset to all filenames

Reusing function You can create a constant with Comparator function and reuse it in method. ...
SRJ's user avatar
  • 237
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 ...
bipll's user avatar
  • 998
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 ...
papagaga's user avatar
  • 5,817
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, ...
Dair's user avatar
  • 6,220
4 votes
Accepted

String comparator as a lambda

You can also chain the Comparators using thenComparing ...
Ankit Soni's user avatar
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 ...
Bryan Oakley's user avatar
  • 2,169
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. ...
VisualMelon's user avatar
  • 7,581
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 ...
RoToRa's user avatar
  • 11.6k
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 ...
indi's user avatar
  • 16.5k
4 votes

Poor man's JIT using nested lambdas

Technically isdigit(token[0]): Needs #include <cctype>. Should be ...
user673679's user avatar
  • 12.2k
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. ...
Yakk's user avatar
  • 1,030
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, ...
Miguel Alorda's user avatar
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 ...
RoToRa's user avatar
  • 11.6k

Only top scored, non community-wiki answers of a minimum length are eligible