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,354
19 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.3k
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,570
11 votes

Function to find a certificate in either the user or the machine store

Is the purpose and implementation of this function easier to read with the lambda expression? Or is this utterly confusing? IMHO a separate function is more readable: ...
JanDotNet's user avatar
  • 8,538
11 votes

Function to find a certificate in either the user or the machine store

I agree with @JanDotNet that by using a separate method you will gain readability but that's just my subective view. As you are asking about C#7 stuff I assume that you will use .NET >= 4.6. ...
Heslacher's user avatar
  • 50.4k
9 votes
Accepted

Ordering data by boolean

I wouldn't use either ordering on the server side because it looks like the ordering only matters for displaying the data. I cannot imagine why it should matter from the programmatic point of view. ...
t3chb0t's user avatar
  • 44.3k
8 votes
Accepted

Increment all values in a Map by 1

You must not modify the keys of a HashMap while iterating over it. You are just lucky it worked. Instead of the put(...), write ...
Roland Illig's user avatar
  • 21.3k
8 votes

Function to find a certificate in either the user or the machine store

I'm looking forward to C#7 local functions :) ...but they are already there ;-) This means that your lambda can become a local function. I would also put it last and not first. Since it's a method ...
t3chb0t's user avatar
  • 44.3k
7 votes
Accepted

Count how many times a value is referenced in a grid

There is no intermediate operation that groups items by key. But in your example there are some changes that can make code more readable. Instead of collectiing to ...
Nazarii Bardiuk's user avatar
7 votes
Accepted

Calculate working days and excluding specific dates (Holidays)

Bug There is a bug in this method. It counts non-working days because the workDay condition needs to be negated. ...
t3chb0t's user avatar
  • 44.3k
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,514
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,029
6 votes
Accepted

Calling a function on an object if not null

To be sure it always works you should add a constraint to the method: where TInput : class This will ensure that TInput is a ...
t3chb0t's user avatar
  • 44.3k
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,822
5 votes

Too much fun with EnumMap-related features and lambdas?

Error Handling Why not use NullPointerException (by way of validateArguments, which - as @Pimgd noted - is better done using ...
Stevel's user avatar
  • 151
5 votes
Accepted

Creating a pipeline operator in Java

This starts getting messy quickly, preventing authors from writing readable one-line expressions. Based on this statement, I don't get, how you want to use your code. You definitely don't want to ...
mheinzerling's user avatar
  • 2,724
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

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
  • 95.3k
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
  • 8,917
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
  • 33.7k
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
  • 9,279
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
  • 50.4k
5 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,019
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
  • 62.4k
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

What is the best way to extract method?

db_data = {} def create_info(db_data, …): … return db_data new_db_data = create_info(db_data, …) This feels plain wrong. Either your ...
301_Moved_Permanently's user avatar
4 votes

advfind() template

You don't need std::function, and may do: ...
Jarod42's user avatar
  • 566
4 votes
Accepted

Lambda to obtain a new merged object

To determine the result you're after, it is necessary to group by the id and hold a temporary map of the grouping operation. You can make it a bit simpler, and not have a second Stream pipeline, by ...
Tunaki's user avatar
  • 9,233
4 votes
Accepted

Accessing properties by name with compile-time typesafety

Expressions & Factories ...
t3chb0t's user avatar
  • 44.3k
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 ...
bipll's user avatar
  • 988

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