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
@saahm iterators only have one use, if you call length on it, you just throw away all the data.
You can remeber that, or just do a toList after getLines so you can load all the data in memory an being able to use it multiple times.
Michael Thomas
@Michaelt293
I am writing a scala 2 macro at the moment and am trying to get the field types for case classes using WeakTypeTag. Using typeSignature, I get the following for Int field - => Int. I want to inspect using something like in =:= typeOf[Int]. I'm a bit confused on what i should be doing?
Michael Thomas
@Michaelt293
Actually, if I use returnType, I seem to get what I need.
Luis Miguel Mejía Suárez
@BalmungSan
Uhm, there was a question here a moment ago.
Two advises:
  1. Use proper types, rather than a List[List[Any]] where the inner list always has two elements of different types; use a List[(Int, A)]
  2. The Scaladoc is your friend: https://www.scala-lang.org/api/current/index.html
Hope you still manage to see this :)
Sakitha
@Sakitha
yeah, I'm here .. thought it was a dumb question to ask, is it bad to have a for loop that wouldn't yield a value but instead change a predefined array ?
Luis Miguel Mejía Suárez
@BalmungSan

@Sakitha

thought it was a dumb question to ask

There are no dumb questions, there are fools that don't ask.

Is it bad to have a for loop that wouldn't yield a value but instead change a predefined array?

Well, it depends on a lot of things, specially what is your definition of "bad".

What I can say is that, in general, idiomatic Scala prefers immutable solutions over mutable ones.
There are 2 reasons for that:
  1. Shared mutability can become problematic when you have concurrency.
  2. Immutable solutions powered by the stdlib rich operations are usually more maintainable than a mutable loop (although, this is somewhat subjective)
As such, if your mutation is contained in the scope of a single method then it is fine.
And if you use that mutation to either improve performance or make the code easier to maintain to your team then that is great.
However, what I personally think is that it is easier to be 100% consistent than 99%
Thus, if all the code base is immutable I would rather make each method immutable even if their contained mutability is fine just for the sake of consistency.
Sakitha
@Sakitha
I just want to learn the functional way of coding, Thank you for the information and for the example
Luis Miguel Mejía Suárez
@BalmungSan
And I would only break that rule if I have enough evidence that the immutable version is hurtful to the performance of the app and the mutable one fixes that.
Which, IME, has never been the case; but your mileage may change.

I just want to learn the functional way of coding, Thank you for the information and for the example

Sure!
No worries and welcome to the community!

Feel free to keep asking questions as you continue to practice.
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?