Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 06:55
    lihaoyi commented #1487
  • 06:54
    lihaoyi commented #1487
  • 06:53
    lihaoyi commented #1487
  • 06:52
    lihaoyi commented #1487
  • 06:02
    eugene70 synchronize #1507
  • 04:43
    som-snytt assigned #11428
  • 04:41
    som-snytt closed #11428
  • 04:41
    som-snytt commented #11428
  • 04:40
    som-snytt edited #7546
  • 04:25
    sjrd commented #11698
  • 04:19
    psilospore commented #11428
  • 03:48
    psilospore edited #8369
  • 03:45
    roottraveller commented #10418
  • 03:43
    scala-jenkins milestoned #8369
  • 03:43
    psilospore opened #8369
  • 03:25
    eed3si9n commented #11698
  • 01:02
    NthPortal commented #11698
  • Aug 24 23:00
    ijuma commented #10418
  • Aug 24 21:38
    SethTisue commented #10418
  • Aug 24 21:38
    SethTisue commented #7966
Guillaume Martres
@smarter
I thought there was an unsafe method or something for that now
oh ArraySeq.unsafeWrapArray, got it
som-snytt
@som-snytt
Maybe I'll try a PR moving SRE from scala to scala.reflect and see if Seth takes it for 2.14. Where I guess it would remain forever.
Guillaume Martres
@smarter
If I have a Set, can I get a sorted Seq out of it without making an intermediate Seq ?
I was expecteding a Set#sorted that would return a Seq
Nth
@NthPortal
I don't think so, sadly
not without doing it manually at least
som-snytt
@som-snytt
scala.tools.reflect has a package.scala with reflect.Eval class in the expected package.
Guillaume Martres
@smarter
manually ?
Nth
@NthPortal
@smarter
scala> val set = Set(2, 5, 1, 7, 3, 4, 8)
set: scala.collection.immutable.Set[Int] = HashSet(5, 1, 2, 7, 3, 8, 4)

scala> val arr = set.toArray[Int]
arr: Array[Int] = Array(5, 1, 2, 7, 3, 8, 4)

scala> java.util.Arrays.sort(arr)

scala> scala.collection.immutable.ArraySeq.unsafeWrapArray(arr)
res5: scala.collection.immutable.ArraySeq[Int] = ArraySeq(1, 2, 3, 4, 5, 7, 8)
that is in fact roughly what Seq(2, 5, 1).view.sorted.toSeq does; sadly there doesn't appear to be a good way to get there from Set
if you don't care about the mutability of the returned Seq, you can do set.toArray[Int].sortInPlace()
Nth
@NthPortal
actually, here's a nice one-liner:
 immutable.ArraySeq.unsafeWrapArray(set.to(mutable.ArraySeq).sortInPlace().array)
Guillaume Martres
@smarter
cool, thanks
So, the Ordering of Iterable is deprecated: Iterables are not guaranteed to have a consistent order; if using a type with a consistent order (e.g. Seq), use its Ordering (found in the Ordering.Implicits object), but... there's no Ordering of Seq in Ordering.Implicits, what am I missing ?
Nth
@NthPortal
you need to import a thing
1 sec
import scala.math.Ordering.Implicits._ should do it for you
(btw, in the one-liner above, the type of .array is not actually known to be Array[Int], so it may need some tweaking)
Guillaume Martres
@smarter
oh, I missed that, thanks
Nth
@NthPortal
I think it may need a cast at the end somewhere
I don't think .to(mutable.ArraySeq) guarantees it's an Array[Int], but I think mutable.ArraySeq.from[Int](set) might? you'd still need a cast though, sadly
Guillaume Martres
@smarter
I'm just going to eat the cost of the copy I think
don't blame me if Scala 3 is slow :p
Nth
@NthPortal
LOL
oh, another possibility
Guillaume Martres
@smarter
But I guess we should open an issue to consider this for 2.14
Nth
@NthPortal
mhm :thumbsup:
som-snytt
@som-snytt

Sorry for the unthreaded crosstalk. I happen to be reading a bio of Chopin, and it occurred to me that the whole thing about ell looking like the numeral one could be avoided by using crossed ell as in the Polish. Also .

scala> val ł = List(1)
ł: List[Int] = List(1)

I realize that basically all of my novel ideas are rejected. I also just realized that I've always mispronounced Lech Wałęsa (IPA: [ˈlɛɣ vaˈwɛ̃sa]), Polish labor leader and former president courtesy of https://en.wikipedia.org/wiki/%C5%81 I always thought it was like palatalized ell in Russian. Could I be more wrong?

Because of the Scala presence in Warsaw, I can't help but wonder about what you might call "Polish notation" in Scala.

Nth
@NthPortal
nvm, 2-liner doesn't work
Guillaume Martres
@smarter
So, I have an Iterable implementation that overrides foreach and then define override def iterator = this.toList.iterator
which explodes beautifully in 2.13 because toList is defined in terms of iterator
something to mention in the migration guide ? /cc @julienrf @szeiger
(and also in Dotty, where it leads to an actual crash, might be dead code in scalac)
Not an Iterator expert, so I'd appreciate it if someone could show me how this is actually supposed to be written
(also it's 2 AM and I'm 78 commits deep into making Dotty work on 2.13, so a bit out of motivation)
Nth
@NthPortal
@smarter it appears that the old implementation of toList was (List.newBuilder ++= it).result(), and the default impl of ++= for a builder is for (elem <- it) this += elem.
However, the new implementation of toList is List.from(it), which while loops over hasNext on the result of it.iterator
it looks like you can just take the implementation of foreach, drop the foreach f, and have a drop-in implementation of iterator though
Nth
@NthPortal
fun fact: an easy way to get the call stacks there is to do (Iterator.empty ++ { throw null }).toList
Guillaume Martres
@smarter
@NthPortal Just taking the foreach implementation and removing foreach f doesn't work, because withJarInput closes the input stream
Nth
@NthPortal
oh, hmm...
perhaps
def iterator = withJarInput { in =>
    Iterator.continually(in.getNextJarEntry()).takeWhile(_ != null).toList
  }.iterator
that seems ugly to me, and not super performant, but workable?
Guillaume Martres
@smarter
Turns out it doesn't actually need to be an Iterator, so I'll just keep a toList method
Nth
@NthPortal
fair
Guillaume Martres
@smarter
thanks for the help!
Nth
@NthPortal
np!
som-snytt
@som-snytt
TIL among other things that np is short for nth portal. I always wondered when they say np complete, but now it makes sense.
som-snytt
@som-snytt
Also, I don't know how to say Radziwiłł. Maybe I should ask over on typelevel?