Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Add the ability to use either with Java 8 #365

Closed
wants to merge 1 commit into from
Closed

Add the ability to use either with Java 8 #365

wants to merge 1 commit into from

Conversation

k33g
Copy link
Contributor

@k33g k33g commented Feb 18, 2016

It could be interesting to use golo as library for Java:

import gololang.error.Result;
import java.util.function.Function;
...

Function<String, Result<Integer, RuntimeException>> toInt = (String val) -> {
  try {
    return Result.ok(Integer.parseInt(val));
  } catch (Exception e) {
    return Result.fail("Huston? We've got a problem!");
  }
};

Integer result = toInt.apply("fourty-two").either(value -> {
  System.out.println("Success: " + value);
  return value;
}, err -> {
  System.out.println(err.getMessage());
  return 42;
});

@jponge
Copy link
Contributor

jponge commented Feb 18, 2016

What's the link between your Java 8 code sample and using Golo as a library?

I understand what you have in your commit, but I can't see your point in the discussion 😉 🍷

@k33g
Copy link
Contributor Author

k33g commented Feb 19, 2016

Java 8 brings us Optional, but not Result. I found it interesting to use
the Result of Golo, and especially the either method directly with Java.
But, to my mind the version of either with FunctionReference is hard to
use
And it's more "human" readable if we can pass Function as parameters of
either (the code becomes beautiful as JavaScript :p)

It's also an other way to demonstrate the interoperability between Golo and
Java, and by the way, it shows that Golo has some assets that not exist in
Java.

... Even if Result is written in Java

On Thu, Feb 18, 2016 at 9:55 PM, Julien Ponge notifications@github.com
wrote:

What's the link between your Java 8 code sample and using Golo as a
library?

I understand what you have in your commit, but I can't see your point in
the discussion [image: 😉] [image: 🍷]


Reply to this email directly or view it on GitHub
#365 (comment).

@k33g k33g closed this Jul 31, 2016
@k33g k33g deleted the wip-either-for-java8 branch July 31, 2016 08:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants