Questions tagged [implicit]

An implicit in Scala is a function applied or a parameter provided without explicitly appearing in the source code.

implicit
Filter by
Sorted by
Tagged with
0 votes
1 answer
54 views

ZIO Quill: Can't find implicit SchemaMeta for type models.Pet

I'm currently working on a pet store application using ZIO and Quill. As part of my learning process, I've set up a local H2 database and configured it to store pet information. However, I'm ...
Penchala Yegu's user avatar
2 votes
2 answers
66 views

How to define a "fallback" implicit?

Consider a tapir.Codec object (this is how I encountered this problem, but I don't think it has much to do with tapir specifically, it is just about implicit resolution priority in general), it has a ...
Dima's user avatar
  • 40.1k
0 votes
1 answer
81 views

In Scala 2/3, why can't unboxing or view bounds be chained (as in OCaml), and how to fix/circumvent it?

Considering the following example, derived from the official manual of Scala 3 on Context Abstractions: https://docs.scala-lang.org/scala3/guides/migration/incompat-contextual-abstractions.html#view-...
tribbloid's user avatar
  • 3,898
1 vote
1 answer
60 views
+100

How to test fastparse parsers in a separate class?

I'm writing a parser, something like, object MyParser: def int[$: P]: P[Int] = digit.rep(1).!.map(s => s.toInt) def digit[$: P]: P[Unit] = CharIn("0-9") Now I'd like to test this in ...
Todd O'Bryan's user avatar
  • 2,186
0 votes
0 answers
51 views

Scanamo Paginated Query Issues

Need example of a method to create paginated query on dynamoDb using scala's, Scanamo library I am trying to create to create a method which performs paginated queries on dynamodb table using a query ...
zeus's user avatar
  • 1
0 votes
0 answers
61 views

All partial unification algorithms failed on implicit conversion from functions - How to improve in Scala?

Here is a simple example: object UnificationOnConversionFromFn { trait :=>[I, R] implicit def fromVanilla[I, R]( vanilla: I => R ): I :=> R = ??? // fail implicit def ...
tribbloid's user avatar
  • 3,898
1 vote
1 answer
96 views

Implicit resolution failure when multiple instances present, despite having different types

My goal is to implement a Schema[T] (from scala-jsonschema) and Writes[T] (from play-json) for a handful of T classes whose companions I can't modify. My sub-goal is to define them close together to ...
Dylan's user avatar
  • 13.7k
2 votes
0 answers
34 views

Extensions methods using implicits do not compile with Scala 3

Following code compiles fine with Scala 2.13.12, but not with Scala 3.3.1: import scala.language.implicitConversions object Types { trait Vector3f implicit class Vector3fOps(v: Vector3f) { ...
Suma's user avatar
  • 33.9k
2 votes
0 answers
50 views

Scala 3 given/implicit resolution doesn't work as expected

I'm working on the Chapter 11 Case Study: CRDTs from the excellent book "Scala with Cats". The code in the book is written using Scala 2, but I've modified it for Scala 3, specifically 3.3.1....
Abhijit Sarkar's user avatar
1 vote
1 answer
36 views

Recursive value needs type error in Scala 3 implicit parameter

I'm trying to compile the following code in Scala 3 (worked on Scala 2.13): import scala.concurrent.duration._ @main def main(): Unit = { case class AAA(d: FiniteDuration) val duration1 = 5....
galbarm's user avatar
  • 2,523
1 vote
2 answers
68 views

c# Implicitly typed arrays behind the scenes

Can someone explain how the compiler proceeds here to find the "common" type (double). I assume the IConvertible plays a role here? private static void Main(string[] args) { var nrColl = ...
McFly's user avatar
  • 25
1 vote
1 answer
64 views

HList Ops - how are type classes constracted?

Can someone explain why this code compiles and works like a charm: val a = true :: Some(5) :: true :: HNil a.select[Some[Int]] // Some(5) but this one fails: def foo[HL ...
Oskar Furmańczuk's user avatar
0 votes
0 answers
23 views

Implicit equation plotting

I’m not a python expert, just a beginner, I would like to know how I could code and plot the equation shown here by using the implicit equation option??. This is my attempt but not sure how to plot it....
Cesarengineer's user avatar
0 votes
0 answers
50 views

It is possible to provider some default given contextual for class method?

Suppose I have defined a class Test: import scala.collection.{IterableFactory, Factory} class Test: def p1[C[_]](xs: Int*)(using f: Factory[Int, C[Int]]): C[Int] = f.fromSpecific(xs) def p2[C[...
esse's user avatar
  • 1,529
0 votes
2 answers
72 views

implicit wait in selenium

I am very confused about how to use implicit wait in selenium driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(4, TimeUnit.SECONDS); I saw ...
user3559982's user avatar
1 vote
1 answer
120 views

How to share url from android app with image preview

I want to create a share sheet just like the share exist in google store , as you can see here is google store sample currently I am using this code : ShareCompat.IntentBuilder(context) ....
Somaia Damlakhi's user avatar
1 vote
1 answer
133 views

Adjusting axis’ ticks in plotting with SymPy

Here is the problem: I have two implicit functions F and G. I am trying to find a way to plot them using SymPy. My question is, how to adjust ticks on x- and y-axis, so I can see a crossing point of ...
Alena's user avatar
  • 15
2 votes
1 answer
28 views

Generic type BoundedComponent struct

I want to do a struct for boundedElements like number that has a max and min value. However I'm stuck on how to do this. Here is an example of a property. The setfield method is just a method to set a ...
LaLoutreCouillue's user avatar
0 votes
0 answers
37 views

Scala - Trying to wrap occurrences of booleans using implicits

I'm new to implicits in scala and am sure there is a way to do this but have tried everything I can think of. I have a trait: trait WrappedDataframe[T] extends Rep[DataFrame] def apply[S](colName: ...
B-Brennan's user avatar
  • 133
0 votes
2 answers
118 views

how to use implicit intent in android

In my application, I created two activities. In activity1, I created a button, set event: activity2, I created, and write in manifest: when i click to the button in activity1, error was throw: Why? ...
Thanh Tùng's user avatar
1 vote
2 answers
74 views

Question about implicit class argument in Java method reference

In Java, the class portion of a method reference can become the first argument of the function. I've seen lots of examples in working code. But I wondered where in the Java Language Specification this ...
cha's user avatar
  • 207
0 votes
0 answers
50 views

Use default implicit and an overloaded function

Here is what I am trying to achieve: class SomeTest { ... verify(foo).bar(any) verify(foo, times(2)).baz(any) .. inOrder(foo) { implicit order => verify(foo).bar(any) verify(...
Dima's user avatar
  • 40.1k
3 votes
2 answers
164 views

How to properly use collection factories in scala 2.13?

Something like this: implicit class PairOps[A, B, C[X] <: Iterable[X]](val c: C[(A,B)]) extends AnyVal { def swap = c.map { case (a, b) => (b, a) } } Kinda works ... except that val foo: ...
Dima's user avatar
  • 40.1k
-1 votes
1 answer
71 views

Implicitplot with three colors in Maple

I am using implicitplot in Maple using this command: implicitplot(diffr, 0. .. 1, 0. .. 1.0, filledregions = true, coloring = [cyan, yellow]); So, when diffr<0 and diffr>0, I received a diagram ...
Reza Farahani's user avatar
2 votes
1 answer
67 views

Should I explicitly implement getName(), getAddress(), and setAddress() in my Kotlin code based on the UML?

I have implemented the following UML in Kotlin, and I am now considering whether I should explicitly implement the methods getName(), getAddress(), and setAddress() in my code, as they are mentioned ...
Ali Dehkhodaei's user avatar
1 vote
1 answer
64 views

In Scala 3, is it possible to summon implicits based on refined type?

Considering the following example: { trait Gen { type S type Ext } type GenAux[_S] = Gen { type S = _S } trait Gen_Fallback1 { given [_S]: GenAux[...
tribbloid's user avatar
  • 3,898
1 vote
2 answers
363 views

Could not find implicit value for parameter F: cats.Applicative[F] with Sync and Temporal

Basically, I just want to add a sleep somewhere, but I don't understand how to provide the implicit Applicative needed. I'm using cats effect 3.5. It's totally new to me. I have been using ZIO for 2 ...
Terry BRUNIER's user avatar
0 votes
1 answer
158 views

why std::make_unique<A>(*this) could call an implicitly-declared copy-constructor of A

The source question is from Usage of this* in make_unique The code is below, and the best answer says: In clone(), *this is an lvalue-reference to A, so you are constructing a A from an (lvalue-...
wssbygone's user avatar
0 votes
0 answers
39 views

Idk where I supposedly declared my function as a different type (C) [duplicate]

Well I got this issue and I don't get why? If someone could explain I'm just trying to learn C lmao I don't even have a clue of where I'm supposed to let it implicitly declare this function as ...
Erwan Maigne Montamat's user avatar
1 vote
1 answer
47 views

Creating syntactic sugar for a scala argument to give the illusion of a different type

I am creating a library and am exposing a class called A that has in it defined a function func(f: SomeType => A). It is imperative that func is called with the following syntax: val x = new A() ...
B-Brennan's user avatar
  • 133
0 votes
0 answers
91 views

Folding a tuple in Scala 3

Working with ZIO and Scala 3, I want to create a utility function productElementsLayer that for a given type A <: Product produces a value of type ZLayer[A, Nothing, (E1, ..., EN) where (E1, ..., ...
Markus Appel's user avatar
  • 3,208
2 votes
2 answers
2k views

Playwright clicks element (drop down) before it is ready resulting in the drop down not opening

I have a product page containing a product with quantity options. There is a drop down to select the quantities. I want to click this to open it and select an option. The steps are simple: Load page ...
James M's user avatar
  • 31
19 votes
4 answers
791 views

Why in C# an explicit decimal => long conversion operator is called implicitly, losing precision? [duplicate]

The following C# program silently and implicitly calls an explicit decimal-to-long conversion operator, losing precision. I don't understand why this happens. As far as I understand, in C# explicit ...
kaalus's user avatar
  • 4,495
0 votes
0 answers
61 views

Scala: Type Mismatch error when passing argument based on the same type

I have a basic scala issue: I defined a custom function to add to Dataset[Row] that lets me create my own WrappedDataset and used an implicit function to achieve that: class CustomFunctions(dataset: ...
B-Brennan's user avatar
  • 133
0 votes
2 answers
71 views

could not find implicit value for evidence parameter of type cats.MonadThrow[sttp.client3.Identity]

I'm considering using stac4s as a STAC client in our Scala project but boy, is it giving me a hard time. The use of cats, monads and all that fancy stuff is very daunting and there's no documentation ...
Bossie's user avatar
  • 3,592
0 votes
1 answer
336 views

Converting case class object to json string using spray json

I am new to scala and I need to convert a case class object to a json string using spray json. The case class look as below: case class DriverDetails(userId : String, names : Option[List[String]], ...
bugdebug's user avatar
0 votes
1 answer
52 views

Why can't the compiler chain conversions?

Let T1, T2, T3 be three types. We also define two given instances of the Conversion class so that the compiler can go from T1 to T2 and from T2 to T3. The following code then compiles fine: type T1 ...
t9dupuy's user avatar
  • 360
0 votes
1 answer
49 views

Implicit conversion differencies

The following works: case class Fraction(d: Int, n: Int) { def *(other: Fraction) = Fraction(d * other.d, n * other.n) } implicit val int2fraction: Int => Fraction = { x => Fraction(x, 1) } ...
Sergey Bushmanov's user avatar
0 votes
1 answer
146 views

No implicit Ordering defined for ord

I want to define a collection class and require its element being Ordered Considering the code below: class MyCollection[K: Ordered[K]] { def func(seq: Seq[K]): Unit = { seq.sorted } } The ...
Ziqi Liu's user avatar
  • 3,011
2 votes
2 answers
362 views

Using Postgres enum with Quill

I'm trying to use a Scala 2 enum with Quill, like so: import io.getquill.MappedEncoding object MyEnumType extends Enumeration { type MyEnumType = Value val ONE, TWO, THREE = Value implicit ...
daharon's user avatar
  • 2,000
0 votes
1 answer
130 views

How import spark.sqlContext.implicits._ works in scala?

I'm new in Scala Here's what I'm trying to understand This code snippet gives me RDD[Int], not give option to use toDF var input = spark.sparkContext.parallelize(List(1,2,3,4,5,6,7,8,9)) But when I ...
Javastudent's user avatar
0 votes
1 answer
263 views

Doobie cannot find or construct a Read instance for Type of case class with Timestamp

Given a case class representation of a data row with a java.sql.Timestamp: case class ExampleRow(id: String, ts: Timestamp) And query expecting an ExampleRow: import doobie._ import doobie....
Ramón J Romero y Vigil's user avatar
4 votes
2 answers
72 views

Proving that a match type resolves to a specific concrete type

I am trying to create an implementation of a trait that uses a match type, where the right-hand-side of that match type is known in advance. However, I can't seem to get the compiler to accept my &...
fehrvuerh93's user avatar
0 votes
2 answers
45 views

Implicit declaration of function // Problem with a createString function

Hey Guys i need your help. I am learning for my C-exam in two days. For that i had written a little code for a simple list. My Problem is that i get every time the same error: "implicit ...
Niklas's user avatar
  • 1
1 vote
1 answer
65 views

Insertion into scylladb table using phantom library in scala not working

I'm new to ScyllaDB, and trying to perform CRUD operations using phantom library in scala. First I've made 3-node cluster and its running fine. Datacenter: DC1 =============== Status=Up/Down |/ State=...
Zaryab Ali's user avatar
0 votes
1 answer
105 views

Parametric polymorphism issue with spark implicits, value toDF is not a member of Seq[T]

This is on scala 2.12.10 and spark 2.4.8. I am trying to define a trait as follows with a method that can convert an array of some case class to be converted to a dataframe. The type parameter is ...
Ken Myers's user avatar
  • 596
1 vote
1 answer
812 views

How to add extension method to a singleton object in scala 2?

I've stumbled upon this thread and there @prolativ provided some fancy scala 3 syntax for creating extension methods for objects extension (int: Int.type) def unapply(s: String): Option[Int] = s....
Killjoyer's user avatar
2 votes
1 answer
236 views

"Deferred inline method `foo` in trait `Foo` cannot be invoked": Pairs

I was just experimenting with the behavior of givens and inline in Scala 3.2.2, and ran into the following example: trait Max[X]: inline def max(a: X, b: X): X inline given maxForDoubles: Max[...
Andrey Tyukin's user avatar
5 votes
2 answers
438 views

How to summon a `given` member?

Suppose that I have some typeclass trait FooBar[X] and an instance of FooBar[Int]: given intIsFooBar: FooBar[Int] = new FooBar {} Now, suppose that I have an interface Intf that has some member type ...
Andrey Tyukin's user avatar
1 vote
1 answer
209 views

Type negation in Scala 3

Is it possible to implement fail proof Not[A] type in Scala 3? Here is a question asked some years ago: how-can-i-have-a-negation-type-in-scala. Unfortunately, a solution based on 'not given A <:&...
Turin's user avatar
  • 2,210

1
2 3 4 5
36