71
votes
18answers
4k views

What is the point of the class Option[T]?

I am a beginner to functional programming and I have recently started studying Scala and I really love this language for the all goodies it provides like closures, pattern matching, currying, etc. ...
62
votes
9answers
4k views

Functional programming - is immutability expensive? [closed]

Request: The question is in two parts. The first is conceptual, comparing functional and imperative programming from the perspective of cost of immutability. Second, about specifics of Java/scala. ...
53
votes
13answers
27k views

Functional Programming in Java [closed]

Is there a good library for functional programming in Java? I'm looking for stuff like Predicate and List.Find() (as a static method). Not complicated to implement, but it would be nice to find a ...
35
votes
10answers
33k views

Stack overflows from deep recursion in Java?

After some experience with functional languages, I'm starting to use recursion more in Java - But the language seems to have a relatively shallow call stack of about 1000. Is there a way to make the ...
32
votes
5answers
9k views

Are there any good Clojure benchmarks?

Edit: The Clojure benchmarks are up on the Benchmarks Game. I have made this question community wiki and invite others to keep it updated. Is anyone aware of benchmarks of Clojure's performance? ...
31
votes
8answers
4k views

Does java support Currying?

I was wondering if there is any way to pull that in Java. I think it is not possible without native support for closures.
31
votes
10answers
3k views

Are there any provable real-world languages? (scala?)

I was taught about formal systems at university, but I was disappointed how they didn't seem to be used in the real word. I like the idea of being able to know that some code (object, function, ...
30
votes
14answers
14k views

How do I identify immutable objects in Java

In my code, I am creating a collection of objects which will be accessed by various threads in a fashion that is only safe if the objects are immutable. When an attempt is made to insert a new object ...
28
votes
4answers
3k views

How can I transition from Java to Clojure?

After discovering Clojure I have spent the last few days immersed in it. What project types lend themselves to Java over Clojure, vice versa, and in combination? What are examples of programs ...
25
votes
1answer
990 views

Which GoF Design pattern will be changed or influenced by the introduction of lambdas in Java8?

Many claims that the biggest part of the GoF design patterns are just workarounds for the absence of first class functions. Now that Java is about to get lambda expressions, which of those patterns ...
20
votes
4answers
1k views

Why ADTs are good and Inheritance is bad?

I am a long time OO programmer and a functional programming newbie. From my little exposure algebraic data types only look like a special case of inheritance to me where you only have one level ...
19
votes
9answers
9k views

How to implement a list fold in Java

I have a List and want to reduce it to a single value (functional programming term "fold", Ruby term inject), like Arrays.asList("a", "b", "c") ... fold ... "a,b,c" As I am infected with ...
17
votes
5answers
4k views

Dynamic programming in the functional paradigm

I'm looking at Problem thirty one on Project Euler, which asks, how many different ways are there of making £2 using any number of coins of 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p). There ...
15
votes
2answers
10k views

GUI programming in Scala

I'm trying to learn Scala, and I'd like to learn by writing a simple swing app, but I'm unsure what GUI programing looks like in a functional world, and specifically when using Scala. Any pointers, ...
14
votes
7answers
8k views

Does guava have an equivalent to Python's reduce function?

Does guava (or another java library) have something like reduce() function in Python? I'm looking for something like this http://docs.python.org/library/functions.html#reduce
13
votes
7answers
14k views

Filtering a list of JavaBeans with Google Guava

In a Java program, I have a list of beans that I want to filter based on a specific property. For example, say I have a list of Person, a JavaBean, where Person has many properties, among them ...
13
votes
4answers
2k views

What is the Guava equivalent of Scala's flatMap?

Looking through http://code.google.com/p/guava-libraries/wiki/FunctionalExplained I see operations like transform, which will transform a list but keep the same cardinality. How can I perform a ...
13
votes
8answers
2k views

what's a good persistent collections framework for use in java?

By persistent collections I mean collections like those in clojure. For example, I have a list with the elements (a,b,c). With a normal list, if I add d, my original list will have (a,b,c,d) as its ...
13
votes
1answer
769 views

Five Digit Primes in a 5x5 Grid

|---|---|---|---|---| | 1 | 1 | 3 | 5 | 1 | |---|---|---|---|---| | 3 | 3 | 2 | 0 | 3 | |---|---|---|---|---| | 3 | 0 | 3 | 2 | 3 | |---|---|---|---|---| | 1 | 4 | 0 | 3 | 3 | |---|---|---|---|---| | ...
11
votes
5answers
834 views

Functional/Immutable Data Structures for the JVM?

Does anyone know of a Java/JVM data structure library providing functional (a.k.a. immutable, or "persistent" in the functional sense) equivalents of the familiar Java data structures? By ...
11
votes
6answers
1k views

Functional programming applied

I have been interested in programming all my life and for the past 6 years I have worked almost exclusively with Java. I just finished with my University studies and have a job as a Java developer for ...
11
votes
4answers
554 views

Why doesn't Java 8's Predicate<T> extend Function<T, Boolean>

If I wrote the Predicate interface, i'd want to encode in the interface the fact that it's just a function that returns a primitive boolean, like this: @FunctionalInterface public interface ...
11
votes
5answers
23k views

