Questions tagged [lambda]

Anonymous functions or closures in programming languages such as Lisp, C#, C++, Lua, Python, Ruby, JavaScript, or Java. (Also, lambda expression.)

0
votes
2answers
32 views

Compare two maps for keys and return boolean

I have two maps and I need to check if both has the same keys and same number of keys or not and return a boolean. I would like to use streams for this and I have got is by creating another list mapA ...
2
votes
2answers
34 views

Create a List compose by matching fields between a List of Maps and an List of Objects using Lambda Functions?

I'm new to Java lambda expressions and have been struggling with the following problem: I have a List of label objects, whose fieldsid are the only keys I wanna extract from the other List of Maps. [...
0
votes
0answers
18 views

RocksDB exception in Kafka Streams

In a simple Kafka Stream program when I am using the below code, it works without throwing any error: KTable<String, Long> result= source.mapValues(textLine ->textLine....
1
vote
2answers
70 views

How to find total count of Words, total count of Vowels, total count of Special Character in a text file using java 8

I have a text file and i want to check - total words count in file - total vowels count in file - total special character in file By using Java 8 Streams. i want output as a Map in a single ...
2
votes
2answers
56 views

Function Template Instantiated With Runtime Constant

I need some way to combine lambda's ability capture a runtime value and function template's ability to specify any type we want. What is the best way to do it? Lambda allows us to capture the value ...
-1
votes
1answer
52 views

What does it mean to surround a method reference with brackets?

I'm using Java 8. I know it's new features like lambda, method references, etc. But I'm confused about this code: static class SRoad implements Comparable<SRoad> { int id; public SRoad(...
-3
votes
1answer
68 views

Java 8 : How to have a condition check in-between multiple comparisons

I need to sort a collection with multiple conditions. But, in between these conditions I need to modify the stream data. Customer.class import java.math.BigDecimal; import java.util.Date; public ...
0
votes
1answer
28 views

Dataframe apply(map) function TypeError

Can someone please point out the error of my ways with this piece of code: groupIds = allData.drop_duplicates('GroupID').set_index('Ticket')['GroupID'] allData.loc[(allData['SexGroup']!='Man') & ...
0
votes
1answer
28 views

How to only window the input in Kafka Streams using Java lamda?

I have input data that I am fetching using Kafka Stream. What I need to implement is just a tumbling window of 5 seconds and output the data to a Kafka topic. However, I am not able to accomplish this ...
0
votes
0answers
21 views

How does Padlevski code compile with no error [duplicate]

The code associated to Padlevski compiles with no error. int main() { <:]()<%[](){[:>()<%}();}();}(); } In the c++ conference, he said that it is a lambda in lambda. I can only see one ...
0
votes
1answer
37 views

Lambda or LINQ for result

I have got a Feedback table from the user and feedback class contains Steps... Steps can be Achieved(A), Didn't Achieved(DA) or Achieved with Prompt(AWP) Name Step1 Step2 Step3 ...
0
votes
1answer
34 views

How to call a lambda function with a message (M1) before another message (M2), but the output to be “M2 M1”?

My homework is to implement a function called finally, which takes a procedure with 0 arguments and executes it at the end of the current scope. I should demonstrate its usage by using a lambda ...
1
vote
2answers
76 views

How do I improve my vector search function?

So I was implementing a TCP-server in c++ and was storing all the users in a vector. Now I need a more generalized function to search for multiple different properties, How do I improve this code? ...
1
vote
4answers
43 views

Is it possible to use lambda in a for loop for this?

I want to follow task with lambda function but not sure it's possible. Let's say I have following list: list = [3,2,33,45,566,21] The longest length of the list is 566 so len(566) = 3. Then I ...
1
vote
1answer
35 views

Can't get result of desired query in linq

I need to get data of two or three years like from 'Jan, 2017 to March, 2019' or so. In my query I've separated properties for Year & Month which are compared with SYear(from Year - 2017), Tyear(...
7
votes
3answers
108 views

List filter in Java8 using isPresent method

I have one list which contains some String values. I want to iterate the list comparing with another String. Only if another String doesn't match with any element in the list, then I should enter the ...
0
votes
0answers
35 views

Buggy code in A tour for C++ about initializing a vector with switch in lambda expression

