Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 14:27
    jxnu-liguobin synchronize #9706
  • 13:59
    smarter commented #9697
  • 13:53
    SethTisue edited #1461
  • 13:53
    SethTisue labeled #1461
  • 13:53
    SethTisue assigned #1461
  • 13:53
    SethTisue opened #1461
  • 13:49
    SethTisue edited #1460
  • 13:48
    SethTisue labeled #1460
  • 13:48
    SethTisue assigned #1460
  • 13:48
    SethTisue opened #1460
  • 13:47
    dwijnand commented #9697
  • 11:37
    som-snytt commented #12433
  • 11:24
    som-snytt commented #12434
  • 09:56

    lrytz on 2.13.x

    Inline Lifted.apply in condOpt Merge pull request #9709 from s… (compare)

  • 09:56
    lrytz closed #9709
  • 09:50
    dwijnand commented #12434
  • 09:20
    lrytz edited #12434
  • 09:19
    lrytz edited #12434
  • 09:18
    lrytz labeled #12434
  • 09:18
    lrytz milestoned #12434
Nathan Fischer
@nrktkt:matrix.org
[m]
what are the issues with typesafe/lightbend config?
I know a few things I'd like to improve, but nothing really bad comes to mind
gitleet
@gitleet
I don't like how it returns java collections by default....
Rob Norris
@tpolecat
I don’t like how it uses config files.
1 reply
Seth Tisue
@SethTisue
unless you take Rob's position, HOCON seems quite nice to me
Luis Miguel Mejía Suárez
@BalmungSan
I believe I understand Rob's point. All my HOCONS are just redirects to env vars or constants.
So the config file just becomes more work to maintain and extra source for bugs.
Like having runtime errors because I had a typo in the HOCON file.
I want to try ciris, but it is in the bottom of my TODO list.
Jim Newton
@jimka2001

I am using a library function which I didn't write which as an argument of type => Any. I'd like to prepend some action before and after the object passed to that function. How can I do that?
Here is what I've tried, but it doesn't work.

class MyFunSuite extends AnyFunSuite {
  import org.scalactic.source
  import org.scalatest.Tag
  override def test(testName: String, testTags: Tag*)(testFun: => Any /* Assertion */)(implicit pos: source.Position):Unit = {
    lazy val action = locally{
      println("[ starting " + testName)
      try{      testFun }
      finally{ println("] finished " + testName)}
    }
    super.test(testName,testTags : _*)(action)(pos)
  }
}

When I run my test case I see output like the following which (I believe) means the finally is executed before the testFun

[ starting subclass
] finished subclass
[ starting disjoint
] finished disjoint
[ starting disjoint and subtype
] finished disjoint and subtype
[ starting randomizer
] finished randomizer
[ starting test 1
] finished test 1
[ starting typep
] finished typep
[info] GenusBddTest:
[info] - subclass
[info] - disjoint
[info] - disjoint and subtype
[info] - randomizer
[info] - test 1
[info] - typep
Jim Newton
@jimka2001
The problem is that I have a test which gives an out-of-heap-space error. And if [info] is printed after the test finishes, then the [info] for the problematic test never gets printed.
Alessandro
@ImGrayMouser_twitter

@BalmungSan

They are mutable, they are invariant, they do not have a pretty toString nor a sensible equals

In such a case why the Scala library allows to have Set[Array[A]] when we know upfront that it won't just work ? It's a wrong. At least it must force us to provide a working equal or hashcode or whatever the Set implementation is using under the hood

