-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Converters among optional Functions, PartialFunctions and extractor objects #7111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I find myself converting between these quite frequently, would love to have this out of the box ❤️ |
|
I updated the proposal to remove the extra |
2203267 to
ea42814
Compare
a066d88 to
1f3d18e
Compare
This comment has been minimized.
This comment has been minimized.
|
Hi @SethTisue , will there be a chance to include this PR in 2.13? |
|
Very useful. I vote for this being in 2.13. |
|
Looks good (the change) and useful. Seems small enough and self-contained, does it need to go to the SIP meeting? cc @adriaanm |
|
No, I don't think this needs a SIP |
|
This is purely a library-based changed. Even though it touches classes that are typically considered core to the language, I do not believe that this needs to be covered by the SIP process either. |
This comment has been minimized.
This comment has been minimized.
6ef5897 to
d5de017
Compare
|
although we agreed this doesn't need a SIP vote, the writeup you provided at scala/docs.scala-lang#1135 is nonetheless extremely helpful for reviewing this — thank you for that. I'm in favor of merging this, but I have some questions about specifics:
|
|
Seth Tisue <[email protected]> 于2018年12月5日周三 上午5:15写道:
although we agreed this doesn't need a SIP vote, the writeup you provided
at scala/docs.scala-lang#1135
<scala/docs.scala-lang#1135> is nonetheless
extremely helpful for reviewing this — thank you for that.
I'm in favor of merging this, but I have some questions about specifics:
- should Function.unlift be deprecated (and its Scaladoc merged into
that for the new method)...?
Function.unlift and UnliftOps.unlift share the same implementation for
different use cases, similar to assert and ensuring in Predef.
Considering we did not deprecate assert or ensuring, I don't think we have
to deprecate Function.unlift.
- given that PartialFunction#lift is now synonymous with the new
PartialFunction#unapply, should the former be deprecated?
No, because they are different. unapply is a unary method while lift is a
nullary method that returns a unary function.
- there is an elementWise example in the SIP draft; could this become
a Scaladoc @example?
Sure
-
- but also, perhaps it would be better to demonstrate elementWise
separately from unlift?
`elementWise` was originally implemented as `.extract.seq` , which is used
for creating extractors for matching nested repeated expressions
https://github.com/ThoughtWorksInc/Binding.scala/blob/96a311ec463fb8e47846565c516e23a3fdbc20be/XmlExtractor/src/main/scala/com/thoughtworks/binding/XmlExtractor.scala#L57
https://github.com/ThoughtWorksInc/Binding.scala/blob/96a311ec463fb8e47846565c516e23a3fdbc20be/dom/src/main/scala/com/thoughtworks/binding/dom.scala#L286
-
- the "cheat sheet" in the SIP draft is cool; is there a natural
home for it in the stdlib Scaladoc...?
Maybe in PartialFunction?
- is elementWise the best possible name? perhaps matchAll?
Given the following code,
```
val firstChar: String => Option[Char] = _.headOption
Seq("foo", "bar", "baz") match {
case firstChar.unlift.elementWise(c0, c1, c2) =>
println(s"$c0, $c1, $c2") // Output: f, b, b}
```
you can read it as:
The sequence of foo, bar, baz is matched for the first character on
element-wise.
`matchAll` seems a little redundant because there is the keyword match.
…
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#7111 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAktumj_ZTDKs5QvqNs8Mq5oMmS_v3Ceks5u1uX3gaJpZM4WEeay>
.
--
杨博 (Yang Bo)
|
I believe that you should retain the val pf: PartialFunction[Int, String] = {
case 0 => "zero"
case 1 => "one"
}
1 match {
case pf(m) =>
assertEquals(m, "one")
}This gives us a feeling that I believe that in the clause |
|
@ctongfei , it's true that the extractor reversed the result and parameters. I can rename it back to |
|
@Atry I believe that this is considered a library improvement, so no need for a SIP process? |
|
@adriaanm and @SethTisue How do you think of the |
|
@SethTisue could you look into this one? |
|
Rebased and squashed. |
|
@SethTisue it looks like all outstanding review comments were addressed -- could you make a final pass and get this merged? |
I think it's fine the way it is. I can see where @ctongfei is coming from, but it seems to me that whenever we have |
SethTisue
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's merge as soon as CI is green. (I just force-pushed a fix for a semantic conflict with #7847)
|
the Travis-CI failure is an unrelated Dotty problem (with a fix PR in-flight). green Jenkins is good enough |
|
@Atry I'm sorry this PR sat so long. it's my fault. thank you for this work, and I'm glad we did finally get it in. |
Assigned number 38 to SIP “Converters among optional functions, partial functions, and extractor objects”. Implemented in Scala 2.13.0 and Scala 3.0.0 in scala/scala#7111 The change did not _require_ a SIP because it was implemented at the library-level. Nevertheless, I decided to keep the SIP for posterity.
|
@Atry I happened to notice today that this PR is linked from the Scala 2.13.0 release notes, but the PR description lacks any information about what the PR actually adds. Can I interest you in editing the description to add that...? |
Assigned number 38 to SIP “Converters among optional functions, partial functions, and extractor objects”. Implemented in Scala 2.13.0 and Scala 3.0.0 in scala/scala#7111 The change did not _require_ a SIP because it was implemented at the library-level. Nevertheless, I decided to keep the SIP for posterity.
This is the implementation for scala/docs.scala-lang#1135