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
Luis Miguel Mejía Suárez
@BalmungSan
The only way for this to become easy is to code, and code, and code some more.
Sakitha
@Sakitha
ok, thanks
Luis Miguel Mejía Suárez
@BalmungSan
Finally, this chat is slowly dying.
If you can and want; I would recommend joining the discord server instead: https://discord.gg/7aUsmzyD
Sakitha
@Sakitha
will do.. really appreciate your time and efforts
Luis Miguel Mejía Suárez
@BalmungSan
You are welcome :)
Oliver Winks
@PaperPlaneSoftware
trait A { def hello: String }
trait B { def hello: String }

def test(x: A | B) = x.hello // error: value `hello` is not a member of A | B
surely this is incorrect
N.S. Cutler
@godenji
@smarter is it possible to combine Match Types with generic type argument(s) such that the application of the type match can occur solely based on type? (i.e. with no value present).
type Id = Int | Long | UUID

trait MappedTo[+T <: Id] extends Any:
  def value: T

type GetType[T <: MappedTo[_]] = T match
  case MappedTo[Int] => Int
  case MappedTo[Long] => Long
  case MappedTo[UUID] => UUID

class Extract[T <: MappedTo[_]](val map: T => GetType[T])

given extract[T <: MappedTo[_]]: Extract[T] = new Extract[T](_.value) // ERROR
Found: _$1.T
| Required: GetType[T²]
|
| where: T is a type in trait MappedTo with bounds <: Id
| T² is a type in given instance extract with bounds <: MappedTo[?]
|
|
| Note: a match type could not be fully reduced:
|
| trying to reduce GetType[T]
| failed since selector T
| does not match case MappedTo[Int] => Int
| and cannot be shown to be disjoint from it either.
| Therefore, reduction cannot advance to the remaining cases
|
| case MappedTo[Long] => Long
| case MappedTo[java.util.UUID] => java.util.UUID

So, in val map: T => GetType[T], T is unknown and therefore the match type fails.

I guess I'm looking for a lazy Match Type if that makes sense, or is even possible.

Use case is attempting to use Match Types as a means to replacing removed Abstract Type Projections in Scala 3.
Eric K Richardson
@ekrich
@godenji If it is not to inconvenient, most people have moved to Discord - https://discord.gg/scala
N.S. Cutler
@godenji
Most people, except for Guillaume :), thus the question placed here.
Eric K Richardson
@ekrich
Oh, I think contributors is better.
rnd4222
@rnd4222_gitlab
Is there something like shapeless Generic/LabelledGeneric but for trait methods / function arguments?
Artem Egorkine
@arteme
in scala 2.13 is it okay to generalize as def process[A, C[x] <: IterableOps[x, C, C[x]](coll: C[A]): C[A] when I want to map over a collection C[A] to get back a C[A]? Or is there a better way?
Seth Tisue
@SethTisue
4 replies
Todd O'Bryan
@toddobryan

I just found some interesting behavior in Scala 3.

infix case class ~[T1, T2](_1: T1, _2: T2)

def main(): Unit =
   val ab: Int ~ Int = ~(1, 3)
  println(ab)

results in value unary_~ is not a member of (Int, Int). In other words, ~(1, 3) is getting parsed as unary_~ plus Tuple2(1, 3) instead of function name ~ + arguments (1, 3). Is this a change in how Scala 3 parses, a known bug, or have I discovered something interesting?

~.apply(1, 3) seems to work as a workaround, but is a little annoying.
Todd O'Bryan
@toddobryan
I also tried to create an infix version using an extension method:
infix case class ~[T1, T2](_1: T1, _2: T2)

extension [T1](t1: T1)
  infix def ~[T2](t2: T2) = ~.apply(t1, t2)

@main
def main(): Unit =
  val ab: Int ~ Int = 1 ~ 3
  println(ab)
This resulted in ~ is already defined as object ~ in /path/to/the/scala/file
Ghost
@ghost~61ab4f6e6da03739848bd7e2
@toddobryan as per Eric's comment, most people have moved over to discord https://discord.gg/scala
Todd O'Bryan
@toddobryan
Oh. Thanks.
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...