Jim Newton
@jimka2001
copying the locally{....} directly into the call to super.test(...)(locally{....})(pos) seems to do a better job. At least I can see that it runs the test between printing starting and finished however, it still prints all the [info] lines after all the tests have run.
Jim Newton
@jimka2001
can anyone tell me whether the java reflection API will allow me to somehow walk the subclasses of a given class?
I have some code which tries to reason about whether two given classes (i.e., objects of class java.lang.Class) are disjoint (i.e., have no common subclass) . Currently I'm supposing that a class such as java.lang.Number is not necessarily disjoint from myTrait because it is possible to to create a subclass of Number like this abstract class Xyz extends java.lang.Number with myTrait.
However, if I could detect that that has not occurred, i.e., there is no common subclass of myTrait and java.lang.Number (which is the case 99.9999% of the time), then there is a significant optimization I could make in my data structure.
Rob Norris
@tpolecat
Not in general, no. A program can load classes over the network for example. There’s no way in general to know what’s out there.
It sounds like a design problem.
Jim Newton
@jimka2001
I found this, but I don't know enough about java to know whether it is what I want or not https://www.javadoc.io/doc/org.reflections/reflections/0.9.10/org/reflections/Reflections.html
@tpolecat as far as Java is concerned are these two questions the same? 1. does there currently in VM exist a subclass of a given class X, and 2) does there exist a class which I have not loaded yet which would be a subclass of X if it ever gets loaded? For example in CLOS those are two different questions, the first is answerable, the second is not.
Jim Newton
@jimka2001

If I want to experiment with: https://www.javadoc.io/doc/org.reflections/reflections/latest/org/reflections/Reflections.html is there a way to update my build.sbt file to include the library? I tried the following, but it doesn't work

libraryDependencies += "org.reflections" %% "Reflections" % "0.9.12"

I see the following when I try to start sbt:

[warn]     module not found: org.reflections#Reflections_2.13;0.9.12
[warn] ==== local: tried
[warn]   /Users/jnewton/.ivy2/local/org.reflections/Reflections_2.13/0.9.12/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/reflections/Reflections_2.13/0.9.12/Reflections_2.13-0.9.12.pom
[warn] ==== local-preloaded-ivy: tried
[warn]   /Users/jnewton/.sbt/preloaded/org.reflections/Reflections_2.13/0.9.12/ivys/ivy.xml
[warn] ==== local-preloaded: tried
[warn]   file:////Users/jnewton/.sbt/preloaded/org/reflections/Reflections_2.13/0.9.12/Reflections_2.13-0.9.12.pom
[warn]     ::::::::::::::::::::::::::::::::::::::::::::::
[warn]     ::          UNRESOLVED DEPENDENCIES         ::
[warn]     ::::::::::::::::::::::::::::::::::::::::::::::
[warn]     :: org.reflections#Reflections_2.13;0.9.12: not found
[warn]     ::::::::::::::::::::::::::::::::::::::::::::::
I see the library exists in https://repo1.maven.org/maven2/org/reflections/reflections/0.9.12. but not sure what syntax to use in the build.sbt file.
Jim Newton
@jimka2001
Seems to work if I replace %% with %.
Rohan Sircar
@rohan-sircar
%% appends the project scala version to the end of the dependency name
so for java libs it should be single %
(as that is a java lib)
Rob Norris
@tpolecat
@jimka2001 there is no way to iterate loaded classes as far as I know. The reflections library above will scan your classpath if it can, but this isn't possible in general.
"classpath" is only a meaningful idea for certain kinds of classloaders.
Jim Newton
@jimka2001
@tpolecat yes it seems reflections doesn't really work. The following prints [] without realizing that Class1 is a subclass of Abstract1 :-(
object sanityTest {
  def main(argv: Array[String]):Unit = {
    import genus._

    import org.reflections.Reflections
    val reflections = new Reflections("cl-robdd-scala")
    abstract class Abstract1
    trait Trait1
    class Class1 extends Abstract1 with Trait1
    println(reflections.getSubTypesOf(classOf[Abstract1]))
  }
}
Jim Newton
@jimka2001
although I wonder whether I'm doing something wrong, as at least getSubTypesOf should know that Abstract1 is a subtype of itself.
I wonder that the argument to the constructor new Reflections(...) is supposed to be. It seems to work (create an object) even if I give it the name of a non-existent project.

Interesting, when I use "" as the argument of the constructor, I get something more promising.

