Skip to content

Enable parameter Optionality through Java's Optional class #78

Closed as not planned

Description

@gselzer

Current iterations of Op reduction (see scijava/incubator#32) use an @Optional annotation. @ctrueden suggested that we also support optionality using java.util.Optional, i.e. an Op written as:

public class Foo implements BiFunction<Integer, Optional<Integer>, Integer> {
  @Override
  public Integer apply(Integer in1, Optional<Integer> in2) {
    ...
  }
}

This Op could then be manipulated (nearly identically as in the linked PR) to produce 2 OpInfos:

  1. Functionally a Function<Integer, Integer>
  2. Functionally a BiFunction<Integer, Integer, Integer>

Activity

  1. added this to the unscheduled milestone on Oct 4, 2021
  2. self-assigned this
    on Oct 4, 2021
  3. gselzer commented on Jul 13, 2023

    @gselzer
    MemberAuthor

    I think that for now, we are going to avoid doing this, for the following reasons:

    • The Optional class is designed more for providing nullable return values instead of optional-with-default parameters
    • Adding two ways to make parameters optional adds more complexity
    • Rewriting parameter types from Optional to the generic type of the optional requires javassist (whereas we could potentially use LambdaMetafactory if the parameter order is suitable), and could lead to matching errors
  4. added a commit that references this issue on May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions