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.
1
vote
1answer
36 views
Asynchronous connect() with one function call, using C++11 lambdas and Boost.Asio
I've wanted to write a C++11 class for making IPv4 TCP connections and figured that it probably could be done with just one static function using some shared_ptr and lambda "magic". The following code ...
7
votes
2answers
81 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 ...
5
votes
1answer
304 views
9
votes
3answers
386 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.
...
3
votes
0answers
35 views
Java 8 CompletableFuture - fan out implementation
I was wondering what is the best way to implement a fan out type of functionality with Java 8 Completable future. I recently rewrote a function that had a bunch of old ...
8
votes
3answers
94 views
Sending duplicate to heaven with Java 8
Follow up to Duplicate like a weapon, arrays like heaven.
@rolfl suggested in chat that I try to complete this challenge again in a Java 8 friendly way. I took the opportunity to also employ the ...
6
votes
4answers
966 views
Using LINQ or Lambda instead of nested and multiple foreach statements
I want to use a better syntax than nested foreach statements to overwrite the initial list with items from the second list.
In the code below:
I want to ...
5
votes
1answer
64 views
Effective use of branch prediction in terrain generator
I am trying to learn how branch optimization works.
For an experiment, I have a recursive fractal terrain generation and I have moved all if statements to binary ...
0
votes
0answers
33 views
Parallel for loop in Java - follow-up 2
The previous iteration at Parallel for loop in Java 8 - follow-up.
The changes are as follows:
MyTask is removed.
Synchronization removed. Now the user is ...
1
vote
1answer
96 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; ...
3
votes
2answers
90 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 ...
3
votes
1answer
132 views
How can I avoid repeated code using lambdas?
I have a method which should accept a Function/Action and do something with that method (in my case I've added retry logic).
I'm wondering how I can remove the duplicated code (for loop, etc) from ...
1
vote
1answer
107 views
Cleaner way to map array of objects in CoffeeScript
Im wondering if there is a cleaner way to write this -
map = (obj) ->
$scope.data.push({name : obj.name, id : obj.id})
map obj for obj in objArr
...
2
votes
1answer
53 views
Conditional statements with doctor and patient information
I'm focusing on trying to write clean, modular Python 2.7.5 code.
...
3
votes
1answer
27 views
Generic Timing Class - Follow Up
I wrote a class which can time and compare functions.
I already posted it here once before, and got great suggestions from @rolfl, which I have added to my code.
my original question can be found ...
10
votes
3answers
893 views
Displaying information about people from a JSON file
I'm working with Python 2.7.5 and I have written the following code:
...
6
votes
1answer
54 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 ...
11
votes
2answers
231 views
Collatz conjecture using Java lambdas
From the Wikipedia article:
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 ...
12
votes
3answers
296 views
Basic Rock-Paper-Scissors implementation
I decided to try to make a simple RPS implementation in Java 8, the following notes should be said first:
At a later point it should support RPSLS aswell, as any other Gesture-game variant.
At a ...
8
votes
1answer
212 views
Too much fun with EnumMap-related features and lambdas?
I have created an utilities class to handle certain EnumMap-related features, such as creating and converting between ...
9
votes
1answer
63 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'.
Find sum of number of times that ...
1
vote
1answer
121 views
Group by two lists in one map using lambda
I've got two collections: collection of rules, and collection of keys that can handle specific rules. Key have method ...
8
votes
2answers
136 views
A method that generates a Comparator<String> using lambda expression
Given below is an exercise from the book *Java SE 8 for the Really Impatient( by Cay S. Horstmann:
Write a method that generates a Comparator that can be normal or
reversed, case-sensitive or ...
6
votes
1answer
189 views
Elixir pipes and anonymous functions
I recently got started with Elixir. I'm used to F#'s pipes, and Seq.map and LINQ's .Select statements. Things are different in ...
7
votes
1answer
159 views
Pokemon Type Evaluator part 2
I started anew and completely refactored the way I implemented Pokemon Type Evaluator.
Also, first use of a lambda expression (Case of using it, but still don't fully grasp how it's working). I'm ...
3
votes
2answers
350 views
Removing hackery from pair of radix functions
I like the radix function and found a really neat way to compute its inverse in Python with a lambda and reduce() (so I really feel like I'm learning my cool ...
2
votes
1answer
288 views
Is there better way to shorten this Lambda expression's result selector?
I'm new in LINQ and Lambda expression. I'm not sure is there a way to shorten the result on this o.z.cust.cust.cust.bintAccountNo. As you can see below, the more ...
10
votes
1answer
560 views
EF6-Lambda Expressions deep big-tree query
I am looking to improve the following query.
We are using EF6 (CodeFirst) and C# Lambda Expressions, and Repository/Unit of Work patterns. Also, we needed to restrict the query in a way that we ...
14
votes
3answers
2k views
Effective use of multiple streams
I am experimenting with streams and lambdas in Java 8. This is my first serious foray using functional programming concepts; I'd like a critique on this code.
This code finds the Cartesian product of ...
2
votes
1answer
175 views
Refactor Oracle Entity Framework lambda query
I had a ugly problem and wrote an ugly query.
Query creates a cache that is used to get person id when I have {full_name, id_code?, birth_date?}. By question mark I mean that it is perfectly valid ...
4
votes
2answers
397 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 ...
6
votes
1answer
4k views
A generic way to use LINQ to Entity with types and operations unknown until run time
A question was asked here about reflection and LINQ to entity. I'm trying to modify the code that was presented to fit my needs.
Here's what I am trying to accomplish: I'm writing back-end support ...
3
votes
1answer
168 views
Exception handling with expression lambda in Presenter class
Following is a code snippet from MVP Win Forms application.
My DAL doesn't handle exceptions and it will be propagated up to the calling method in the presenter classes where the exception will be ...
2
votes
3answers
205 views
Boost::range::for_each + functor
I would like your comments on my code in C++ (C++98 + Boost)
I have written some code to use the functors with the boost::range::for_each algorithm.
My main ...
1
vote
2answers
122 views
Validate fields in Python dictionary using dictionary of lambdas
I would love some feedback on this. I use it to validate web-form objects before persisting them in the dangerously-lazy MongoDb. I have a class and many validators for each of my collections. Is ...
1
vote
1answer
190 views
Excessive use of lambda with variant of Sieve of Eratosthenes?
This is a function which produces the sum of primes beneath (not including) a certain number (using a variant on the sieve of Eratosthenes).
...
2
votes
1answer
49 views
13
votes
1answer
252 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 ...
2
votes
2answers
6k views
Sum(), ForEach() with Lambda in a hierarchical List Collection
I have to list the number of documents related to items in a hierarchical tree.
The specification states:
The tree will only ever be 2 levels deep.
The higher level items will list not only the ...
3
votes
2answers
1k views
C++11 factory pattern with lambdas
Anonymous functions are one of the best features of C++11. They make everything so beautiful!
However, one can get carried away and start overusing them.
This code calls a function that reads ...
2
votes
2answers
162 views
Mixing Linq queries and Linq lambdas
I have been given a change to rewrite an old framework we use, and to implement the repository and unit of work patterns, but in an attempt to not rewriting all queries I have ended up with a weird ...
18
votes
2answers
544 views
Dynamically call lambda based on stream input
Some context: I have code that looks like this (minor issue noted here):
...
11
votes
6answers
2k views
Increment up the build number in AssemblyInfo.cs on every build
I just wrote this short little program to increment up the build number for my projects every time I build them.
After compiling this exe, I just call it in the pre-build command line.
I did take ...
6
votes
1answer
1k views
Fixed point combinator in C++1x
This has been tested and compiled under Visual Studio 2010. Are there any serious problems with this implementation?
PS. This implementation is fully lambda expression based. If I can make ...
5
votes
2answers
71 views
Beta Reducer in Haskell
This is my first Haskell application, so any non-name-calling tips will be taken extremely well! It is just a beta reducer:
...
5
votes
1answer
97 views
Combining contents of files by reading them in a human ordering
This code review is inspired by the this StackOverflow question and written in Java 8.
The code is supposed to:
Order all files, with syntax jobXXX.script, where ...
3
votes
2answers
47 views
Elegant way of making a List of an attribute from a list of objects containing that attribute
If this is my class:
class Something
{
UUID id;
// Other members
}
Given a List<Something> things and I want to ...
4
votes
2answers
447 views
Project Euler “Largest product in a grid” (#11) in Java 8
I have come up with a Java 8 solution for the following problem:
In the 20×20 grid below, four numbers along a diagonal line have been marked in red (bold here).
08 02 22 97 38 15 00 40 00 75 ...
2
votes
2answers
217 views
Unwanted return values in lambda functions?
From a previous question, I got the idea of moving boilerplate code structures into a helper function and passing in a lambda function to it.
I then applied the idea to a data access class (code ...