Questions tagged [lambda]

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.

Filter by
Sorted by
Tagged with
3
votes
1answer
54 views

Finding out the indices of common elements in two array lists having duplicate elements

I have two lists which are also having some duplicate elements , i am converting this list to map as key value pair with element index as the value for the key - element List 1 : [1, 2, 3, 4, 5, 6, ...
21
votes
6answers
4k views

Implementing any_of in C++

I've decided to implement Python's any in C++. I've gone about this using templates to allow multiple types of data to be passed, instead of overloading the ...
1
vote
1answer
65 views

Better Filtering on Java Streams

I need to run filtering on nested Lists and return a List of items from back I will put a sample code here with my model ...
1
vote
0answers
82 views

get better performance [closed]

I have this code that works, but I'm sure that it can be done better, any suggestions? ...
2
votes
2answers
70 views

Concise way of creating a IntRange out of an Int

I want to create a collection (in this case a map due to the extended function 'groupBy') that maps an IntRange to a list of a data class, which members are determined whether an int inside the data ...
6
votes
2answers
97 views

Printing the max of groups of three random ints

I'm trying to teach myself streaming and lambda expressions. Here's the scenario: I have a collection of 10 Thing objects each containing an int[] of 3 random number. I've written code to print out ...
6
votes
2answers
79 views

Filtering a list of customers in Java based on three criteria

Let's assume that you need to filter customers based on 3 criteria: name tags assigned to customer customer's location For some reasons you have to do it directly in your program code, without ...
2
votes
2answers
43 views

LINQ queries to generate a report on accrued work time on projects

The following code fetches data from a MySql database to generate a simple report on accrued work time on projects. I've been away from Entity Framework for a while and looking at this code you can ...
1
vote
1answer
78 views

Repeatedly open and close a PDF document to perform various operations [closed]

I am trying to implement the Execute Around pattern described in Kent Beck's Smalltalk Best Practice Patterns. An example in Java could be found here. Basically, I am repeatedly opening and closing ...
1
vote
1answer
66 views

Extract Common Data From List of Objects

I have a list of orders and for some order fields I need get the data that is common among the orders. If the data is not in common, I should indicate null. I collect the common data in a ...
5
votes
2answers
214 views

Using lock with value type (multithread context)

I have to use value type to lock code sections in correspondence to objects identifiers (i.e. Guid, int, ...
0
votes
2answers
74 views

Threads with lambdas and runnable in Java

I'm learning Java and I've started writing some tasks. Could you give me feedback for it? Write a static method andThen that takes as parameters two Runnable ...
1
vote
1answer
158 views

FizzBuzz with Lambda Expressions in Java

I wanted to create a FizzBuzz in Java that is supposed to be open for extension. So the initial problem is the good old, if divisible by 3 print fizz, if divisible by 5 print buzz, if divisible by ...
1
vote
1answer
2k views

On tkinter: scrolling multiple widgets simultaneously in different frames

Below is an example on how to scroll two canvasses in two separate frames simultaneously. The trick is on how to pass on *args from the bindings to function ...
3
votes
3answers
106 views

String comparator as a lambda

I am writing a Comparator for my TreeMap. It looks like this: ...
0
votes
1answer
59 views

Using a wrapper on a primitive as a generic for an interface used for Java lambda

I apologize for that title, lol. I have a Java method that I'm writing where I want to be able to pass in an array of Objects and two interfaces that will be used for lambda expressions that specify ...
2
votes
0answers
743 views

Lambda@Edge function for handling redirects and rewrites

We're converting the City of Philadelphia's website to be served as static files. In order to support redirects and rewrites (URL masking), we decided to use a Lambda@edge function, which modifies (or ...
1
vote
2answers
74 views

Simplifying minimum search of two dimensional vector with complex struct

Is there a way to simplify this function? I tried to use the std::min_element function inside the lambda, but i don't get it to work with ...
3
votes
0answers
787 views

AWS Lambda Function to Register in Cognito

This is the entire code for a Lambda function that registers a new user in Amazon Cognito. The email, username, and password are passed to the Lambda function. The client ID is stored in an ...
4
votes
2answers
99 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 ...
5
votes
1answer
64 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 ...
4
votes
1answer
5k views

Examples of lambda functions, std::for_each / max_element / remove_if etc

I have written a cpp program which demonstrates the use of the following functionalities in modern cpp. Lambda Functions ...
2
votes
2answers
140 views

Returning a collection inside of an IEnumerable method

The following scenario came out of a discussion I was having with a fellow developer on this project. He likes to execute an Ienumerable as soon as possible, hence ...
0
votes
2answers
137 views

Reach C++ policy-based common interface with different template parameters from one container

Please review my solution for the following problem. I am interested in: What do you think of the design Improvement tips Usability Efficiency Problem: Need to be store policy-based objects with ...
3
votes
1answer
48 views

Checking whether an image is part of another

I have the following code (slightly modified for simplicity). It checks whether a given image A (the template) is part of another image B. To handle different sizes, image B is scaled as long as a ...
2
votes
0answers
135 views

Handling IndexError using lambda function within scrapy

I've written a script using python's scrapy library to parse some fields from craigslist. The spider I've created here is way normal than what usually gets considered ideal to be reviewed. However, I'...
2
votes
1answer
148 views

Optimising multiple streams to single loop

I am trying to find the best way to optimise the converters below to first follow the flow I call convertAndGroupForUpdate, which triggers the conversions and ...
2
votes
2answers
1k views

Merging, sorting and limit Map streams using Java 8

I have two maps map1 and map2 . I want to merge both maps and then sort in desc order and get top 5. In case of duplicate keys in merge I need to sum the values. I have the following code that works: ...
3
votes
0answers
49 views

Designing a system to apply multiple effects to one or multiple targets

I posted this on SO first, but was redirected here, since the code below already works: I'm currently trying to develop a small game as a hobby project, which contains an automated combat system ...
3
votes
3answers
208 views

Attempt at the Most dynamic FizzBuzz possible in Java

I was trying to come up with the most dynamic fizzbuzz answer I could.. and well, this is what I came up with: ...
0
votes
1answer
57 views

Data validation for to check required fields are mapped

Can I break the below foreach and IF statements into LINQ expression. Also, performance wise which will be better. Please suggest. ...
1
vote
0answers
43 views

Querying a database to find notifications to comments

I have a solution what I think is not the best, and I want to make this not so expensive. I'm using MVC 5 + SignalR (hubs) + EF + UnitOfWork + Generic Repos. I have a table ...
1
vote
0answers
1k views

Opencv forEach with lambda expression for parallel processing

I'm using forEach function to access pixels in parallel like so: ...
2
votes
0answers
208 views

Comparing speed of common sorting algorithms in an extensible way

I have written a program with the goal of comparing the speed of some common sorting algorithms. It works with many data types. ...
2
votes
0answers
527 views

Flattening a map into a list of records

In my everyday work I'm trying to move away from traditional iterating over collections to a more Java 8 streams-like behavior. I'm currently working on a project where I have a collection defined as: ...
2
votes
1answer
1k views

Better QOpenGLWidget by delaying GL code to initializeGL with lambda functions

When I am writing OpenGL applications with the QOpenGLWidget class, deciding what code goes into the initializeGL function has ...
1
vote
1answer
271 views

Control class for an entity

For a Student object in the package entity, I have a control.studentpackage with classes ...
12
votes
3answers
10k views

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

I wanted a function that would return a certificate, given its serial number, regardless of which store it is in. It has to do almost the same exact thing but twice (once for each store). To keep it ...
0
votes
2answers
147 views

Callback notation in a Mediator [closed]

I'm implementing a Mediator and I'd like to simplify the callback notation a bit. My mediator has Register and Notify methods : ...
1
vote
3answers
3k views

Combine a boolean condition with a Where clause in same query

I'm trying to see if I can somehow reduce the length of this query. I have a common part with the string.Compare(...), is IsProperty == true I would like to take all strings where Value is property, ...
2
votes
3answers
7k views

Fill ArrayList of String with empty String to maintain order of elements

I'm writing a logic for converting data fetched from data base into CSV format. The total number of header fields in CSV file are 14. Now it is possible that not all the field values are available. To ...
2
votes
3answers
254 views
2
votes
1answer
1k views

Generic Comparator Using Class Fields & Lambda Java

I have a grid in which i have to display some/all fields of a Java Class, this grid displays the List of elements of that class type. I have to sort this list provided: Class type of the List item ...
4
votes
1answer
2k views

Select value based on condition on dataframe

I have some data in data frame and would like to return a value based on specific conditions. It is highly time consuming. I tried three methods: Method 1: Without dataframe, this is the simple ...
2
votes
0answers
38 views

DynamicIterable

I have written this DynamicIterable that can be used as a Lazy Iterable, where you give it a Supplier<T> of something and ...
0
votes
1answer
358 views

Simple lambda like define trick

Due to a lack of every standard from C++11 upwards in my IDE I rolled an own litte lambda expression like construct some time ago, which I want to share now. I wouldn't necessarily recommend using ...
3
votes
1answer
9k views

Calculate working days and excluding specific dates (Holidays)

I read some questions/answers related to functions in C# to calculate the working days; some use an extended code to achieve that. I have a data table with more than 50,000 rows and I required an ...
6
votes
2answers
1k views

Fill a vector with uniformly distributed random complex numbers

I want to fill an array of complex numbers using a uniform generator. I thought up the next code. (Complex is a simple fixed-point complex data type.) ...
1
vote
3answers
780 views

HashMap keys to sorted List

The idea is to obtain the keys as a list ordered by the natural ordering of the keys but first of them all the ones that have priority, stated by the method hasPriority(). The custom comparator code ...
6
votes
2answers
978 views

Ordering data by boolean

I have a bit of EF Lambda code which returns a list of data from the db table, then orders by a field called IsDefault At first, the code was ...