Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 16:19
    som-snytt commented #9668
  • 16:19
    som-snytt commented #9668
  • 16:16
    SethTisue milestoned #12414
  • 16:13
    SethTisue commented #215
  • 14:02
    som-snytt commented #12414
  • 09:47
    danarmak commented #12414
  • 09:05
    retronym converted_to_draft #215
  • 08:47
    retronym synchronize #215
  • 08:22
    julienrf closed #2072
  • 08:22
    julienrf commented #2072
  • 08:16

    julienrf on main

    fix: fix syntax issue with argu… Merge pull request #2080 from S… (compare)

  • 08:16
    julienrf closed #2080
  • 08:15

    julienrf on main

    Suggestions in the Scala 3 book… Merge pull request #2079 from s… (compare)

  • 08:15
    julienrf closed #2079
  • 08:11
    Raysphere24 closed #2059
  • 08:06
    julienrf synchronize #2079
  • 06:54
    SrTobi opened #12415
  • 06:06
    retronym synchronize #215
  • 06:01
    retronym synchronize #215
  • 05:42
    Philippus commented #2081
Deepak Singh
@dpk3d
@ochrons got 2h 5m0s but my expected is 2h5m0s
Deepak Singh
@dpk3d

I have a string S = "00-44 48 555 8361"

And I want to format the string that digits are grouped in blocks of length three separated by - dash . Final block can be two digits.

Expectation is "004-448-555-583-61"

Can someone gives me heads up on this

Josef
@Josef-Vonasek
in pseudocode: S.filter(!_.inside("- ")).groupBy3.mkString("-")
Deepak Singh
@dpk3d

I've done in Python
Can someone convert in Scala

Solution

ph = "00-44 48 5555 8361"

def normalize(ph):
tmp = []
final_str = ""
index = 0
while( index < len(ph)):
if ph[index] == ' ' or ph[index] == '-':
index +=1
continue
tmp.append(ph[index])
if len(tmp) == 3:
str = ""
final_str = final_str + '-' +str.join(tmp)
tmp = []
index+=1
str = ""
final_str = final_str + '-' +str.join(tmp)
final_str = final_str.lstrip("-").rstrip("-")
return final_str

print (ph)
print (normalize(ph))

Andriy Plokhotnyuk
@plokhotnyuk
s.filter(_.isDigit).sliding(3, 3).mkString("-")
Josef
@Josef-Vonasek
^ or this :D
Did not know about sliding, nice.
Deepak Singh
@dpk3d
@Josef-Vonasek @plokhotnyuk do I've to import something
Andriy Plokhotnyuk
@plokhotnyuk
no
Josef
@Josef-Vonasek
use @plokhotnyuk code, mine is just pseudocode, some of the functions do not exist
Andriy Plokhotnyuk
@plokhotnyuk
here is how it looks in Scala REPL:
$ scala
Welcome to Scala 2.13.0 (OpenJDK 64-Bit GraalVM CE 19.1.1, Java 1.8.0_222).
Type in expressions for evaluation. Or try :help.

scala> val s = "00-44 48 555 8361"
s: String = 00-44 48 555 8361

scala> s.filter(_.isDigit).sliding(3, 3).mkString("-")
                           ^
       warning: method sliding in class StringOps is deprecated (since 2.13.0): Use `s.toSeq.sliding(...).map(_.unwrap)` instead of `s.sliding(...)`
res0: String = 004-448-555-836-1
! "00-44 48 555 8361".filter(_.isDigit).sliding(3, 3).mkString("-")
multibot1
@multibot1
^
warning: method sliding in class StringOps is deprecated (since 2.13.0): Use 's.toSeq.sliding(...).map(_.unwrap)' instead of 's.sliding(...)'
String = 004-448-555-836-1
Andriy Plokhotnyuk
@plokhotnyuk
multibot use Scala 2.13 too :)
Josef
@Josef-Vonasek
! 1 + 1
multibot1
@multibot1
Int = 2
Deepak Singh
@dpk3d
I've little change in case suppose input is "004-44 8553 615 4" -->. Final block or last two block can be of length two … output "004-448 -553 -61-54"
@plokhotnyuk thanks can you give heads up for above case also
Deepak Singh
@dpk3d

