[
https://issues.apache.org/jira/browse/FLINK-1159?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15162888#comment-15162888
]
ASF GitHub Bot commented on FLINK-1159:
---------------------------------------
GitHub user stefanobaghino opened a pull request:
https://github.com/apache/flink/pull/1704
[FLINK-1159] Case style anonymous functions not supported by Scala API
The proposed API extension methods would allow developers to pass a pattern
matching anonymous function so that they are applied on a `DataSet` or
`DataStream`; many methods defined on the `DataSet` and `DataStream` APIs don't
support those functions due to the overloading[[1]][[2]]; pattern matching
anonymous functions allow a very idiomatic approach in Scala to *decompose
tuples, case classes and collections*.
The PR does not pollute the original `DataSet` and `DataStream` APIs but is
provided as an optional set of extensions methods, implemented via implicit
conversions and made available to the developer by explicitly importing the
required package, e.g.:
```scala
import org.apache.flink.api.scala.extensions.acceptPartialFunctions
env.fromElements('a -> 1, 'b -> 2).mapWith {
case (key, value) =>
... // key and value are now available and have a sensible name
}
```
[1]: https://groups.google.com/d/msg/scala-user/3oHnDEl1UsM/dDNir9BsiG4J
[2]:
http://www.scala-lang.org/files/archive/spec/2.11/06-expressions.html#overloading-resolution
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/radicalbit/flink 1159
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/flink/pull/1704.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1704
----
commit 61d184075cce9fa4f3a8e477634adef083d3a070
Author: Stefano Baghino <[email protected]>
Date: 2016-02-24T12:05:16Z
[FLINK-1159] Case style anonymous functions not supported by Scala API
----
> Case style anonymous functions not supported by Scala API
> ---------------------------------------------------------
>
> Key: FLINK-1159
> URL: https://issues.apache.org/jira/browse/FLINK-1159
> Project: Flink
> Issue Type: Bug
> Components: Scala API
> Reporter: Till Rohrmann
> Assignee: Stefano Baghino
>
> In Scala it is very common to define anonymous functions of the following form
> {code}
> {
> case foo: Bar => foobar(foo)
> case _ => throw new RuntimeException()
> }
> {code}
> These case style anonymous functions are not supported yet by the Scala API.
> Thus, one has to write redundant code to name the function parameter.
> What works is the following pattern, but it is not intuitive for someone
> coming from Scala:
> {code}
> dataset.map{
> _ match{
> case foo:Bar => ...
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)