This repository was archived by the owner on Oct 26, 2026. It is now read-only.
Repository navigation
Establish Scijava-functions as an independent module - #29
Merged
Merged
Conversation
ctrueden
suggested changes
Apr 27, 2021
Member
There was a problem hiding this comment.
This is awesome, and awesomely clean! 🏆
Here's what we discussed should be changed:
- For simplicity, and because this module is highly unlikely to grow in size, let's dispense with the
annotationssubpackage, and just keep all seven.javafiles at the top level. - The package name will become
org.scijava.function(singular) for consistency with Java core's functional interfaces packagejava.util.function. - Add a
package-info.javaexplaining that the naming aligns withjava.util.functionand is all about functional interfaces, not to be confused with SciJava Ops's use of the term "function". Relatedly, we discussed whether to use a different term in Ops now, to avoid a name clash here, but, ultimately decided that keeping the name "function" is the "least bad" approach for a number of reasons. - Add
ArityNinterfaces to container classes, but without the matching part—just the interface adaptation part. See below.
Points for future consideration:
- For
FunctionUtilset. al matching methods: since they all are static but take anOpEnvironmentas their first parameter, they are almost begging to be instance methods ofOpEnvironmentitself. The two main points against this are: 1) it greatly expands theOpEnvironment's API (but I'd argue not so greatly that it overwhelms callers, but rather empowers them to more easily match functions etc.); and 2) it "bakes in" three core functional op types more deeply. We need to be careful with (2) to avoid resulting in a system that does not support extensibility into additional functional types. But it might be worth the tradeoff here... - About
OpWrapper: our thinking as of our discussion is that theorg.scijava.ops.functionpackage will go away, with the wrappers moved to join the matcher, because it's an implementation detail that we want to encapsulate, and is only used by the matcher. - We decided not to move the op annotation interfaces (
OpClass,OpMethod,OpField) intoscijava-function, because they feel like bloat. However, they cannot live inscijava-opsas currently structured either, because then anyone who wants to use them will inherit bad dependencies (e.g. guava, javassist, therapy... 🤢) We agreed (reluctantly) that we need a separate Ops API module. The questions to ponder are: 1) how to name it? (scijava-ops-apiandscijava-ops-engine?) 2) which classes exactly belong in API vs impl module? Reviewing all the logic currently inscijava-opsone by one will be needed.
Interface adaptation for n-ary
Functions.Arity3<I1, I2, I3, O> myFunc = ....
Functions.ArityN<O> myFuncN = Functions.nary(myFunc);
public static Functions.ArityN<O> nary(Functions.Arity3<?, ?, ?, O> f) {
return new ArityN<>() {
Functions.Arity3<Object, Object, Object, O> func;
public Arity3AsN(Functions.Arity3<Object, Object, Object, O> func) {
this.func = func;
}
public O apply(Object... ins) {
// Consider doing more safety checks here, but I'm initially inclined against...
//if (ins[0] genericinstanceof func's first param type) and .... and length matches...
return func.apply(ins[0], ins[1], ins[2]);
}
public Function getFunction() {
return func;
}
}
}
public static Functions.ArityN<O> nary(Functions.Arity4<?, ?, ?, ?, O> f) { ... }
... code generated ...
Member
Author
|
Time commitment: 1 week |
gselzer
force-pushed
the
scijava/scijava-function/init
branch
3 times, most recently
from
May 18, 2021 17:19
1ea0333 to
7eaeb40
Compare
Member
Author
|
@ctrueden I have resolved all bullet points resulting from our discussion, and have also deleted the |
Member
Author
|
As of this comment, all commits build with passing tests |
Functions/Inplaces to come
To rimplify this module, we dispense with the annotations package. We also rename the module to scijava-function to align with java.util.function
This allows us to remove the package org.scijava.ops.function
gselzer
force-pushed
the
scijava/scijava-function/init
branch
from
June 25, 2021 19:48
99b0eb1 to
5fb1a5e
Compare
hinerm
approved these changes
Jun 25, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a new module,
scijava-functions, into the incubator. At the time of writing, this module contains only:Computers,Functions,Inplaces, andProducer) used by Ops@Container,@Mutable) designed to be used with those OpsThis partition is motivated by a desire to abstract the interfaces themselves from our particular use case. It is plausible that other developers might find our interfaces useful and would wish to use them without the baggage of Ops/the Ops matcher.
Points of discussion:
scijava-functionsa suitable name? Can we think of a better one? It is a little confusing that theComputers interfaces are found inscijava-functions...Functions.ArityXAsNinterfaces belong withinscijava-functions? They have no dependence on/relationship to Ops, but would developers get any use out of them? We would also have to make thempublic(as they are currentlyprotected)Computers/Inplaces/Functionshas been repackaged withinComputerUtils/InplaceUtils/FunctionUtils(this is mostly referring to thematch()methods. Should these classes continue to reside withinorg.scijava.ops.function, or should we move them intoorg.scijava.ops.util? We might also want to consider movingOpWrappers...@OpMethod/@OpField/@OpDependency, etc.) belong in this module as well? Anyone who wants to write Ops will need these annotations in addition to the interfaces enclosed in this module, however this module is spiritually independent of Ops; adding these annotations would remove that spirit.