Skip to content

Conversation

@mdedetrich
Copy link
Contributor

In #2198 we defined an IntFunction but there were some issues with the definition

  • There is no reason for IntFunction to allow throwing, this is used in retry functions for the delayFunction and supplying a function that can throw makes no sense and can lead to undefined behaviour
  • Moves implementation to scala since thats where all of the other functions sit, there is no reason to pointlessly split our implementations in java and scala, and having it sit in Scala is beneficial if we want to explore native/js. Java users can still use these functions without any problems (it in fact creates the exact same bytecode)

@SerialVersionUID(1L)
@FunctionalInterface
trait IntFunction[T] extends Serializable {
def apply(value: Int): T
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? what's the poin of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a place where we define all of our functional interfaces, its in actor/src/main/scala/org/apache/pekko/japi/function/Function.scala. In your PR you created another implementation in Java which means we have functional interfaces defined in both Scala and Java for no good reason.

Lets keep all of the functional interfaces defined where they already are in actor/src/main/scala/org/apache/pekko/japi/function/Function.scala so its consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is in #2185, ok?
Even Akka-sdk is now Java-first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are Java APIs, so shouldn't they be written in Java? Just because they were done in the past doesn't mean they should be done now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is in #2185, ok? Even Akka-sdk is now Java-first.

If you are going to make a decision like move everything to Java (or to Scala) for that matter, you need to discuss it with community first. You can't just sneak it into PR's because you think its a good idea.

Please discuss this with community first, also whether to throw an exception or not is a separate matter from whether functions can throw exceptions.

@He-Pin
Copy link
Member

He-Pin commented Sep 13, 2025

Check #2185 first

And then why can't the IntFunction throw? Are you kidding me?

Then tell why an Array(index: Int) can throw IOBE`?

@mdedetrich
Copy link
Contributor Author

Check #2185 first

And then why can't the IntFunction throw? Are you kidding me?

Then tell why an Array(index: Int) can throw IOBE`?

Its not that Int functions can never throw, its that throwing an exception as a supplier function in a pekko stream doesn't make any sense.

@He-Pin
Copy link
Member

He-Pin commented Sep 13, 2025

These are common functions. Thanks. Do you actually write Java on a daily basis? How much Java do you write on a daily basis?

@He-Pin
Copy link
Member

He-Pin commented Sep 13, 2025

And you should never define such a method in Scala , there is already one, In java's stdlib.

@mdedetrich
Copy link
Contributor Author

And you should never define such a method in Scala , there is already one, In java's stdlib.

Then we should use that one, I will change the PR to do so.

These are common functions. Thanks. Do you actually write Java on a daily basis? How much Java do you write on a daily basis?

I write Java/Kotlin frequently, and there is a reason why the Java functional interfaces do not allow exception throwing (albeit they should have also provided alternatives that do allow throwing)

Copy link
Member

@He-Pin He-Pin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a Java's IntFunction in stdlib

@mdedetrich mdedetrich force-pushed the move-int-function-to-scala-dont-allow-throwing branch from 0bac5cd to 43a2362 Compare September 13, 2025 08:31
@mdedetrich
Copy link
Contributor Author

There is already a Java's IntFunction in stdlib

Fixed and pushed

@mdedetrich mdedetrich force-pushed the move-int-function-to-scala-dont-allow-throwing branch from 4a05322 to f9a8c96 Compare September 13, 2025 09:04
Copy link
Member

@pjfanning pjfanning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - I'm ok with this if @He-Pin is happy with this change

@He-Pin
Copy link
Member

He-Pin commented Sep 15, 2025

actually we should just do a revert instead of this.

Copy link
Member

@He-Pin He-Pin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@He-Pin
Copy link
Member

He-Pin commented Sep 15, 2025

Although this is not the result I want, I can accept it, reduce the change set help anyway.

@He-Pin He-Pin merged commit daf3458 into apache:main Sep 15, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants