Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-17170

Lambda-based mapping of an ObjectProvider's object when available or unique

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 5.x Backlog
    • Component/s: Core:DI
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      ObjectProvider should accept Function as argument like Consumer SPR-16001

      	public default <R> Optional<R> ifAvailable(Function<T, R> dependencyFunction) throws BeansException {
      		T dependency = getIfAvailable();
      		if (dependency != null) {
      			return Optional.ofNullable(dependencyFunction.apply(dependency));
      		}
      		return Optional.empty();
      	}
      
      	public default <R> Optional<R> ifUnique(Function<T, R> dependencyFunction) throws BeansException {
      		T dependency = getIfUnique();
      		if (dependency != null) {
      			return Optional.ofNullable(dependencyFunction.apply(dependency));
      		}
      		return Optional.empty();
      	}
      

        Attachments

          Activity

            People

            Assignee:
            juergen.hoeller Juergen Hoeller
            Reporter:
            quaff Yanming Zhou
            Last updater:
            Spring Issuemaster
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Days since last comment:
              1 year, 26 weeks, 1 day ago