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
saahm
@saahm
I was suggested src/main/resources and now src/test/resources
Do both work?
Luis Miguel Mejía Suárez
@BalmungSan
Yes
Is the same as src/main/scala VS src/test/scala
One is included in the final jar
The other is just for tests
saahm
@saahm
The part with the jar isnt too important for me as I'm just executing it from the sbt environment.
saahm
@saahm

I have moved the data to src/mainr/esources.
So even tho the path (I'm still printing it, and its the correct (absolute) path) is correct now, fromFile doesnt open the file properly it seems.
val arrayFile = Source.fromFile(path).getLines for example wont hold the iterator for the file.

maybe for some context: I read in the file through a functioncall that I define

    def readArrayFile(path: String) = {
      println(new java.io.File(path).getAbsolutePath)
      val arrayFile = Source.fromFile(path).getLines
      val caseArray = new Array(arrayFile.size)
      println(arrayFile.size)
      for(line <- arrayFile){
        println(line)
      }
    }

For now it will output the filepath (absolute) and the arrayFile.size is always 0. So it didnt open the file properly (it also prints out no lines)

Source.fromResource raises and error that it is not part of Source (which is weird, as it is as I'm reading the API now (https://scala-lang.org/api/3.1.0/scala/io/Source$.html#fromResource-e32)
I do import scala.io.Source
Luis Miguel Mejía Suárez
@BalmungSan
A resource is not a file.
Are you sure you are using an updated Scala version?
saahm
@saahm
Oh, indeed, I did not see that. I'm on Scala 2.11 it seems
Luis Miguel Mejía Suárez
@BalmungSan
Can you upgrade to 2.13?
Daniel de Oliveira Mantovani
@mantovani
I wish I could be using Scala 2.13.x but I need to maintain code running in Spark cluster from third-party vendor running Scala 2.11.x ...
Few customers use Spark with Scala 2.12.x
Dmitriy Kostyuchenko
@thedmitriyk
I’m sorry I keep asking for this all the time.
What is that one website where the functional programmer used machine learning to analyze all FP questions? And the answer is always traverse
Luis Miguel Mejía Suárez
@BalmungSan
Dmitriy Kostyuchenko
@thedmitriyk
Thank you!
I can’t believe that’s not in my history.
saahm
@saahm

@BalmungSan I'm not sure if I can update to 2.13 but I managed the following

    val fileStream = getClass.getResourceAsStream(path)
    val lines = Source.fromInputStream(fileStream).getLines

to open and successfully read the Files

But as soon as I do that inside a function it doesnt work(?!)
saahm
@saahm
Nevermind
saahm
@saahm
      val fileStream = getClass.getResourceAsStream(path)
      val lines = Source.fromInputStream(fileStream).getLines()
      println(lines.length)
      lines.foreach(println)
So when I print the length of the iterator, it doesnt print the lines one line after it anymore, does using .length change something with that Iterator?
Because when I comment out the print(lines.length) it prints the lines.
Francois GORET
@fgoret

Hello, looks like the export clause does not exports the default values of a function's parameters. Using Scala 3.1.1-RC1 on
scalastie :

class A(s: String):
  def greeting(name: String = s) = s"Hello $name"

class B:
  val a = A("You")
  export a.*

val b = B()

println(b.a.greeting())      // works
println(b.greeting("John"))  // works
println(b.greeting())        // nope !

Is it a known restriction ?

Guillaume Martres
@smarter
No, I'd say that's a bug.
Francois GORET
@fgoret
@smarter Ok, I will open an issue on github lampfl/dotty.
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