All Questions
832
questions
1
vote
1
answer
39
views
Scala 2 to Scala 3: Instantiating a trait no longer recognises new methods
The following code compiles and runs in Scala 2:
trait SomeTrait {
val myName: String
}
class SomeClass() extends SomeTrait {
override val myName: String = "Billy Banana"
}
val ...
0
votes
1
answer
41
views
Suggestion dealing with multiple traits and profile combinations in Scala
I have a situation where I have several traits with each trait containing a set of methods. I have now to expose these functionalities to the external world through profiles. For example., a basic ...
0
votes
1
answer
120
views
Use default value for Scala trait or abstract class in a case class that implements it
Is there a way to get a version of this code to use the default value defined in the trait?
trait A { // alternately `abstract class A`
def x: String
def y: Int = 1
}
final case class B(x: ...
0
votes
1
answer
57
views
Scala Issue with Mixin Traits and Conflicting Members
I have the following setup for ms Scala test where I have a trait that looks like this:
trait CPODBTestContainerSpec extends AnyFlatSpecLike with TestContainerForAll {
....
....
}
abstract class ...
0
votes
1
answer
59
views
What is the issue with below Scala code snippet?
I am facing issue with the code snippet, it says there is a conflict for func function in traits A and B
//Tried the below code:
trait A{
def func(): Unit = {
println("Inside trait A")
...
0
votes
1
answer
47
views
How to let the implementor of a trait define the context parameter type
I would like to define a trait in a library, and where the type of the contextual parameter is defined by the caller user of the library. For example, it would look something like:
////////////////////...
1
vote
1
answer
83
views
Is there any way to rewrite the below code using Scala value class or other concept?
I need to write two functions to get the output format and the output index for file conversion. As part of this, I wrote a TransformSettings class for these methods and set the default value. And in ...
0
votes
2
answers
109
views
How to restrict generic trait in subtype
I have a trait Mutable[T] that describes objects that can be mutated to T using a Mutation object:
trait Mutable[T] {
def mutate(mutation: Mutation): T
}
class Mutation {
def perform[T <: ...
0
votes
1
answer
110
views
Scala Ordering case classes implementing a trait in a list
I have case classes that extend a trait Token and a function that returns a list of instances created using the case class apply method with appropriate parameters.
The trait defines a property name ...
0
votes
1
answer
402
views
Can I extend an existing class (e.g. String) with a custom trait in Scala?
Consider the simple trait TypeName
trait TypeName {
def typeName(): String
}
For a custom class, it is clear how I might specify my implementation for the typeName method.
class Point(val x: Int, ...
0
votes
1
answer
176
views
How to collect field values from case classes in scala
I've got various case classes with different fields inherit some trait. All are mixed in a List. What is the way to collect (or group by) specific field's values?
sealed trait Template
object ...
0
votes
3
answers
156
views
Can Scala Companion Object Traits call a constructor of the class?
I'm trying to solve a problem that may not be possible in Scala.
I want to have a Trait to solve default constructors
trait Builder[T <: Buildable] {
def build(code: String): T = new T(code)
...
1
vote
1
answer
146
views
Remove Case Class Definition in asJson output from Circe
Consider:
import io.circe.generic.auto._, io.circe.syntax._
sealed trait Data
case class Failed(foo: String, bar: String) extends Data
case class Success(foo1:String, bar1:String) extends Data
case ...
1
vote
2
answers
242
views
Use one recursive case class constructor in two sealed traits
I am defining few ADTs representing logic formulas. They all use i.e. And constructor, but then differ in what other constructors they use. I'd like to reuse case class definitions with a hope that I ...
0
votes
1
answer
296
views
How to obtain a Trait/Class from a string with its name
I have multiple hierarchy of Scala traits that can compose an object in many ways. Example:
trait MainA { someDefs... }
trait SubA1 extends MainA { someDefs... }
trait SubA2 extends MainA { someDefs......