Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 19:17
    steinybot opened #2184
  • 18:26
    SethTisue commented #2172
  • 18:25

    SethTisue on main

    Simplify the example used for c… (compare)

  • 18:25
    SethTisue closed #2172
  • 18:25
    SethTisue reopened #2172
  • 17:50
    vlulla closed #2172
  • 14:53
    lrytz edited #12463
  • 14:53
    lrytz milestoned #12463
  • 14:53
    lrytz assigned #12463
  • 14:53
    lrytz labeled #12463
  • 14:53
    lrytz opened #12463
  • 12:59
    retronym labeled #9761
  • 08:51
    scala-jenkins milestoned #9761
  • 08:51
    lrytz review_requested #9761
  • 08:51
    lrytz opened #9761
  • 05:39
    nwk37011 synchronize #9752
  • 05:38
    nwk37011 synchronize #9752
  • Sep 15 20:28

    SethTisue on 2.12.x

    2.12: new Scala SHA (post-2.12.… (compare)

  • Sep 15 20:28
    SethTisue closed #1485
  • Sep 15 19:03
    NthPortal synchronize #9388
heksenlied
@heksenlied:matrix.org
[m]
The problems that it was made to solve are fixed in Scala 3, I think.
Rob Norris
@tpolecat
Not entirely fixed but the intent is that they will be. There is an open issue.
Fabio Epifani
@epifab

hello! In scala 2 I could have a type class to prove that another type class instance cannot exist:

sealed trait Negative[A]

object Negative {
  implicit def negative[T](implicit t: T): Negative[T] = new Negative[T] {}
  @implicitAmbiguous("Cannot negate ${T}")
  implicit def positive[T]: Negative[T] = new Negative[T] {}
}

What's the canonical way of achieving this in Scala 3?

heksesang
@heksenlied:matrix.org
[m]
NotGiven
Fabio Epifani
@epifab
awesome! thanks
Marco F.
@mfirry
Ichoran
@Ichoran
@Swoorup - No, Scala doesn't have the equivalent of dbg!, not exactly. You can get something close by building it with https://github.com/com-lihaoyi/sourcecode
Rob Norris
@tpolecat
scala> @implicitNotFound("oops, it's a subtype!") type <:!<[A,B] = NotGiven[A <:< B]
// defined alias type <:!<[A, B] = util.NotGiven[A <:< B]

scala> summon[String <:!< Int]
val res2: util.NotGiven[Nothing] = scala.util.NotGiven@10c23a76

scala> summon[String <:!< Object]
1 |summon[String <:!< Object]
  |                          ^
  |                          oops, it's a subtype!
Neato. The type argument interpolator foo ${A} bar doesn't work on type aliases, hm.
known issue lampepfl/dotty#7092
Guillaume Martres
@smarter
as a side-note, be careful about using a type like the <:!< you defined here, it doesn't mean "A is not a subtype of B", it means "I can't prove that A is a subtype of B"
Rob Norris
@tpolecat
:+1: indeed
idk-kid
@idk-kid

I have a nested schema dataframe.
I wanted to traverse and get some information out.
I was writing this function

def func(struct: StructType) = {
    struct match {
      case StructType(arr) => {
        arr.map{ fields =>
          fields match {
            case StructField(field, dataType, _, _) =>
              dataType match {
                case StructType(_) => func(dataType)
                case ArrayType(structTyp: StructType, _) => func(structTyp)
                case _ => .....
              }
          }
        }
      }
    }
  }

This line case StructType(_) => func(dataType) why is it of type DataType by default?
I tried making it StructType but it said cannot upcast.

Can anybody help?

Luis Miguel Mejía Suárez
@BalmungSan
Try with case struct @ StructType(_) => func(struct)
idk-kid
@idk-kid
So, how does this help? I never used that before
Luis Miguel Mejía Suárez
@BalmungSan
foo @ Bar means match the Bar pattern and if it matches then assign it to foo
In this case, it helps, because struct is of type StructType, which is what you need.
Eric K Richardson
@ekrich

I am really confused by this piece of code and Scala 3 braceless format:

object Foo:
  def joe(): List[(Int, Int)] =
    List((2, 3), (3, 4)).filter { case (a, b) => b > a }

If I remove the {} I get a parser error. If I then wrap the case onto the next line and indent it doesn't like that. I can replace the {} with () but then it doesn't like the case so then I can remove the case and it seems fine with that. I can't wrap the case or without the case to the next line. It is like () is required but is that going to work with a multi-line lambda?

Dan Sokolsky
@dansok
Hi, how to do this properly? --
val logicalPlans: Seq[LogicalPlan] = parsedQuery.collect {
  case logicalPlan >: org.apache.spark.sql.catalyst.plans.logical => logicalPlan
}
I.e., I want to check whether the logicalPlan is of subtype org.apache.spark.sql.catalyst.plans.logical
Rob Norris
@tpolecat
case logicalPlan: org.apache.spark.sql.catalyst.plans.logical => ...
Dan Sokolsky
@dansok
doesn't like it
Rob Norris
@tpolecat
What does it say?
idk-kid
@idk-kid
@BalmungSan it still complains
Luis Miguel Mejía Suárez
@BalmungSan
Really? What is the error this time?
Rob Norris
@tpolecat
Are you sure org.apache.spark.sql.catalyst.plans.logical is a type? The capitalization is suspicious.
Dan Sokolsky
@dansok
intellij doesn't recognize logical. highlights it in red, and gives you one of three opotionns along the lie of "create case class logical"
although the import statement import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan does in fact import LogicalPlan
Rob Norris
@tpolecat
Are you sure you don't want case logicalPlan: LogicalPlan => ...?
Dan Sokolsky
@dansok
I am
Rob Norris
@tpolecat
Why don't you want that?
Dan Sokolsky
@dansok
I want to filter all logical statements and make sure they are all SELECTs
(of type org.apache.spark.sql.catalyst.plans.logical.Project)
Rob Norris
@tpolecat
Ok then case logicalPlan: Project => ...
And your return type can be Seq[Project]
idk-kid
@idk-kid
@BalmungSan it's the same complaint
Dan Sokolsky
@dansok
but I want to throw if there is, say, an insert
so I want to get all logical statements, not just the selects
so I need to filter for org.apache.spark.sql.catalyst.plans.logical.*, not Project
Rob Norris
@tpolecat
Oh I see. You want to filter for anything in that package?
You can't do that.
You would need to check for each type, or for their common supertype if they have one.
Dan Sokolsky
@dansok
alright plan b -- convert to JSON and parse strings 🤘
yolo
"class" : "org.apache.spark.sql.catalyst.plans.logical.InsertIntoStatement"
I was trying to be a good citizen
Luis Miguel Mejía Suárez
@BalmungSan
I am sure my attempt to reproduce the code has many differences, try playing with the code until you get the same error.
Another possibility is that maybe the error you are seeing is not real? Like it is just an IDE thing but a real compiler will not produce it?
Dan Sokolsky
@dansok
how to get only the match from a regex?