JUnit 4: Set up things in a test suite before tests are run (like a test's @BeforeClass method, just for a test suite)

I want to do some functional testing on a (restful) webservice. The testsuite contains a bunch of test cases, each of which performs a couple of HTTP requests on the webservice. Naturally, the ...
11
votes
3answers
912 views

java: libraries for immutable functional-style data structures

This is very similar to another question (Functional Data Structures in Java) but the answers there are not particularly useful. I need to use immutable versions of the standard Java collections ...
10
votes
3answers
2k views

Is there a good comparison between Functional Java and Guava?

I'd like to use either Functional Java or Guava (or less likely Scala) in a course I'll be teaching. Although there are lots of functional languages that run on the JVM I'd like to stick to something ...
10
votes
9answers
2k views

Functional Data Structures in Java

Does the Java standard library have any functional data structures, like immutable Sets, Lists, etc., with functional update?
10
votes
5answers
357 views

functional programming in Java

how can you emulate functional programming in java, specifically, doing things like map a function to a collection of items? map(func, new String[]{"a","b","c"}); what's the least verbose & ...
9
votes
3answers
664 views

Any example in which Clojure really shines against Java which is not concurrency/immutability-feature related?

I can perfectly see why Clojure is really good for concurrent programming. I can see the advantages of FP also in this regard. But clearly, not every line of code that we write is part of a thread or ...
9
votes
5answers
538 views

Removing code duplication

I am trying to create a little functional programming library for Java (just to scratch my own itch). While defining the higher-order functions for Lists, Sets and Maps I have come across this ...
9
votes
5answers
683 views

Composing functions in Java?

I'm writing demo code for an API we've created and I keep running into the same problem where I'm repeating myself, over and over ad nauseum. I am painfully aware that Java is scheduled to have ...
9
votes
1answer
596 views

What are your experiences using the functional java project?

I was reading the following question - How safe would it be to use functional-java to add closures to a Java production project? and I had been thinking of using the Functional Java project as well in ...
8
votes
6answers
2k views

Explain Type Classes in Haskell

I am a C++ / Java programmer and the main paradigm I happen to use in everyday programming is OOP. In some thread I read a comment that Type classes are more intuitive in nature than OOP. Can someone ...
8
votes
4answers
775 views

Is there any reason to prefer functional programming for data mining projects?

I am researching the possibility of starting a data mining project which will include intensive calculations and transformation on data, and should be relatively easy to scale. In your experience, is ...
8
votes
1answer
155 views

A java List that implements the new Stream interface?

I just took some time to start looking into the java-8 buzz about streams and lambdas. And have a couple of questions... The first thing that surprised me is that you cannot apply the Stream ...
8
votes
6answers
666 views

immutable java

immutability, any good sources on writing immutable programs in a functional way with java? shifting over to erlang - scala - clojure is not a possibility.
8
votes
3answers
3k views

Java generics - implementing higher order functions like map

I decided to write some common Higher Order Functions in Java (map, filter, reduce, etc.) that are type safe via generics, and I'm having problems with wildcards matching in one particular function. ...
8
votes
4answers
1k views

Is Reactive Programming bounded to Functional programming?

I'd like to know how Reactive Programming is tied to Functional-Programming. Most papers refer "Reactive Programming" as "Functional Reactive Programming". Does Reactive Programming can be ...
8
votes
7answers
4k views

How can I map a String to a function in Java?

Currently, I have a bunch of Java classes that implement a Processor interface, meaning they all have a processRequest(String key) method. The idea is that each class has a few (say, <10) member ...
7
votes
6answers
2k views

What's the Scala way to implement a retry-able call like this one?

Still the newbie in Scala and I'm now looking for a way to implement the following code on it: @Override public void store(InputStream source, String destination, long size) { ObjectMetadata ...
7
votes
3answers
2k views

Is Scala a Functional Programming Language? [closed]

I've learned programming from Java, then tried to learn one programming language per year, second was C++, then Python. It came to learn next one, I looked for something new, I choose Scala because it ...
7
votes
3answers
692 views

functional java: what's this P1 thing?

I'm looking at Functional Java and I don't understand what a P1 is. Could anyone explain and/or give an example? (background: I do know what currying and closures are)
7
votes
5answers
517 views

Recursion runtime implementation Java vs. other/functionals languages?

I like recursion, but at Java you meet an dead end at some point. E.g. I had a case where recursion with ~100K iterations wouldn't work (StackOverflowError). Badly I had to switch to annoying ...
7
votes
6answers
1k views

How do I code a tree of objects in Haskell with pointers to parent and children?

I've got the following problem: I have a tree of objects of different classes where an action in the child class invalidates the parent. In imperative languages, it is trivial to do. For example, in ...
7
votes
1answer
1k views

Will I be able to use Clojure functions as Lambdas in Java 8?

I use a number of libraries in Clojure that produce higher order functions that conform to the "clojure.lang.IFn" interface. It has multiple arity overloads, I.e. the interface looks something like: ...
7
votes
3answers
257 views

What are the kinds of covariance in C#? (Or, covariance: by example)

Covariance is (roughly) the ability to mirror inheritance of "simple" types in complex types that use them. E.g. We can always treat an instance of Cat as an instance of Animal. A ...
6
votes
4answers
1k views

How to program without side-effects in Java?

Being a long-time Java programmer and in recent years a Haskell addict, I am learning Scala now. My question is: How to program without side-effects in Java ? i.e. How can I do manually what Scala ...
6
votes
5answers
462 views

Why - in Java 1.8 - is Function<V,R> used and not Function<R,V>?

The order seems odd because in regular Java the return type is always specified first. As in: public static double sum(Iterable<Number> nums) { ... } Why then, in the Function and ...
6
votes
5answers
220 views

Can anyone explain me what is state and mutable data?

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. ...
6
votes
6answers
1k views

static methods make Java a pseudo functional language?

I've been mulling about a post by Misko Hevery that static methods in Java are a death to testability. I don't want to discuss the testability issue but more on the concept of static methods. Why do ...
6
votes
3answers
551 views

How do you integrate functional programming languages to Java or C#?

I am interested in using OCaml or Haskell to develop an engine for statistical computing. This functionality is supposed to work on data that is going to be provided by a model driven, Object Oriented ...