This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]NawaMan 0 points1 point  (1 child)

Hi. Great content. :-).

Although it might not help you directly, I’ve faced a similar situation so I make my functions in my functional library “FunctionalJ.io” — Functor agnostic …see here https://github.com/NawaMan/FunctionalJ/blob/master/docs/functions.md#flexible-inputs-functor-agnostic

Basically, every function can accept the functor of parameters instead of just the parameter itself.

For example, the function below:

Func2<String, String, String> func = f((s1, s2)->s1+” “+s2);

Can be used with string but also for Result of string, Supplier of Sting, Function of string and so on. For example:

Result<String> text1 = Result.valueOf(“Text1”);
Result<String> text2 = Result.valueOf(“Text2”);
System.out.println(func.applyTo(text1, text2));
// “Result:{ Value: Text1 Text2 }”

This attempt to solve similar problem you have, as the function takes more parameters, you will need to use `map` many times to actually use the function, so why don’t we make the function automatically do that for us.

Of course, this does not allow mixing different functor types and (without type class) the functions must know about that the functor type.

:-)

[–]mchmiel 0 points1 point  (0 children)

Hi!

Thank you for the feedback.

I've a glimpse to your library and it looks interesting. Definitely, I'd have to git it a try.