Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 08:51
    NthPortal commented #9820
  • 07:52
    joroKr21 synchronize #9818
  • 07:52
    joroKr21 synchronize #9818
  • 07:03
    som-snytt commented #10342
  • 07:01
    som-snytt commented #11779
  • 06:48
    som-snytt commented #10276
  • 04:56
    eed3si9n edited #2235
  • 03:14
    NthPortal edited #9821
  • 03:14
    NthPortal synchronize #9821
  • 03:10
    NthPortal commented #9821
  • 03:10
    NthPortal edited #9821
  • 03:09
    NthPortal commented #9821
  • 03:07
    NthPortal commented #9821
  • 03:05
    NthPortal edited #9821
  • 03:05
    NthPortal edited #9821
  • 03:04
    NthPortal commented #9821
  • 03:04
    scala-jenkins milestoned #9821
  • 03:04
    NthPortal labeled #9821
  • 03:04
    NthPortal review_requested #9821
  • 03:04
    NthPortal opened #9821
Dan Sokolsky
@dansok
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
Ghost
@ghost~5fac9159d73408ce4ff3d745

@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
Ghost
@ghost~5fac9159d73408ce4ff3d745
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
there isn't really any difference between inline and not inline
in your situation, it probably works because T is defined when you call it inline, and not if you don't
e.g. given def foo[T](f: T => Int), you can do foo((t: T) => 7) because T is defined there
It's good to note that you can't really do anything with it, precisely because it's abstract: in my example I ignore it entirely
in your example, you call toString on it, which you can always do
but that's about it for the things you can do with T of a type you don't know
it could just as well have been Any, you can't do anything more with it