Questions tagged [implicit]
An implicit in Scala is a function applied or a parameter provided without explicitly appearing in the source code.
implicit
2,010
questions
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 ...
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 ...
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 ...
53
votes
0
answers
1k
views
Materialize the Value for a Type that has One Inhabitant
Thanks to @MilesSabin's answer I can write a type level Fibonacci sequence:
sealed trait Digit
case object Zero extends Digit
case object One extends Digit
sealed trait Dense { type N <: Dense }
...
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 ...
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-...
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 ...
1
vote
2
answers
111
views
Contextbound "Temporal" causes: "Cannot resolve symbol flatMap"
I have something like
def test[F[_]: Sync: Console](counter: Int): F[Unit] =
for {
_ <- if(counter % 10000 == 0) Console[F].println(s"counter: ${counter}") else Sync[F].unit
_ &...
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 ...
2
votes
0
answers
864
views
implicit instantiation of undefined template 'std::function::__1::void(int,int)
#include <QApplication>
#include <unordered_map>
#include <memory>
#include <QDebug>
#include <functional>
template<typename T,typename ...args>
class TestClassA
{
...
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 ...
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) {
...
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....
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....
17
votes
5
answers
20k
views
Need explanation difference between json and dict in Python
I am just curious to understand JSON and Dict in Python more deeply.
I have a JSON response from a server like this:
`{"city":"Mississauga","country":"Canada","countryCode":"CA"}`
And I want to ...
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 = ...
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 ...
12
votes
4
answers
1k
views
Are implicit operators and TypeConverters equivalent?
It seems to me its very easy to implement an implicit operator versus a TypeConverter, so I'm assuming they aren't equivalent because of the prevalence of TypeConverters in the framework (see anything ...
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 ...
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....
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[...
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)
....
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 ...
1
vote
2
answers
1k
views
Why are implicit conversion deprecated in scala?
Taken from "Scala with cats" (page 18):
Implicit Conversions
When you create a type class instance constructor using an implicit def, be sure to mark the parameters to the method as ...
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: ...
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 ...
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
...
22
votes
5
answers
12k
views
popen implicitly declared even though #include <stdio.h> is added
This is tiny snippet of my code.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/...
22
votes
3
answers
29k
views
How does SQL Server decide format for implicit datetime conversion?
declare @str_datetime varchar(50)
set @str_datetime='30-04-2012 19:01:45' -- 30th April 2012
declare @dt_datetime datetime
select @dt_datetime=@str_datetime
This is giving following error:
Msg ...
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? ...
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 ...
0
votes
1
answer
282
views
ScalaTest : inject implicit variable
I am from Java background and I am trying to write UnitTests using Scala.
My class is as follows :
import com.softwaremill.sttp.{HttpURLConnectionBackend, Uri, sttp}
class MyClient(endpoint: String,...
83
votes
9
answers
56k
views
explicit and implicit c#
I'm new to C# and learning new words. I find it difficult to understand what's the meaning of these two words when it comes to programming c#.
I looked in the dictionary for the meaning and here's ...
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(...
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: ...
-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 ...
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 ...
0
votes
1
answer
104
views
Scala type bound on implemented function
I have a generic class that looks like:
class GenericClass[T <: AnyRef] {
def getHash(obj: T): String = obj.toString
}
As you can see, type T needs to have implemented the toString function in ...
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[...
0
votes
1
answer
181
views
How to write an implicit Numeric for a tuple
I have a scenario where I would like to call sum on a sequence of (Double, Double) tuples.
Ideally I would like to do something like the following:
implicit def toTupleNumeric[T](num: Numeric[T]) = ...
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 ...
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-...
3
votes
2
answers
8k
views
The method implicitlyWait(long, TimeUnit) from the type WebDriver.Timeouts is deprecated what is that Mean really?
please resolve issue , please update the same
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(());
driver.get("https://accounts.google.com/signin");
...
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 ...
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, ..., ...
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()
...
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 ...
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 ...
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: ...
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]], ...