Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 02 23:58
    @SethTisue banned @fakubishes:nerdsin.space
  • Dec 15 2021 05:01
    som-snytt commented #12516
  • Dec 15 2021 04:38
    SethTisue edited #1312
  • Dec 15 2021 04:38
    SethTisue opened #2273
  • Dec 15 2021 04:31
    jackkoenig opened #12516
  • Dec 15 2021 04:29
    SethTisue edited #1312
  • Dec 15 2021 04:28
    SethTisue edited #1312
  • Dec 15 2021 04:27
    SethTisue labeled #9831
  • Dec 15 2021 04:27
    scala-jenkins milestoned #9831
  • Dec 15 2021 04:27
    SethTisue labeled #9831
  • Dec 15 2021 04:27
    SethTisue opened #9831
  • Dec 15 2021 03:35
    som-snytt commented #11339
  • Dec 15 2021 03:27
    som-snytt labeled #12494
  • Dec 15 2021 03:07
    SethTisue edited #1312
  • Dec 15 2021 03:07
    SethTisue edited #1312
  • Dec 15 2021 03:05
    SethTisue edited #1312
  • Dec 15 2021 03:05
    SethTisue edited #1312
  • Dec 15 2021 03:05
    SethTisue edited #1312
  • Dec 15 2021 02:58
    SethTisue edited #1312
  • Dec 15 2021 02:58
    SethTisue synchronize #1312
Thorarinn Sigurdsson
@thsig

Hello there! I just started poking around with Scala and sbt, but am running into some gnarly errors right out of the box that I'm finding hard to diagnose.

