Skip to main content

All Questions

-1 votes
2 answers
89 views

lambda function uses member variable and produces different results

I dont know why the code runs without errors. From what I learned, in functional programming, same input results in same output and function's internal state cannot be changed from outside. When I ...
Deenadayalan's user avatar
0 votes
1 answer
164 views

Java: How to throw an exception in optional ifPresent using method reference or use a runnable in ifPresent

I would like to simulate an optional .ifPresentThrow() to use somenthing like: .ifPresent(MyException::go) and not use: .ifPresent(e -> { throw new MyException(); }) so I created my class with ...
hr13's user avatar
  • 21
1 vote
1 answer
1k views

Java Functional Interface chaining around conditions

Have been recently trying to toy around with functional interface chaining and I am trying to understand if the following is possible. If I have an FI like this: @FunctionalInterface public interface ...
Justin's user avatar
  • 4,539
-1 votes
1 answer
137 views

Code sorting functions as Functional Interfaces to pass them to testing method

I have sorting functions like bubbleSort(args) and mergeSort(args). How would I go about making them passable to other method that would test execution times etc. I was thinking about making ...
new User's user avatar
1 vote
1 answer
110 views

Functional Programming exercise (Lambda function)

Happy new year everyone! I have the following exercise for my Programming courses: Write a class named Imbauba. Class must contain the following method: A public method named dit which has a ...
spinos's user avatar
  • 31
4 votes
2 answers
105 views

How to invoke different methods from parameters in Java?

Assume that I have a method A and B from a class: List<String> A(int start, int size); List<String> B(int start, int size); Now, I have another function that might use A or B. But before ...
injoy's user avatar
  • 4,403
0 votes
4 answers
353 views

Functional way to Wrap multiple methods into one

I am fairly new to the World of Function style Programming I was trying some code in Kotlin, given snippet below is what I did, but Looks so much Imperative to me @EmailTemplate("onCallTemplate") fun ...
user5685250's user avatar
2 votes
2 answers
84 views

Using lambdas as methods of a class in Java

As the title says, I am looking to implement some very short methods of a class using lambdas, nothing unheard of. Python can do it, C# can do it, and to some extent i believe even C++ can do it now....
Rares Dima's user avatar
  • 1,767
22 votes
9 answers
38k views

Java 8 Functions - compose and andThen

I find my Java knowledge out-of-date with Java 8, and there are many new language features I am trying to learn. One of them is Functions, specifically the compose and andThen methods. I have written ...
NickJ's user avatar
  • 9,579
-2 votes
1 answer
349 views

Java passing function as parameter

This is my first approach to lambda expressions, function as parameter or in general functional programming... How I can call B function in this code? public class Fp_example<T> { public ...
Marco Castano's user avatar
1 vote
1 answer
69 views

Clarification on functions - is it a property, special code, another word for procedure/routine or have more than one definition?

I'm a beginner/intermediate programmer going from Java to C# and has been doing a little reading on functions on codeproject.com. My understanding is that namespace in C# is equivalent to packages in ...
Ellyl's user avatar
  • 61
6 votes
3 answers
4k views

What is the Java equivalent to Python's reduce function?

Similar questions have been asked, here and here, but given the advent of Java 8, and the generally outdated nature of these questions I'm wondering if now there'd be something at least kindred to it? ...
Legato's user avatar
  • 610