Discord is now Scala’s main chat platform. Please join us at https://discord.com/invite/scala
import
statements in Scala 3? I checked the implicit-resolution
document but that does not seem very enlightening.
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.
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")
}
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
#tooling
channel of the Discord server: https://discord.gg/7aUsmzyD
ConsoleApp.scala
in a folder alone.
scalac ConsoleApp.scala
scala ConsoleApp
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?
#tooling
channel of the discord server.
publishTo := { if (isJenkins) Some(...) else Some(...) }
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?
items.foreach(item => mapBuilder.updateOrSet(item.key, set = 0, update = n => n + 1))
items.groupMapReduce(_.key)(_ => 1)(_ + _)
items.foldMap(item => Map(item.key -> 1))
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.
MapBuilder
is just a mutable map that also has a mutable version of the method I explained above,
Builders
are intended for the stdlib itself, not really for users.
Map
with the method you want.