First, I installed sbt via Homebrew (I'm on OSX) and followed the instructions in this example project: https://github.com/tototoshi/sbt-hot-reload-example

At first, it worked like a charm. Then I came back to it a few minutes later, did another cd framework && sbt publishLocal && cd ../app && sbt run, and got the following error:

INFO: No global web.xml found
Dec 06, 2021 7:08:26 PM org.apache.tomcat.util.scan.StandardJarScanner processURLs
WARNING: Failed to scan [file:/Users/ths/.sbt/boot/scala-2.12.14/org.scala-sbt/sbt/1.5.5/scala-reflect.jar] from classloader hierarchy
java.io.IOException: java.lang.reflect.InvocationTargetException
    at org.apache.tomcat.util.compat.Jre9Compat.jarFileNewInstance(Jre9Compat.java:209)
    at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:65)
    at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:49)
    at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:383)
    at org.apache.tomcat.util.scan.StandardJarScanner.processURLs(StandardJarScanner.java:318)
    at org.apache.tomcat.util.scan.StandardJarScanner.doScanClassPath(StandardJarScanner.java

Like it's looking for a JAR but not finding it.

I tried uninstalling and reinstalling sbt, installing it via sdk instead, but to no avail.
Seth Tisue
@SethTisue
@thsig do I remember right that you already got help with this on Discord?
Eric K Richardson
@ekrich
@SethTisue Yes, he got some help over there and was welcomed and is all set for now.
bramvdbogaerde
@bram:vdb.network
[m]
Does anybody know where I can find documentation about "shadowing" of givens using import statements in Scala 3? I checked the implicit-resolution document but that does not seem very enlightening.
daymo
@daymo

Hey there, I'm having an odd problem with taking user input in the terminal. I'm using scala.io.StdIn.readLine() method to prompt the user for interaction but it doesn't work as expected. I can type something in and press ENTER but nothing happens afterwards. Looks like everything after the readLine() is not being called anymore.

I'm on Ubuntu 18.04 LTS using Java 11 and Scala 2 and 3. I also tried to google the problem but I couldn't find a solution yet. I was hoping that someone here had the same strange issue and might have a solution.

Luis Miguel Mejía Suárez
@BalmungSan
@daymo can you share a small code that reproduces the problem?
daymo
@daymo
@BalmungSan Of course, here is the simplest example. I suppose it's rather an Ubuntu/JVM problem than a Scala one but I wasn't able to find a solution yet. Some suggested it's a Java Compat problem, Jline thing etc but I tried all that and still no success... Is the bash broken?
import scala.io.StdIn.readLine

object ConsoleApp extends App {
  print("Enter your first name: ")
  val firstName = readLine()

  // This is never run. Why?
  print("Enter your last name: ")
  val lastName = readLine()

  println(s"Your name is $firstName $lastName")
}
Luis Miguel Mejía Suárez
@BalmungSan
@daymo sorry for the late response, how are you running this code?
Boon
@laiboonh

I have a multi project sbt as such

lazy val root = (project in file(".")).settings().aggregate(foo, bar).dependsOn(foo, bar)
// sub-project in the Foo subdirectory
lazy val foo = (project in file("Foo")).settings()
// sub-project in the Bar subdirectory
lazy val bar = (project in file("Bar")).settings()

I created a case class inside bar module simply

object Models {
  case class Example(s:String)
}

When i try to refer to it in root module

package com.example.root

import Models._

case class RootExample(example: Example)

I get

not found: object Models
not found: type Example

This is very puzzling. Why are classes in foo not visible in root even though i specified dependsOn in sbt

Luis Miguel Mejía Suárez
@BalmungSan
@laiboonh maybe because you are also aggregating them?
I haven't see the two used at the same time.
Anyways, you may want to ask in the #tooling channel of the Discord server: https://discord.gg/7aUsmzyD
Boon
@laiboonh
I figured out the behaviour. For it to be visible in a package. The object Models have to be in a package as well. By moving it to a package in bar module makes it visible. Very odd behaviour i feel
Luis Miguel Mejía Suárez
@BalmungSan

Very odd behaviour i feel

Why?

How did you expect it to be visible if it was not in the same package?
daymo
@daymo
@BalmungSan I run the code with Mill v0.9.10
Luis Miguel Mejía Suárez
@BalmungSan
@daymo maybe that is the problem? I just tried with the plain compiler and it works.
Try putting that in a file called ConsoleApp.scala in a folder alone.
And then run:
scalac ConsoleApp.scala
scala ConsoleApp
And let me know if it runs as expected.
daymo
@daymo
@BalmungSan Hmm, that actually works as it is supposed to and that narrows the problem down even more. Any idea why running it with Mill would make such a huge difference? I will consult the Mill channel anyway...
Luis Miguel Mejía Suárez
@BalmungSan
Yeah all I know about Mil is its name and the name of its creator lol.
So yeah, the best is to consult there.
:) :wave:
daymo
@daymo
@BalmungSan No worries and thank you for your help.
Derek Willingham
@DirtySoc
I am completely new to Scala and SBT. I am trying to setup a built.sbt file so that sbt publish will push the maven style project to one remote repository if the build agent is a Jenkins and a different remote repository if the build agent is a GitHub action. I've spent about 6 hours on this today and I don't feel like I really understand much more about SBT and how to modify the behavior of sbt publish. Does anyone here have good example sbt projects or suggestions for learning more in regard to what I am trying to do?
Also are Seq() and Some() special sbt functions? I see those throughout the build.sbt files I have been looking at and I don't really know what they do.
Luis Miguel Mejía Suárez
@BalmungSan
So you don't even know basic Scala and yet you want to do a custom publishing which seem very complex (if even possible) to do...
I think you would need more help.
Anyways, you may want to ask in the #tooling channel of the discord server.
Luis Miguel Mejía Suárez
@BalmungSan
BTW according to the docs you should be able to do something like this:
publishTo := { if (isJenkins) Some(...) else Some(...) }
Now, not sure how are you going to check which is the runner.
2 replies
Alex
@unthingable
Question about transparent inlining: I have a value x and a deserialized class object o fetched from a database. The fetch is polymorphic in that the object can be one of two distinct types, I don't know which one ahead of time. o has a method .foo(x) that expects a specific type of a value, depending on the type of o, and for that it has a safeguard method transparent inline cast[A](a: A) = inline erasedValue[A] match {...}. The question: given that the object is only known at runtime, is inlining going to do any good, or am I grossly misunderstanding it?
Luis Miguel Mejía Suárez
@BalmungSan
@DirtySoc so it seems you could do this:
publishTo := {
  scala.util.Properties
    .envOrNone(name = "GithubRunnerEnvVar")
    .fold(ifEmpty = Some(jenkinsRepository)) { _ =>
      Some(githubActionsRepository)
    }
southrivers
@southrivers
import java.lang.{Byte => JByte}
any one know what does this mean?
ml10
@ml10
I’m not sure ther precise name, but I’ve seen it referred to as a “rename import” or “import rename”. https://alvinalexander.com/scala/how-to-rename-members-import-scala-classes-methods-functions/
southrivers
@southrivers
thanks very much
megri
@megri
Is there a way to build a Map[K, V] by using the builders pattern, where I need to update a map key with a new value as I go along?
Basically what I want is items.foreach(item => mapBuilder.updateOrSet(item.key, set = 0, update = n => n + 1))
Luis Miguel Mejía Suárez
@BalmungSan
@megri you can do this:
items.foldLeft(Map.empty[K, V]) {
  case (acc, item) =>
    acc.updatedWith(key = item.key) {
      case Some(n) => Some(n + 1)
      case None => Some(0)
    }
}
No need to mutate.
Also, this seems it is doing some kind of word-count or something similar, right?
You should be able to just:
items.groupMapReduce(_.key)(_ => 1)(_ + _)
Bonus: If you have cats in scope, you can just do:
items.foldMap(item => Map(item.key -> 1))
megri
@megri
@BalmungSan Thanks, but I wanted a builder version specifically. I'm just coding for fun and part of that is exploring the standard library. Not having a way to build a map stumped me and I figured I had to be missing something, but maybe it's just an omission..
I think the underlying issue is that all collection builders return a base trait Builder, which has no specific knowledge of maps for instance. So when you do Map.newBuilder[String, Int] you end up with a Builder[(String, Int), Map[String, Int]], which has no knowledge of maps specifically.
Luis Miguel Mejía Suárez
@BalmungSan
@megri Well if you add a new key-value pair whose key was already present it overwrite the previous key.