Source.fromResourceraises 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)
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?
val fileStream = getClass.getResourceAsStream(path) val lines = Source.fromInputStream(fileStream).getLines() println(lines.length) lines.foreach(println)
print(lines.length)it prints the lines.
Hello, looks like the
export clause does not exports the default values of a function's parameters. Using Scala 3.1.1-RC1 on
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 ?
getLinesso you can load all the data in memory an being able to use it multiple times.
typeSignature, I get the following for
=> Int. I want to inspect using something like
in =:= typeOf[Int]. I'm a bit confused on what i should be doing?
List[List[Any]]where the inner list always has two elements of different types; use a
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".
I just want to learn the functional way of coding, Thank you for the information and for the example
No worries and welcome to the community!
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
| 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
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.