All Questions
1,644
questions
0
votes
1
answer
98
views
EitherT with Scala type alias
Try to use type alias with EitherT get compilation error
type FuEiErr[T] = Future[Either[Error, T]]
type FuEiErrInt = Future[Either[Error, Int]]
case class Error(msg: String)
def fA(x:Int): FuEiErr[...
0
votes
0
answers
43
views
Scala: Type error not detected in "contains" method
I have this test code:
object Main:
trait X0
class X1(name: String) extends X0
class X2(name: String) extends X1(name)
{
val seq = Seq[X1]()
seq.contains(3.1415926) //compiles
...
3
votes
1
answer
125
views
What is the difference between the types Null and Null & T where T <: AnyRef?
Look at the following method
def toOption[T <: AnyRef](value: T | Null): Option[T] =
value match {
case null => None
case content: T => Some(content)
}
If you ...
0
votes
1
answer
50
views
Scala type mismatch error involving generics and refined types
The following is a simplified version of a type-mismatch error I'm trying to solve:
trait Foo[A] {
type B
val b: B
}
trait Bar[T, R[_]] {
val r: R[T]
}
object TypeMismatch extends App {
def ...
0
votes
0
answers
47
views
Prefix type operators in Scala?
Scala allows writing infix operators for types, just as for expressions:
type ->[P,Q] = P => Q
Making X -> Y equivalent to writing ->[X,Y].
I would like to have a unary prefix operator, ...
1
vote
2
answers
61
views
Anonymous subclasses with extra methods -- scala2 vs. scala3
The following code works as (I) expect in scala2 but generates a compile-time error in scala3. I tried to find an explanation in Programming in Scala, Fifth Edition and the web but failed. Any ...
2
votes
1
answer
133
views
Scala 3 generic tuples: type bound & converting to Seq
I have two problems, which I think are related.
I want to have a type for tuples, of which all elements of the tuple are at least an Animal, in Scala 3.3.1. I came up with the following:
// In ...
0
votes
0
answers
32
views
In Scala 3, how can I write a method that returns some sort of Tuple depending on arguments?
I'm trying to write a method that combines higher types into new higher types using tuples. Say I have a type Foo[X], then I want something like:
trait Foo[X]:
def +(y: Foo[Y]) = <tuplify X and Y&...
1
vote
1
answer
57
views
Generic Numeric range function in Scala
I have two functions in scala that do exactly the same like this:
private def getIntRange(minLimit: Int, maxLimit: Int, step: Int): Something = {
(minLimit to maxLimit by step)
.map(_....
0
votes
0
answers
39
views
Having trouble using class as a key within Scala map. Any help appreciated
Beginner here and I've been having some difficulty getting one of my maps to work within Scala. My nested map symmetryTable contains keys of the type Shape which is class that I have implemented. ...
1
vote
1
answer
77
views
Get key and value types of scala map
If I have a complicated map type, like
type MyMap = Map[(String, String), List[Map[String, Int]]]
is there a way to do something like Map.Key to get the type of the key (here, (String, String))?
I ...
2
votes
1
answer
63
views
Scala: Verify Unique Type Existence At Compile Time
I have the following:
sealed trait Tag
case object MyTag1 extends Tag
case object MyTag2 extends Tag
sealed trait Error[T <: Tag]
// error implementations...
I'd like for two Error ...
1
vote
1
answer
49
views
Implement function which output type is depend on input type
Let imagine I have the following traits/classes hierarchy ( scala 2.13 )
trait In
trait Out
case class In1() extends In
case class In2() extends In
case class Out1() extends Out
case class Out11() ...
0
votes
3
answers
64
views
lists contain few types Scala
I am relatively new to Scala and I'm currently working on a function that will process a list containing both Strings and Integers.
My desired functionality is as follows:
If the list item is a String,...
3
votes
1
answer
68
views
Unable to use .to() operator on Long data type
The question is:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143?
I have written a code for it but it gives an error.The code is written in ...