Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 19:04
    NthPortal review_requested #9786
  • 17:20
    Kordyjan commented #1284
  • 17:14
    Kordyjan synchronize #1284
  • 17:13
    Kordyjan opened #1284
  • 16:31
    som-snytt commented #12473
  • 15:22
    NthPortal commented #12473
  • 15:18
    NthPortal commented #12473
  • 15:16
    NthPortal commented #12473
  • 15:15
    NthPortal commented #12473
  • 15:11
    NthPortal commented #12473
  • 14:49
    ches commented #12378
  • 13:15
    bishabosha edited #2205
  • 13:15
    bishabosha assigned #2205
  • 13:14
    bishabosha review_requested #2205
  • 13:14
    bishabosha review_requested #2205
  • 13:14
    bishabosha opened #2205
  • 11:15

    bishabosha on main

    simplify sbt cheatsheet eliminate we from scala 3 guide implement suggestions and 8 more (compare)

  • 11:15
    bishabosha closed #2202
  • 02:06
    SethTisue commented #10831
  • 02:06
    SethTisue closed #10831
Dan Sokolsky
@dansok
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?
I'm getting a hit, but it's returning the entire line

so,

val regex: Regex = "\"class\":\"org.apache.spark.sql.catalyst.plans.logical.*\"".r
println(regex.findAllMatchIn(queryString).toList)

gives back

List("class":"org.apache.spark.sql.catalyst.plans.logical.InsertIntoStatement","num-children":1,"table":[{"class":"org.apache.spark.sql.catalyst.analysis.UnresolvedRelation","num-children":0,"multipartIdentifier":"[table_1]"}],"partitionSpec":null,"query":0,"overwrite":false,"ifPartitionNotExists":false},{"class":"org.apache.spark.sql.catalyst.analysis.UnresolvedInlineTable","num-children":0,"names":"[col1]","rows")

where I am only looking for

"class":"org.apache.spark.sql.catalyst.plans.logical.InsertIntoStatement"

to be returned

Derek Wickern
@dwickern
For my Play plugin to work with any Play version [2.8.0,2.9), should the plugin depend on 2.8.0? Or should it depend on the range like [2.8.0,2.9.0[ or 2.8.+? Does it matter?
Martijn
@martijnhoekstra:matrix.org
[m]
@dansok: values in scala have types. findAllMatchIn returns a value of the type Iterator[Match]. You can then use those matches to get what you want. But it's not clear to me what it is you want exactly. Is it the matched text? Then you can use findAllIn which returns the matched strings rather than match objects
or select the matched member on the match object, which will give you the matched text
@dwickern: you can just depend on 2.8.0, and everything should work as expected.
you can also do the range, or at least, I've read that before, but I've never seen anyone do that in the wild
Derek Wickern
@dwickern
yeah, I haven't seen anyone use version ranges either
som-snytt
@som-snytt

@dansok your regex is greedy

scala> val r = raw"""(".*")""".r
val r: scala.util.matching.Regex = (".*")

scala> r.findFirstIn(""""one" and "two"""")
val res0: Option[String] = Some("one" and "two")

scala> val r = raw"""("[^"]*")""".r
val r: scala.util.matching.Regex = ("[^"]*")

scala> r.findFirstIn(""""one" and "two"""")
val res1: Option[String] = Some("one")

Nobody can tell but dotty is my default snippet repl now. Also, I notice using raw for regex spells raw.r.

BalmungSan @BalmungSan starts to sweat for resisting the urge of doing the "rawr" meme reference because is too cringe.
Rob Norris
@tpolecat
https://regexper.com is useful when you're trying to see what a regex does
som-snytt
@som-snytt
I have wanted string.r.explain for an instrumented regex that tells me what it did and why.
Rob Norris
@tpolecat
It could give you a URL to rexper populated with the regex. I wish regexper provided a way to quote your regex because that ends up being a big source of bugs.
gitleet
@gitleet
When reading a inline function (anonymous lambda?), do you read right from left or left to right? f: (String, T) => String = (a: String, b: T) => b.toString
Rob Norris
@tpolecat
What do you mean?
gitleet
@gitleet
I have trouble reading that ....
function that takes 2 params, string and T, and returns a String?
Rob Norris
@tpolecat
Yeah I would say something like "String T to String"
The parameter types are inferred on the RHS so you can say ... = (a, b) => b.toString which shortens it a bit.
gitleet
@gitleet
how can I add this inline function to a value? val f = .... ?
Are inline function parameters in a def optional?
zeroexcuses
@zeroexcuses
Is https://www.artima.com/shop/programming_in_scala_5ed still "draft", or is the book done:? (I can not find this book at any other website, and I have never purchased from this website, and this website's design does not look very modern.)
Martijn
@martijnhoekstra:matrix.org
[m]
What do you mean with adding to a funtion in this context @gitleet ? If you have some val f: Int => String, you can pass it to a method just by its name. Say, you have a val l = List(1, 2, 3), then you can pass it to its map method with l.map(f)
or do you maybe want to compose to functions, where you have a val g: Double => Int and also a val f: Int => String, and you want a function that first does g and then f, you can compose that as g.andThen(f)
(or as f.compose(g), which has the downside that you'll look more mathy and the upside that everyone finds it harder to read)
(bonus points on insisting it's way more natural for you)
gitleet
@gitleet
I tried to do: val f = (String, T) => String = (a: String, b: T) => b.toString
Martijn
@martijnhoekstra:matrix.org
[m]
you're going wrong with the syntax. The geneal syntax when defining a value is val name: Type = value
name here is f, the type is (String, T) => String, and the value is (a: String, b: T) => b.toString
that gives you val f: (String, T) => String = (a: String, b: T) => b.toString
there's a few things to notice here
if you already have a fully expected type, you can leave the ascriptions of the parameters off:
//instead of 
val f: (String, T) => String = (a: String, b: T) => b.toString
//you can do
val f: (String, T) => String = (a, b) => b.toString //because you already know the expected type, you don't need to repeat it
I get a not found type T error
Martijn
@martijnhoekstra:matrix.org
[m]
another thing to note is that you're not using a at all! that's probably a bug. This is a toy example, but be mindful
if T is intended to be a type parameter, in scala 2, you can't do that, and in scala 3, there is special syntax for that
gitleet
@gitleet
this is scala2
Martijn
@martijnhoekstra:matrix.org
[m]
in scala 2, unfortunately you can't have a function with a type parameter
gitleet
@gitleet
as a value...so it works inline ok
Martijn
@martijnhoekstra:matrix.org
[m]
there are workarounds, but they're not very pretty. Best for now to forget about it