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
1
vote
3 answers

How can I use functional programming to do string manipulation?

I'm writing a function where I'm essentially doing the same thing over and over. I have the function listed below public String buildGarmentsString(List garments) { StringBuilder garmentString = new StringBuilder(10000); for(int…
1
vote
2 answers

combine two lists in Java

I have two lists with the same number of arguments, and I'd like an elegant way of combining them (not concatenate). Here is my current (not so good) way of doing it (just so you know what I am trying to do). List list1 = ... // init…
One Two Three
  • 22,327
  • 24
  • 73
  • 114
0
votes
1 answer

Seeking in-depth understanding of Function

Shown below is some sample code that uses Java Streams. My question specifically pertains to Interface Function which accepts an input of type T and returns something of type R. import static java.util.Arrays.asList; import static…
Sandeep
  • 1,245
  • 1
  • 13
  • 33
0
votes
1 answer

Why this Consumer complaining compile time error?

I am new to java8 and I am trying to write template method design pattern ,and I am using Consumer for this purpose but I donn't know where I am doing wrong. package org.java.series.ds.cleancode; import java.io.File; import…
krish
  • 1
  • 1
0
votes
1 answer

Java Static Method, Wildcard / Generic Return Type

I'm building an API, which uses abstract classes, to invoke static methods. Some Java Pseudocode: public abstract class APIBaseClass { public static List myMethod(Class clazz, MyConverter converter, List objects) { return…
Ryan Robison
  • 3
  • 1
  • 2
0
votes
3 answers

Functionally rewriting assignment from an Optional without executing "else" logic

I have the following in my code: Optional optionalFoo = fooDAO.findByName(name); Foo foo; if(!optionalFoo.isPresent()) { foo = fooDAO.addFoo(name); } else { foo = optionalFoo.get(); } IntelliJ popped up a hint that said can be replaced…
Mike S
  • 1,451
  • 1
  • 16
  • 34
0
votes
1 answer

Different Optional/Option semantics in Java

I am trying to understand reasons behind different Option/Optional semantics in probably 3 most used implementations in Java ecosystem: Java 8, Functional Java and Guava. Considering following three snippets. java.util.Optional.of(100).map(i ->…
hgrey
  • 3,033
  • 17
  • 21
0
votes
1 answer

Functional Java: importing from Maven

I have cloned a maven project on a new machine but I am having some problems with some of the dependencies as they don't seem to have been loaded. One such case, is fj.Effect of Functional java. I am not sure if I am (manually) adding the right…
Maths noob
  • 1,684
  • 20
  • 42
0
votes
1 answer

how would you transform this functional java code to scala above SparkContext?

Ok so I have points which is a List The following piece of code is written using java 8 functional API. It takes the points, calculates for each point its matching cluster , and then groups them point by the ClusterKey. Eventually we end…
kumetix
  • 1,032
  • 1
  • 12
  • 18
0
votes
1 answer

Functionaljava: sorting a list of arbitrary types

I have a very simple Java bean, WatchedFile, which has a fileName field. I would like to sort a fj.data.List of WatchedFile objects, but I'm struggling with defining an fj.Ord for the list's sort() method. This is what I came up with: protected…
egbokul
  • 3,944
  • 7
  • 36
  • 54
0
votes
1 answer

Functionaljava compilation errors

From here: http://functionaljava.googlecode.com/svn/artifacts/3.0/demo/bgga/Option_filter.java Q: Ho would I compile this example? If no way: What the purpose to put now working examples? import fj.data.Option; import static…
ses
  • 13,174
  • 31
  • 123
  • 226
0
votes
2 answers

Scope management - Stateful IO Monad?

I am playing with functional programming and in particular with Functional Java. I have implemented with success my version of the IO Monad and I am writing IO actions for my core. It is basically serializing objects to Xml files (the object type…
Andrea Richiardi
  • 703
  • 6
  • 21
0
votes
2 answers

Functional Java: how do I construct an empty list?

I wish to construct the empty list of type List. The best I can come up with that satisfies the type-checker is: (List) (Object) List.nil() which is terribly ugly. Is there something better?
jameshfisher
  • 34,029
  • 31
  • 121
  • 167
0
votes
2 answers

How to construct a FunctionalJava TreeMap?

I'm just starting to use the FunctionalJava library and wanted to make use of the immutable TreeMap. However I can't figure out how to create an empty one to start with when using a user defined class or interface. fj.data.TreeMap
0
votes
1 answer

Fold on Option, instead of `if maybeT.isNone()`

This is a similar question to Why doesn't Option have a fold method?, but for functional-java. I want to perform some side-effect if an option is None. Is there something I can use other than if maybeT.isNone()? I'm thinking along the lines of…
Synesso
  • 37,610
  • 35
  • 136
  • 207