/**
 * Copyright (C) 2014-2018 Lightbend Inc. <https://www.lightbend.com>
 */
package akka.stream.javadsl

import akka.stream._
import akka.stream.scaladsl
import akka.japi.function
import akka.NotUsed

/**
  * Combine the elements of multiple streams into a stream of combined elements using a combiner function,
  * picking always the latest of the elements of each source.
  *
  * No element is emitted until at least one element from each Source becomes available. Whenever a new
  * element appears, the zipping function is invoked with a tuple containing the new element
  * and the other last seen elements.
  *
  *   '''Emits when''' all of the inputs have at least an element available, and then each time an element becomes
  *   available on either of the inputs
  *
  *   '''Backpressures when''' downstream backpressures
  *
  *   '''Completes when''' any of the upstreams completes
  *
  *   '''Cancels when''' downstream cancels
  */
object ZipLatestWith {

   /**
   * Create a new `ZipLatestWith` vertex with the specified input types and zipping-function `f`.
   *
   * @param f zipping-function from the input values to the output value
   * @param attributes optional attributes for this vertex
   */
  def create[A, B, Out](f: function.Function2[A, B, Out]): Graph[FanInShape2[A, B, Out], NotUsed] =
    scaladsl.ZipLatestWith(f.apply _)

  [3..22#/** Create a new `ZipLatestWith` specialized for 1 inputs.
   *
   * @param f zipping-function from the input values to the output value
   * @param attributes optional attributes for this vertex
   */
  def create1[[#T1#], Out](f: function.Function1[[#T1#], Out]): Graph[FanInShape1[[#T1#], Out], NotUsed] =
    scaladsl.ZipLatestWith(f.apply _)#

  ]

}