Can someone provide the solution for below Problem in Scala::
It's in python I want in scala

https://stackoverflow.com/questions/47448218/find-the-sentence-containing-the-largest-number-of-words-in-a-given-text-codilit

Daniel Gordon
@DanielGGordon

I have this regex with matching groups, and l tested it online via some free regex tester, but in Scala I am having strange results.

  val ProductExtractorRegex: Regex = {
    val Product = """.+?""" //name of the product
    val Dvn = """[A-Z0-9]{5}"""
    val Region = """[A-Z]{2,}""" 
    val ProductCode = """[A-Z0-9]{5}""" 
    val ProductSubtype = """[A-Z0-9]{5}""" 
    val Extension = """(zip|z[0-9]{2})"""
    s"($Product)[\\-_]($Dvn)[\\-_]($Region)[\\-_]($ProductCode)[\\-_]($ProductSubtype)\\.($Extension)".r
  }

val ProductExtractorRegex(productName, dvn, region, productCode, productSubtypeWithUnderscore, extension) = "SOMEPRODUCT_12345_SOMEREGION_OLELS_SLSLS.z01"

I get a scala.match error on this, and it is because of the ProductSubtype. If I get rid of it, and remove that part from the string - it works. But after I add the ProductSubtype, the match fails. Even though it is a very simple 5x letter string.

Martijn Hoekstra
@martijnhoekstra
nothing strikes me as odd -- do you have test input for it?
Daniel Gordon
@DanielGGordon
"SOMEPRODUCT_12345_SOMEREGION_OLELS_SLSLS.z01" is the test input I'm testing right now
Martijn Hoekstra
@martijnhoekstra
Deepak Singh
@dpk3d
@martijnhoekstra 🤘🏻😎
Daniel Gordon
@DanielGGordon
@martijnhoekstra that ProductSubtype was actually supposed to be an optional group, but that didn't work either. Even as non-optional capture group, I get the match error
Martijn Hoekstra
@martijnhoekstra
Extension is two groups
or rather, (Extension) is two groups
Daniel Gordon
@DanielGGordon
it is?
Martijn Hoekstra
@martijnhoekstra
Either remove the parents around Extension, or around its interpolation
Daniel Gordon
@DanielGGordon
OH
jesus
Martijn Hoekstra
@martijnhoekstra
regex, the bread and butter of programming help chat rooms :D
Daniel Gordon
@DanielGGordon
F* me
I spent 2-3 hours on this
That was the issue
Martijn Hoekstra
@martijnhoekstra
:+1:
Daniel Gordon
@DanielGGordon
Really appreciate it
Deepak Singh
@dpk3d
@martijnhoekstra totally agreed dude
Rob Norris
@tpolecat
We need an AI that helps people with regexes.
And another that helps people with cats imports.
(That one could be very simple.)
Martijn Hoekstra
@martijnhoekstra
in fact, I bet I could write a regex for the second one
Rob Norris
@tpolecat
Synergy.
Martijn Hoekstra
@martijnhoekstra
it's kinda lame that you "just" get a match exception, but I don't think you can actually do better
Fabio Labella
@SystemFw
just replaced some regexes with atto, quite pleasant
Rob Norris
@tpolecat
:-)
Eric Peters
@er1c
I have a signature like: def makeAndSetIterableField[V, T <: Iterable[V], F <: ScalarFormField[T]](attrRef: AttributeRef[T], field: F): AttributesFormField[T] that I want to use via: makeAndSetIterableField(attrRef.cast(t) /* Set[Int] */, text[Int](key, name, includeUseValueCheckbox = true)) without being explicit with type parameters makeAndSetIterableField[Int, Set[Int], ...](attrRef.cast(t) /* Set[Int] */, text[Int](key, name, includeUseValueCheckbox = true)) ... I could change the signature to something like: def makeAndSetIterableField[V, T <: Iterable[V], F <: ScalarFormField[T]](attrRef: AttributeRef[_ <: Iterable[V]], field: F): AttributesFormField[T] but then I lose the type T in the attrRef. What am I missing? (and ignore the cast red flag :)
Is this where something like (implicit tag: TypeTag[V]) would help? I guess I could try lol