Questions tagged [functional-java]

Functional Java is is an open source library to learn and implement functional programming concepts in Java.

From the functional Java website: Functional Java is an open source library that seeks to improve the experience of using the Java programming language in a production environment.

The library implements several advanced programming concepts that assist in achieving composition-oriented development. Functional Java is written using vanilla Java 1.5 syntax and requires no external supporting libraries. The JAR file will work with your Java 1.5 project without any additional effort. Functional Java also serves as a platform for learning functional programming concepts by introducing these concepts using a familiar language.

Functional Java's code is now hosted on github

48 questions
2
votes
0 answers

How do Java 8 lambdas differ from anonymous classes as objects (under the hood)?

EDIT: how is this question different from Java8 Lambdas vs Anonymous classes: The answers provided in the previous question are regarding of how they work in a higher level. I already understand the syntax benefits. My question here is regarding the…
Jorch914
  • 3,465
  • 2
  • 16
  • 21
2
votes
1 answer

Infinite stream from enumeration

In functional-java, I expected the following to create an infinite stream: Stream.forever(Enumerator.booleanEnumerator, false); But it stops after one full enumeration. The javadoc kind of confirms this, stating that it may only stream until the…
Synesso
  • 37,610
  • 35
  • 136
  • 207
2
votes
2 answers

Does the JVM JIT optimises the creation of new objects that are almost equal?

I was reading the source code of the Functional Java library and noticed this: public static Option none() { return new None(); } I was wondering why they don't always return a singleton parameter, specially because of None's equality…
Luciano
  • 8,552
  • 5
  • 32
  • 56
2
votes
2 answers

Name for pattern in which actions happen upon completion of a future event / Java class

I have a class currently called Promise that works as follows: It holds a future value It can always accept a subsequent action to take that uses the future value as the parameter When the value is completed the function queue launches Any…
1
vote
1 answer

functional java - transform by calling a member function

I'm coming at some functional java from a ruby point of view in ruby you can do something like this mapped_array = [1,2,3].map(&:to_s) which evaluates out to transforming (map) the array by calling the to_s member function on each…
Jamie Cook
  • 4,375
  • 3
  • 42
  • 53
1
vote
3 answers

How can I make use of the Lambda expression returned by spinServerUp() method in following code

I'm learning Java at the moment and I see some code that looks like this: public interface Await { boolean await(long timeout, TimeUnit timeUnit) throws InterruptedException; } public Await spinServerUp() { this.startServers() return…
GRVY
  • 55
  • 6
1
vote
1 answer

How to Implement Functional If-Then-Else in Java

Given the following Function implementations... Get User Credentials From Master Database private Function> getUserCredentialsFromMaster() { return userId -> Optional.ofNullable(userId) …
j3d
  • 9,492
  • 22
  • 88
  • 172
1
vote
1 answer

How can I add retry and custom recovery method in a circuit breaker - functional java

I'm trying to add a resilience 4j circuit breaker to my project. For that, I have a custom mechanism if the call fails and a retry. How can I change the execution sequence of these two? Is there a way where I can execute my custom mechanism first…
1
vote
3 answers

Use the Stream API to create List from HashMap with elements arranged in specific order

I have a HashMap> where the field name::String from the object Appliance is used as a key, and each value in the HashMap is a list of Appliance objects. Each list, is sorted in ascending order, based on the field…
user13123978
1
vote
3 answers

Functional Java bind arity-2 Function (F2) to options

I understand the basic bind syntax for Option with functional java as Option.some(2).bind(new F>(){ public Optionf(Integer i){ return Option.some(i/2); } }; That works well for single input…
joekarl
  • 2,118
  • 14
  • 23
1
vote
2 answers

How to "shrink" a Java 8 stream from many entries to fewer

How can I "shrink" a Java 8 stream containing a lot of items to a stream containing fewer? I am not asking about mapping, where there's 1 "output" item for each input item, or reduction where a stream is reduced to a single value, but shrinking a…
David Kerr
  • 1,376
  • 2
  • 15
  • 20
1
vote
3 answers

How we I achieve add(4)(10)(20)(3)(1).total using Java Function?

I am learning usage of, java.util.function.Function I wrote a code which uses java Function to add 4 to itself, the code is as follows, public class Test01 { public static void main(String[] args) { Function
Rahul Shivsharan
  • 2,481
  • 7
  • 40
  • 59
1
vote
1 answer

Lambda Expression works with no effectively final variable

I've read that the external variables which a lambda expression uses must be final or effectively final. If I try to modify an external String value in the body of a Supplier, for instance, the compiler blocks me, as by the definition above. But if…
1
vote
2 answers

fj.data.Set comparison

In java.util, we can use the containsAll method to compare two java.util.Set. What's the best way to compare two fj.data.Set? Is there really any "valuable" benefit of using fj over java.util?
Sarah A
  • 1,185
  • 12
  • 27