I am reading A Tour of C++ second edition. At the end of Chapter 6.3.3 it gives an example to initialize a vector by a lambda with switch statement in it. The code doesn't seem to compile. The code ...
3
votes
2answers
61 views

Is this code threadsafe, using Java 8 Lambdas - stream.forEach

Assume that I have a list of book elements: List<Book> libraryBooks and the following code: List<BookAuthor> authors = new ArrayList<>(); libraryBooks.stream().forEach(e -> { ...
-1
votes
2answers
44 views

How can I optimize the code reducing the similar repetitive parameters

I want to optimize this code instead of using td(String.valueof(dataset.get())) mutliple times. I am relatively new to lambda expressions usage and not able to figure out a better way than this Code ...
2
votes
1answer
45 views

Group a List of HashMaps to a list of HashMaps based on a key java streams

Have to group a List of HashMaps to a list of HashMaps that have same timestamps based on a key. Map<String, Object> m0 = new HashMap<>(); m0.put("x", "aaa#0322"); m0....
0
votes
1answer
37 views

Expression Tree Group and Select using Column with any Type

I'm using a variation of the code from the excellent thread below to dynamically build a treeview structure from any given data source using a custom list of columns. Expression.Call GroupBy then ...
4
votes
3answers
98 views

Java 8 separate list elements by class

given I have a list of items that all inherit from the same base class: class Item { protected String name; public Item(String name) { this.name = name; } getName() { ...
-1
votes
2answers
24 views

How are lambda functions useful? [duplicate]

Currently I am learning lambda functions in Python 3. Till now all I know about lambda functions is that its an anonymous function which can take any number of arguments but can contain only one ...
-1
votes
0answers
54 views

Cannot compile method reference in JDK 11

I am currently migrating a project to JDK 11 and compiling it with Maven. However, Maven throws a wobbly over a single method reference (it doesn't have issues elsewhere). The method in question looks ...
0
votes
0answers
24 views

PHP: Is there short syntax for closures like lambda expressions in Java/Python? [on hold]

Is there a short syntax for anonymous functions / closures like lambda expressions in Java/Python in PHP yet? Looking for a handy syntax to make use of functions like array_map, array_filter in PHP.
2
votes
1answer
75 views

Anonymous function converted to a void returning delegate cannot return a value

I have a general question: in the C# code below thread tFour can not be created and the compiler shows me the following error: "Anonymous function converted to a void returning delegate cannot return ...
0
votes
1answer
57 views

Linq expression filter in IQueryable

I want to create generic expression filtering in IQueryable public class Vehicle { public int Id { get; set; } public string VehicleNO { get; set; } public int DriverId { ...
-2
votes
0answers
27 views

When using Comparator comparing method by lambda expression, then invoke reversed method, why jvm can not infer the concrete type? [duplicate]

For example, List<Book> list = Arrays.asList(new Book(5L), new Book(3L), new Book(4L)); // No1 It is work list.sort(Comparator.comparing((Book book) -> book.getNum()).reversed()); // No2 It ...
0
votes
0answers
18 views

Decrypt a JWE using list of keys that are stored in DB using JAVA 8 Lambda

I Have a JWE which is to be decrypted using list of keys stored in DB. I have to try each key until I find the one that actually decrypts. I am trying to do it in JAVA 8 way, writing Lambdas But I am ...
1
vote
1answer
42 views

How do I call a netlify lambda function from my React app?

I am new to netlify and the serverless architecture. In react I would normally import an action into my component then call that action which would make a call to the server. Right now I am just ...
0
votes
0answers
23 views

Passing both a lambda and its parameters into a function [duplicate]

I would like to write a function that accepts both a function and its parameters, like the following contrived example: template <typename R, typename... Ts> R call(std::function<R(Ts...)>...
1
vote
2answers
62 views

Java 8 expression fill list from list with another list inside

I'm trying to reach a lambda expression avoiding doing this: for (OrderEntity o: onEntryL) { for(GeoFenceEventEntity g: o.getGeoFenceEvent()){ if(null != g.getEndAt() && g....
0
votes
0answers
20 views

Why implement cucumber stepdef with lambda expression is a good practice?

As we know, with the new Cucumber-Java8 API, we can write our step definitions with lambda expressions. Example code from github-cucumber: package foo; import cucumber.api.java8.En; public class ...
0
votes
0answers
9 views

code coverage does not seem to work for assertion employing @FunctionalInterface

In this function: private void assertAssurancesMissing(Vote vote) { assertThrows( () -> voteManager.showVote(vote.id, "user") ).assertMessageIs("missing assurances"); } ...
0
votes
0answers
15 views

How to send data and code in JAVA to execute on a Hadoop ecosystem

I'm pretty new to Hadoop and I am finding it quite difficult to get a grasp on everything. I have kind of like a conceptual map of the structure (MapReduce, HDFS...) but have not found any videos, ...
0
votes
0answers
32 views

running nodejs and mysql, how can I parse the result in client

var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "yourusername", password: "yourpassword", database: "mydb" }); con.connect(function(err) { if (err)...
4
votes
5answers
53 views

Can I remove double evaluation whilst keeping lambda expression

def bar(x): # some expensive calculation <snip> foo = lambda(x): bar(x) if bar(x) > 10 else 0 However here I have calculated foo twice. Is there a way to still write this as a one ...
0
votes
2answers
49 views

Passing a Func<int, int> to Task.Run() in C# without using lambda expressions

I try to get my head around the Task/Func/Action/await functionality of C# but still need your help: I have a button click event handler in my gui thread that, when called, does the following: Func&...
0
votes
1answer
19 views

WebApi Lambda with DataModel and Entitiy

I have a WebAPI I am creating that returns all values when called by /api/mediareleases but I want to add a QueryString so that I can pull more specific data. Data model public partial class ...
-1
votes
2answers
44 views

group by linq with combine columns

I have Object with the data like this below I am looking for results like this For this i am trying with the linq query below var results = (from l in res group new { ...
0
votes
1answer
19 views

Python pandas adding precision using lambda

I am trying to find the precision of a data field using the following code fieldStructure.loc[fieldName,'Precision'] = df[fieldName].apply(lambda x: len(str.split(str(x), ".")[1])).max() however it ...
0
votes
2answers
83 views

Replacing a function with a lambda in C++

I have a function that just sets a value of 1 to a struct member variable length. In modern C++ this doesn't seem like good code style. Could this be done with a lambda? void setEdgeLengths(Koala::...
0
votes
1answer
34 views

Python lambda function missing lambda keyword but still works

I am using python library tinydb to store data. According to tinydb documentation, the proper syntax for an example query is: User = Query() db.search(User.birthday.year == 1990) Why don't we need: ...
1
vote
2answers
54 views

How to cast an object to a given generic type so I can pass this object to method

I have a class "Event" with one generic argument - T. It's the type of Event and is always an interface. Events listener must implement event types that it wants to "listen". For example: public ...
0
votes
1answer
50 views

Python call function within class using lambda expression

I have a class inside a .py file that contains two functions. new_column generates a new column based on values of existing columns (Col1 and Col2). transform_df applies the previous function to a ...
0
votes
0answers
58 views

Functional Interface not serializable when captured from Mockito Argument captor

I have some logic for validation as follows public interface IValidation { void validate(); } public class ParameterValidator { public void validate(IValidation... validations) { for (...
0
votes
1answer
23 views

Terraform cloudwatch retention logic

I'm trying to add logic to my terraform script so that when a lambda is created a CW retention logic is added, so our logs clear after 30 days. What I'm seeing is that when terraform is run to update ...
0
votes
1answer
11 views

Calling an anonymous/lambda function as a result to the get() method of a property

Assuming we have a class "Test" that has a property "testProperty" that implements a get() method, we can easily assign the get() method the result of a helper method: class Test { val ...
1
vote
0answers
31 views

Error deploying c# .net core aws lambda function

I am trying to deploy a lambda function using .NET Core CLI and am not able to deploy the function. I'm not really sure why. I have been following this article to deploy the function and while running ...
-2
votes
2answers
83 views

How to determine if an int is perfect square?

My code seems to pass many cases, but my codes seem to fail a particular private test case. Can anyone help me ? static boolean isSquare(int n) { IntStream y=IntStream.range(1, n).map(((int x)-&...

http://mssss.yulina-kosm.ru