object sanityTest {
  def main(argv: Array[String]):Unit = {
    import genus._

    import org.reflections.Reflections
    val reflections = new Reflections("")
    abstract class Abstract1
    trait Trait1
    class Class1 extends Abstract1 with Trait1
    abstract class Class2 extends java.lang.Number

    println(reflections)
    println(reflections.getSubTypesOf(classOf[Abstract1]))
    println(reflections.getSubTypesOf(classOf[java.lang.Number]))
  }
}

This prints:

org.reflections.Reflections@229d10bd
[class rte.sanityTest$Class1$1]
[class rte.sanityTest$Class2$1]
kiti_Nomad
@Kiti-Nomad
scala3 is released, new features include ceylon's set theory type.
Dale Wijnand
@dwijnand
What's that? Can't find that working on Google.
Luis Miguel Mejía Suárez
@BalmungSan
@ImGrayMouser_twitter because Set is defined as generic for all types, and they exploit the fact that at runtime any value would have a equals and hashcode methods to implement it. Now, that implies that the Set will behave according to the underlying elements.
And in the case of Arrays that means that equality is based in having the same object (same memory address) rather than the same values.
Which makes a lot of sense, because that is the only sensible equals implementation for something that is mutable.
Now, the stdlib could have restricted Set to only work for types that have a sensible equals using a typeclass. But, that would have just made it weird to use and more limited, at the end the current equals of Array is, in fact, sensible and useful; just not in your case.
Rob Norris
@tpolecat
If you tried to use a TreeSet then it wouldn't typecheck (as you wish).
Geoffrey Knauth
@gknauth
I mentioned the recent release of Scala 3, and a coworker said Databricks has only recently started supporting Scala 2.12. Is that correct? I’m trying to figure out the timeline to being able to use Scala 3 with Databricks.
Luis Miguel Mejía Suárez
@BalmungSan
Disclaimer I have no relationship with them, nor with the compiler team. And I am just a random person in the Internet with some resentments about Spark. So do not take me too serious.
Seth Tisue
@SethTisue
@gknauth Spark has been on 2.12 for a long time. they're close to shipping 2.13 support: https://issues.apache.org/jira/browse/SPARK-25075 . and there are comments on the same ticket talking about the 3 situation
Luis Miguel Mejía Suárez
@BalmungSan
But I guess Spark won't support Scala 3 until 2 years. I hope I am wrong.
Geoffrey Knauth
@gknauth
Thanks @SethTisue
Seth Tisue
@SethTisue
2 years sounds like a reasonable guess
Geoffrey Knauth
@gknauth
Thanks also @BalmungSan , good to clear the pond of rocks before jumping in.
Khagay Nagdimov
@khagaydv01
Hello. I'm encountering an interesting situation. I have a method that is wrapped in a Try. That method has a sub-method that throws an exception but, the return value of that sub-method is a String. It seems that the exception gets thrown and the thread crashes even though the parent method is wrapped in a Try. Is that expected behavior? I would have thought the exception gets wrapped in a Failure.
Jim Newton
@jimka2001
Is there a better idiom for following? I.e., without interrupting the exception being thrown, take a different finally action based on whether the expression finished or aborted? I'm using a mutable variable.
      println("[ starting " + testName)
      var finished = false
      try{
        testFun
        finished = true
      }
      finally{
        if (finished)
          println("] finished " + testName)
        else
          println("] aborted" + testName)
      }
Seth Tisue
@SethTisue
@khagaydv01 what kind of exception is it? Try distinguishes fatal from nonfatal exceptions and only catches the nonfatal ones
Khagay Nagdimov
@khagaydv01
@SethTisue a custom exception that derived from RuntimeException
Jim Newton
@jimka2001
in this particular case it is a java.lang.OutOfMemoryError: Java heap space
keep in mind I don't want the exception tampered with. I still want it to fail, I just want to indicate that the test case finished successfully or that it aborted
Luis Miguel Mejía Suárez
@BalmungSan
@khagaydv01 can you create a MCVE in Scastie?
That should work.