Scala-specific extensions that enable partial function support for more idiomatic Scala programming with automatic conversion between partial and total functions.
import org.apache.flink.streaming.api.scala.extensions._class OnDataStream[T] {
def mapWith[R: TypeInformation](fun: PartialFunction[T, R]): DataStream[R]
def flatMapWith[R: TypeInformation](fun: PartialFunction[T, TraversableOnce[R]]): DataStream[R]
def filterWith(fun: PartialFunction[T, Boolean]): DataStream[T]
def keyingBy[K: TypeInformation](fun: PartialFunction[T, K]): KeyedStream[T, K]
}
class OnKeyedStream[T, K] {
def mapWith[R: TypeInformation](fun: PartialFunction[T, R]): DataStream[R]
def flatMapWith[R: TypeInformation](fun: PartialFunction[T, TraversableOnce[R]]): DataStream[R]
def filterWith(fun: PartialFunction[T, Boolean]): DataStream[T]
def reduceWith(fun: PartialFunction[(T, T), T]): DataStream[T]
}import org.apache.flink.streaming.api.scala._
import org.apache.flink.streaming.api.scala.extensions._
val env = StreamExecutionEnvironment.getExecutionEnvironment
val events = env.fromElements("start", "data", "end", "error")
// Partial function mapping
val mapped = events.mapWith {
case "start" => "BEGIN"
case "end" => "FINISH"
case data => s"PROCESS: $data"
}
// Partial function filtering
val filtered = events.filterWith {
case "error" => false
case _ => true
}Scala extensions provide idiomatic Scala programming patterns while maintaining Flink's type safety and performance characteristics.