Tagged Questions
0
votes
2answers
47 views
Scala read file and split and modify each line
I'm new to Scala. I want to read lines from a text file and split and make changes to each lines and output them.
Here is what I got:
val pre:String = " <value enum=\""
val mid:String = "\" ...
2
votes
1answer
111 views
Is it possible to build a Reactive Application using a non-Functional language?
I would like to understand if the principles behind the Reactive Application manifesto can be achieved using a non-functional language.
Some people say that since FP use immutable states and free ...
2
votes
2answers
64 views
Map a generic method over a list and produce list of results
I have a generic method (called map) which takes a parameter of type Funcn where Funcn<K,T> is an interface having only one method, T eval(K), which takes a K and returns a T. In map, I need use ...
1
vote
0answers
77 views
Functional programming Totallylazy tutorial [closed]
I want to learn the functional programming way provided by Totallylazy library.
However, I can't find any good tutorial or books on the web. Even on the official site, seems the document is less than ...
1
vote
3answers
91 views
How can I create a program in Java that is able to alter its own source code, or a mathematical function that it is then to run?
I want to create a program that uses an stochastic optimization algorithm to evolve mathematical functions, taking two constant numbers as inputs and evolving a function in order to produce a specific ...
6
votes
4answers
433 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 ...
4
votes
3answers
91 views
Immutable data structure replacement for arrays
What do you use when you need a immutable list with the fastest access/update? LinkedList can be slow if you have to access an element from the middle, and it's prohibitive to create and repopulate ...
4
votes
5answers
270 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 ...
0
votes
2answers
78 views
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 ...
2
votes
2answers
104 views
SML Function to “zip together” lists of an arbitrary depth
I'm trying to translate a nested for loop in Java code to SML. I'm going to have a list of the format [[a, b, c], [d, e, f], [g, h, i]] and I want this function to give me a list of the form [[a, d, ...
0
votes
2answers
96 views
Constructors in Scala
I ran into some design issues in Scala that relate to auxiliary constructors having to immediately call the primary (or other auxiliary)
I think the following example demonstrates the concept
class ...
2
votes
1answer
69 views
Symbolic identifiers in Scala
Classes need not use alphanumerics in Scala. Which means, the following is allowed
class > {
}
However, I am having a problem with passing such classes as varargs. The following code will ...
2
votes
2answers
145 views
Mapping data from one data structure to another
I know that it is rather a common pattern in many programming languages (predominantly functional) but I don't know exactly how does it call.
So I have one data structure e.g. List A and other List ...
1
vote
3answers
51 views
A reference to a method in java
I've been playing around with functional programing a little recently and I suspect it's got to me. But there's something I'd like to be able to do in Java and I'm not sure if It can be done.
I have ...
4
votes
1answer
173 views
How could the command pattern be replaced by lambda expressions?
This is kind of a follow-up to another question (Reuse code for looping through multidimensional-array) where my specific problem was resolved by using the command-pattern. My problem was, that I had ...
-1
votes
1answer
59 views
Functional programming in Java on google app engine [closed]
Does google app engine support any functional programming libraries ?
For example functionaljava : http://functionaljava.org/
0
votes
1answer
113 views
TotallyLazy functional code in Java
I am attempting to use the functional library TotallyLazy, in Java. I am programming in AIDE on Android. I have this code which doesn't work:
package net.intrepidis;
import java.util.Comparator;
...
1
vote
3answers
157 views
What is the best Java framework for functional style collection manipulation? [closed]
I am looking for a framework that will allow me to do functional style manipulation of collections. It will need to provide or support immutable collections and efficient multi step processing of map ...
6
votes
3answers
206 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 ...
0
votes
2answers
94 views
zip function for Java
Is there some standard API or established third party library (I am thinking commons or Guava) that provides in Java the equivalent of zip or map vector function in languages like Ruby or Clojure?
...
0
votes
2answers
88 views
How do I filter a list with functional programming in scala?
I have two lists:
val list1 = List("asdf", "fdas", "afswd", "dsf", "twea", "rewgds", "werwe", "dsadfs");
val list2 = List();
I want to filter all items from list1 and setup list2 so that it only ...
22
votes
1answer
731 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 ...
2
votes
2answers
292 views
Functional way to implement a thread safe shared counter
I'm relatively new to Scala and functional programming, and I like the idea that using immutable objects I can avoid many thread safety pitfalls. One thing still haunts me, and it's the classical ...
5
votes
5answers
153 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.
...
2
votes
3answers
181 views
The functional way to do “max” (with recursion / without mutable vars)
Finding a max in an unsorted array with imperative code is quite straight forward
e.g. in Java (I'm sure it can be written better, only used for illustration purposes)
public class Main {
public ...
0
votes
2answers
217 views
How to implement haskell data types in java?
If you have these Haskell data types
data Mlist a = Mlist [a]
data Mordering = MLT | MEQ | MGT | MIN deriving (Eq, Show)
Whats the best way to write this in java?
2
votes
2answers
125 views
How can I generate a List backed by a Function?
I have a function myFunction of Function<Integer, T>, and I want to construct an object mylist of size size, implementing List<T> (or maybe some kind of immutable list interface), backed ...
2
votes
2answers
79 views
Create and then write to a text file what is printed to the REPL
How, from a clj file, to take whats is outputted to the REPL by the function "print" and put it all in text file ?
Is there a way to create a new, empty, text file and put it in the project directory ...
3
votes
4answers
239 views
Equivalent of C++'s std::bind in Java?
Is there a way to bind parameters parameters to function pointers in Java like you can with std::bind in C++? What would the Java equivalent of something like this be?
void PrintStringInt(const char ...
1
vote
3answers
206 views
How to loop elements in 2d array to construct an string in “Ruby functional Style”
Ruby use the functions from "functional concept" heavily, such as map, each. They really depend on a self-contained function which is so called block in Ruby.
It is very common to loop though a 2d ...
1
vote
2answers
82 views
Clojure fails when calling amap on a primitive array
On ClojureDocs, it mentions that aset is only workable on array of refrence java types. But it does not mentions about the usage of amap.
(reduce
(fn [#^doubles sum #^doubles prob]
(println ...
1
vote
1answer
118 views
Why are there primitive functions like DoubleFunction in Java 8
I just had a look at the the new Java 8 function package and wonder why there are interfaces like
DoubleFunction
IntFunction
LongFunction
...
which do not extend Function. Doesn't that mean I will ...
4
votes
2answers
355 views
Inverse of Supplier<T> in Guava
I'm looking for the inverse of Supplier<T> in Guava. I hoped it would be called Consumer - nope, or Sink - exists, but is for primitive values.
Is it hidden somewhere and I'm missing it?
I'd ...
0
votes
4answers
199 views
Is there a purely functional immutable Map implementation for Java?
I have a Map in Java containing a number of key/value pairs.
I want to create a version of this Map with additional key/value pairs, but without losing the old version.
The simple solution would be ...
6
votes
1answer
507 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
1k 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 ...
2
votes
1answer
710 views
Functional programming in Java 7 [closed]
Does Java 7 have functional programming support or I still need to use FunctionalJava or another lib? I thought is has support to this, but didn't find much info about it.
1
vote
4answers
171 views
Functionally add a list of Integers
As the title says, I am trying to add a list of integers using the functional programming paradigm. So, no mutation at all. This is a homework assignment, and the method definition has been set by my ...
0
votes
2answers
125 views
Filtering a List in Java
In Haskell, I can do
filter pred list
To create a new list with elements of list for which the function pred is true. Does the Java API have something similar for java.util.List or other ...
1
vote
3answers
239 views
If you are using Scala as imperative language, you are doing it wrong? [closed]
For example, in previous question: Scala coding styles and conventions?
Someone complains "If the method grows it becomes very painful to read the code" ..
and Dr. Martin Odersky replied ".. The ...
4
votes
2answers
3k views
Guava - How to apply a function that returns Void on an Iterable
I just wonder what's the best way to apply a function that returns Void on an Iterable/Collection?
My usecase is:
i have a list of Animal objects
i want to call on each animal of the list the ...
-1
votes
1answer
209 views
Functional style recursion with Guava?
I have a MyService interface with MyServiceImpl basic implementation.
I wrap MyServiceImpl into a chain of MyService decorators.
For that i've created a MyServiceDelegate which is an abstract class ...
0
votes
2answers
417 views
How to create a session cookie in java with path while still having good programming practice of functional programming
I really like functional programming, I like its immutability concepts and also it's no side-effects concepts for functions.
I'm trying to take some of these concepts into java.
Now I have some kind ...
0
votes
3answers
159 views
Is there a java library for function programming?
Has anybody written a library in java that provides mapping functions (such as mapcar from lisp).
I saw this post and few others (such as this one this one), but sadly nothing that I could consider ...
0
votes
2answers
138 views
LambdaJ: why can't we apply operation in select clause?
select(list, having(on(Integer.class).intValue() % 2, equalTo(0)));
the code above throws exception.
0
votes
2answers
275 views
Reject values while using Maps.uniqueIndex with Guava
I'd like to know whether it's possible to discard some values when we use the Guava method.
public static Function<Locale, String> GET_LANGUAGE = new Function<Locale, String>() {
...
0
votes
2answers
194 views
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 ...
0
votes
1answer
59 views
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 ...
1
vote
2answers
143 views
Implementing simple functional-like paradigm in Java collections and type casting
I've recently started working in Scala and that was my first real contact with a functional paradigm. Although I'm a big fan of Java and, I admit, it lacks functional paradigm sometimes.
That's why ...
2
votes
2answers
123 views
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 ...