Questions tagged [lambda]

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

2
votes
0answers
15 views

Java 8 - throw multiple generic checked exceptions in lambda

In a project I am working at, I have found a class which wraps all methods of its super-class in some elaborate exception handling. It looks similar to that: public void method1() throws ExceptionA { ...
0
votes
1answer
21 views

Python - Can I use a lambda function to generate a repetitive GUI with tkinter? (labels/text/buttons)

I have a very repetitive GUI to implement - think tens of label/text/button fields, for a data entry form. The sizes of each repeated section can be the same - in fact, everything can be the same ...
0
votes
1answer
27 views

Define a Lambda function as Argument Constraint in Spock

There is a piece of code I want to cover with a unit test public List<Product> fetchProducts() { ... String userId = anotherObj.getId() return caller.call(client -> client....
0
votes
1answer
21 views

Storing different actions in Queue (need clarification)

TLDR; Why does this work. Queue<Action> queue = new Queue<Action>(); queue.Enqueue(() => Load("Scene01")); But not this. Queue<Action> queue = new Queue<Action&...
0
votes
2answers
38 views

How to write lambda function with three conditions

I want to write a function that gives returns 3 if x>y returns 1 if x==0 and returns 0 if x def make_points(): return lambda x,y: 3 if x>y else 0 I tried this but I want to add another ...
2
votes
1answer
28 views

Java functional interfaces : how to wrap a function with andThen or similar

I have some repetitve code that goes : router.post("/fleets/:fleetid/vehicles/:boxid/ping").handler(ctx -> pingBox(pingBoxTimer, oemUrl, ctx)); router.post("/fleets/:fleetid/...
0
votes
1answer
78 views

Two lists and statement

Here is my code, I want to get result contains b and c but it gives me error. df = pd.read_excel('C:Test 0926.xlsx') df.drop_duplicates(['mention'],inplace=True) a = df['mention'].str.lower() ...
0
votes
1answer
14 views

Implementing Fibonacci sequence using pure lambda calculus and Church numerals in Racket

I've been struggling with the Lambda Calculus for quite some time now. There are plenty of resources that explain how to reduce nested lambda expressions, but less so that guide me in writing my own ...
2
votes
2answers
63 views

Object returned from lambda loses property value

I am taking a course that is several years old so learning how to use serialization for the first time. When the "return result" executes in the lambda, the Address property of the Contact becomes ...
2
votes
4answers
59 views

Make a Single Capturing Lambda

This is obviously a toy example, but lets say I have a n functions like this: void one(const int param) { const auto func = [=](){ return 13 == param; }; } void two(const int param) { const ...
-1
votes
0answers
8 views

Nodejs - Watermark an Image

I was wondering is it possible to place a watermark on an image in nodejs using an npm library? I looked at dynamic-watermark and image-watermark They work well but it requires to install imagemagick, ...
1
vote
1answer
24 views

Lambda / LINQ to VB.NET

I have a Lambda code that I want to convert to "plain" VB.NET code. I haven't found any tool that would convert Lambda to code, and I don't understand what this code does. What would be a good way ...
2
votes
1answer
38 views

Lambda in return statement gives two outputs but only one if print is not used

def x(n): return lambda a: print(a) print(x(1)(2)) this outputs: 2 None What is this None for? I don't understand the flow here...
1
vote
1answer
35 views

Python: Understanding Lambda Used in Sorted() [duplicate]

I was trying to use the orderedDict module to sort my dictionary but came up with this question while looking at some example code like below: # regular unsorted dictionary d = {'banana': 3, 'apple': ...
0
votes
1answer
39 views

Which one is more effective extra param in lambda or overloading a method?

I have written a lambda and I am not able to make a decision whether to simplify the lambda or to make an extra method in the code. So, here's the scenario - MyIterator public Iterator<DTO> ...
-3
votes
1answer
31 views

Using lambdas to extract an Object attribute contained in an ArrayList [duplicate]

I have made a class called User with two string attributes: Login and Password. I have a database (userList, of type ArrayList<User>) with all the existing users, and I want to know if a login ...
5
votes
4answers
109 views

How to check if an ArrayList of Strings contains substrings of another ArrayList of Strings?

List<String> actualList = Arrays.asList ("mother has chocolate", "father has dog"); List<String> expectedList = Arrays.asList ("mother", "father", "son", "daughter"); Is there a way to ...
0
votes
1answer
45 views

Saving and restoring Kotlin lambda with savedInstanceState

How to save Kotlin lambda in fragment before the screen rotation? It works in Activity but doesn't correct work in the fragment. An exception occurs when executing a lambda expression if it contains ...
4
votes
2answers
61 views

How to use a custom Collector in a groupingBy operation

The Oracle trails on reduction with streams gives an example of how to convert a collection of people into a map containing the average age based on gender. It uses the following Person class and ...
1
vote
1answer
29 views

What's the order for the expression ((lambda (x) (* x 2)) (+ 3 1))?

A ((lambda (x) (* x 2)) (+ 3 1)) ((lambda (x) (* x 2)) 4) (* 4 2) 8 B ((lambda (x) (* x 2)) (+ 3 1)) (* (+ 3 1) 2) (* 4 2) 8 I guess there are 2 versions. But I'm not sure which one is correct.
-2
votes
1answer
71 views

List of String to Map Java8

I have a list of String in my application. Every String is actually an output of 2 different strings concatenated by ".". e.g. Stack.Overflow Now, I am trying to convert this list to a Map with key ...
0
votes
1answer
26 views

Why the wrong output in this Lambda expression? [duplicate]

I can’t explain the wrong output in the following lambda expression. >>> g = lambda x, y: 3*x^2 + 7*y -1 >>> g(4, 4) 17 <-- this is not right. The right answer is 75 : order ...
0
votes
1answer
21 views

Long time processing a lambda function

I have a lambda function witch basically convert 'csv files' into 'json files', the problem is depending on the file the execution can take 5 sec or 400 sec maybe more, do you think it's be a good ...
1
vote
0answers
18 views

Keras Lambda: function cannot return a callable Tensor

Building a special neural network for a complex prediction task. Because of its complexity, I would like to implement a classification task as a pseudo-regression; normal classification does not ...
0
votes
2answers
43 views

How to set flag in one list for the Id's which match with the Id's in another list using Lambda expression c#

I have two lists classes public class class1{ public Int Id { get; set; } public Bool Flag{ get; set; } } public class class2{ public Int Id { get; set; } } Now i have List<class1> and ...
0
votes
1answer
28 views

Can I use lamba experssion to obtain an ejb dynamically through strategy pattern with CDI?

I know I can inject as an instance all the beans that match the interface and then choose between them programmatically : @Inject @Any Instance<PaymentProcessor> paymentProcessorSource; That ...
0
votes
3answers
42 views

Kafka-Streaming: How to collect pairs of messages and write to a new topic

This is a beginner's question to kafka-streaming. How would you collect pairs of messages using the java kafka-streaming library and write them to a new output topic? I was thinking about something ...
0
votes
1answer
66 views

Loop multiple different type of lists and create another using java 8 lambda expressions

I am writing a code to loop through multiple different type of lists and create another based on some business validations using java 8 lambda expressions. Business Validation/Logic: there are 2 ...
0
votes
0answers
21 views

Lambda, python boto3, delete instance older than x days

I'm very new to Python. However I've managed to customize a Python script for Lambda to search for Packer Builder artifacts left behind after running Terraform and Packer. I'm struggling with finding ...
0
votes
2answers
72 views

How to loop through multiple Lists and create another list with merging of unique values from both the lists using Java 8 lambda expressions

I am writing a code to loop through multiple Lists and create another list with merging of unique values from both the lists using Java 8 lambda expressions. Model class: class ServiceMap{ ...
0
votes
1answer
33 views

debugging? or lambda functions and tuples

Create a function get_lambda that returns a lambda function that takes a tuple and raises each element in the tuple to the second power. >>>f = get_lambda() >>>f((1, 2, 3, 4)) >&...
0
votes
1answer
33 views

using CompletionStage instead of CompletableFuture

given the following method: private static String getChuckNorrisJoke () { try { HttpURLConnection con = (HttpURLConnection) new URL( "http://api.icndb.com/jokes/random" )....
0
votes
1answer
33 views

Kotlin lambda function with arguments

I am currently developing an Android application that uses the Retrofit library for REST api usage. For instance, I have the following code from MainActivity.kt : fun userLogin(){ calls....
-3
votes
0answers
30 views

lambda explained python Dataframe

I have a Dataframe, and I want to know the most efficient way to get two specific columns that have the string names of 'FEN-Position' and 'Result'. I am confused about how to do boolean expressions ...
0
votes
2answers
57 views

collecting the sum of a field in java stream

consider the following class: public class PersonalExpense { private String name; private int currentExpenses; ... how to can i write a java stream "pipeline" that works in the same way ...
5
votes
0answers
74 views

Why is compiling a code affecting lambda to std::function so slow, in particular with Clang?

I discovered that compile time of a relatively small amount of code, converting lambda functions to std::function<> values, can be very high, in particular with Clang compiler. Consider the ...
0
votes
0answers
15 views

Regularization Parameter

Did anybody try Tikhonov Regularization before? I used scipy and https://scicomp.stackexchange.com/questions/10671/tikhonov-regularization-in-the-non-negative-least-square-nnls-pythonscipy helped ...
0
votes
2answers
36 views

how to make a new column based on comparing two dataframes' unique id?

Hi, I have two dataframes which have OrderID and stage numbers. I want to create a new column for August Dataframe which returns values in July's stage number if the orderID matches. If not, please ...
-1
votes
0answers
23 views

Java 8 : method references and lambdas [duplicate]

I have a question abour method references, in the special case when there's already a fixed parameter. Let's take this example : Predicate<String> pred1 = s -> s.startsWith("a"); How can I ...
0
votes
1answer
57 views

How to get 'named' tuple components inside Linq queries?

Suppose I have a of tuples, say List<(string, Table)> and I want to iterate over it using a Parallel.ForEach, using the 'named version' of the tuples' components. The following code does that: ...
3
votes
3answers
79 views

Why doesn't for-each method in java not throw an exception when a Function type argument is passed instead of Consumer? [duplicate]

Why doesn't forEach method in java not show a compiler error when a Function type argument is passed instead of Consumer? Here both of the lines are returning a boolean value for every element in the ...
-1
votes
0answers
25 views

Using Lambda function to calculate probablilty weighted moments [on hold]

Hello I would like to learn how to use the lambda function to calculate probability weighted moments such as the following: 𝑏_1=∑(𝑛−𝑖)𝑋𝑖/𝑛(𝑛−1); where summing begins at i=1 to n-i I apologize ...
2
votes
1answer
66 views

How to create/Initialize ArrayList of ArrayList using java Lambda

How to convert the following code to lambda in java8??? List<List<String>> my2dList = new ArrayList<List<String>>(); int counter = 0; for (int i = 0; i < 5; i++)...
0
votes
0answers
22 views

the memory address of lambda expression about python

why the output is different Case 1: The address of each anonymous function object in the list resolution is the same t = [id(lambda t: t * i) if i % 2 == 0 else id(lambda x: x ** i + 1) for i in ...
6
votes
1answer
87 views

Java 8 adding values of multiple property of an Object List

Lets say I have a class below with getters and setters but with only default constructor. Note: I'm not allowed to change the structure of this class. class Target { private String year; ...
2
votes
1answer
38 views

lambda retrieve integer from map

I am trying to get the number after doing calculations using Lambda expression, but getting the error. The lambda expression I am using: int num = Optional.ofNullable(list.stream().filter(x->x....
2
votes
3answers
94 views

Callback using lambda with closures

I'm trying to implement a callback which passes control from an Interrupt Service Routine to a member function on a c++ class. I thought lambdas and closures would be a convenient means of doing this, ...
0
votes
1answer
22 views

Select a List from another List Using Lambda Expression

Here are my classes. public class Product{ public decimal Price {get;set;} public string ProductName {get;set;} } public class Products{ public int Count{get;set;} public List<...
-3
votes
1answer
63 views

what's difference between two syntax in using Consumer object? [on hold]

i read following code from this tutorial and run it in eclipse and every thing was fine. import java.util.Arrays; import java.util.List; import java.util.function.Consumer; /* w w w .j a va2s . c ...
1
vote
1answer
16 views

Explicitly Specifying Lambda Parameter Types

I have a little problem with Lambda Expressions. I don't understand this example from C# In a Nutshell book. How can I use fun argument? Can you explain me that or give some other examples? I will be ...