Skip to content

Conversation

@Atry
Copy link
Contributor

@Atry Atry commented Aug 20, 2018

This is the implementation for scala/docs.scala-lang#1135

@scala-jenkins scala-jenkins added this to the 2.13.0-RC1 milestone Aug 20, 2018
@ShaneDelmore
Copy link
Contributor

I find myself converting between these quite frequently, would love to have this out of the box ❤️

@Atry
Copy link
Contributor Author

Atry commented Aug 21, 2018

I updated the proposal to remove the extra extract method call. A PartialFunction is now an extractor.

@Atry Atry force-pushed the extractor branch 2 times, most recently from 2203267 to ea42814 Compare August 21, 2018 15:37
@Atry Atry force-pushed the extractor branch 2 times, most recently from a066d88 to 1f3d18e Compare August 22, 2018 01:01
@Atry

This comment has been minimized.

@Atry
Copy link
Contributor Author

Atry commented Aug 24, 2018

Hi @SethTisue , will there be a chance to include this PR in 2.13?

@ScalaWilliam
Copy link

Very useful. I vote for this being in 2.13.

@lrytz
Copy link
Member

lrytz commented Nov 2, 2018

Looks good (the change) and useful. Seems small enough and self-contained, does it need to go to the SIP meeting? cc @adriaanm

@adriaanm
Copy link
Contributor

No, I don't think this needs a SIP

@sjrd
Copy link
Member

sjrd commented Nov 26, 2018

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.

@Atry

This comment has been minimized.

@Atry Atry force-pushed the extractor branch 2 times, most recently from 6ef5897 to d5de017 Compare November 27, 2018 05:26
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Dec 4, 2018
@SethTisue
Copy link
Member

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:

  • should Function.unlift be deprecated (and its Scaladoc merged into that for the new method)...?
  • given that PartialFunction#lift is now synonymous with the new PartialFunction#unapply, should the former be deprecated?
  • there is an elementWise example in the SIP draft; could this become a Scaladoc @example?
    • but also, perhaps it would be better to demonstrate elementWise separately from unlift?
  • the "cheat sheet" in the SIP draft is cool; is there a natural home for it in the stdlib Scaladoc...?
  • is elementWise the best possible name? perhaps matchAll?

@Atry
Copy link
Contributor Author

Atry commented Dec 5, 2018 via email

@ctongfei
Copy link

ctongfei commented Jan 6, 2019

I updated the proposal to remove the extra extract method call. A PartialFunction is now an extractor.

I believe that you should retain the extract name, or something else like invert. In your test case:

  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 pf("one") == 1;but it is actually the other way around -- it is pf(1) == "one".

I believe that in the clause y match { case f(x) => }, it should be semantically interpreted as "test if y is f(x); if it is, obtain x", or you could say that it is basically solving an equation y = f(x) for x. This is the case for case class deconstruction/unapplying.

@Atry
Copy link
Contributor Author

Atry commented Jan 10, 2019

@ctongfei , it's true that the extractor reversed the result and parameters.

I can rename it back to extract if the SIP committee agrees your opinion.

@ctongfei
Copy link

@Atry I believe that this is considered a library improvement, so no need for a SIP process?

@Atry
Copy link
Contributor Author

Atry commented Jan 10, 2019

@adriaanm and @SethTisue How do you think of the extract suffix?

@adriaanm adriaanm removed their assignment Feb 4, 2019
@adriaanm
Copy link
Contributor

adriaanm commented Feb 4, 2019

@SethTisue could you look into this one?

@diesalbla diesalbla added the library:base Changes to the base library, i.e. Function Tuples Try label Mar 17, 2019
@adriaanm
Copy link
Contributor

Rebased and squashed.

@adriaanm adriaanm requested a review from SethTisue March 18, 2019 13:01
@adriaanm
Copy link
Contributor

@SethTisue it looks like all outstanding review comments were addressed -- could you make a final pass and get this merged?

@SethTisue
Copy link
Member

@adriaanm and @SethTisue How do you think of the extract suffix?

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 case foo(bar) in any match clause, we always know bar is an output, not an input.

Copy link
Member

@SethTisue SethTisue left a 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)

@SethTisue SethTisue added the prio:blocker release blocker (used only by core team, only near release time) label Mar 19, 2019
@SethTisue
Copy link
Member

the Travis-CI failure is an unrelated Dotty problem (with a fix PR in-flight). green Jenkins is good enough

@SethTisue
Copy link
Member

SethTisue commented Mar 19, 2019

@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.

@SethTisue SethTisue merged commit 5e547be into scala:2.13.x Mar 19, 2019
@Atry Atry deleted the extractor branch March 20, 2019 05:44
julienrf added a commit to scalacenter/docs.scala-lang that referenced this pull request May 3, 2022
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.
@SethTisue
Copy link
Member

@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...?

julienrf added a commit to scala/improvement-proposals that referenced this pull request Jun 9, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

library:base Changes to the base library, i.e. Function Tuples Try prio:blocker release blocker (used only by core team, only near release time) release-notes worth highlighting in next release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.