Discord is now Scala’s main chat platform. Please join us at https://discord.com/invite/scala
def fmap[B](f : A => B) :M[B] = ma.flatMap(a => pure(f(a)))
I guess the time to revive my old ("gamer") discord profile has come.
@BalmungSan
If you have gmail or protonmail, you can use a alias when you signup for an account ${user}@gmail.com => ${user}+${alias}@gmail.com
The aliases still get sent to you, but they have alias in the TO field so you can properly filter via domain
Some thing I wish I knew about 20 years ago for setting up spam filters.
ap
using fmap
it causes the loop. I guess that is because Monad trait is reference to the fmap
within Applicative
. However, why does @main def main = println(List(1).fmap(_ * 2))
refer to the Monad
version of instead of directly using the Functor
implementation?
Monad
)
@BalmungSan Hmm... So, the instance that will always be pass will be the monad instance? What if I have a generalized function that just needs a Functor
constraint, how will the compiler find that instance?
For example:
def someGeneralizedFunc [F[_]: Functor](fa: F[String]): F[Int] = fa.fmap(x => 3)
someGeneralizedFunc(List("yo")) // I don't think this will work with just a Monad instance for List
Monad
can form a Functor
map
in terms of flatMap
and pure
Monad[F] extends Functor[F]
, as such, it is a subtype.
Applicative
already extends Functor
?
map
on a tuple?[error] | Found: Object with PolyFunction {...}
[error] | Required: PolyFunction{apply: [t](x$1: t): Any}
summonForT[A].map(
[r] =>
(reader: r) =>
inline reader match {
case reader: ConfigReader[t] =>
val key = fieldMapping("field")
reader.isInstanceOf[ReadsMissingKeys] match {
case true => reader.from(objCur.atKeyOrUndefined(key))
case false => objCur.atKey(key).flatMap(reader.from(_))
}
}
)
where summonForT
is an inline method which returns a Tuple.Map[m.MirroredElemTypes, ConfigReader]
I can't figure out why this code wouldn't compile:
case class Wrapper[A <: Singleton](a: A)(using ValueOf[A])
def test[A <: Singleton](blabla: Wrapper[A]): Unit = ()
test(Wrapper("yo"))
and fail with a:
No singleton value available for A
where: A is a type variable with constraint >: ("yo" : String) and <: Singleton
Wrapper("yo")
then it works:case class Wrapper[A <: Singleton](a: A)(using ValueOf[A])
def test[A <: Singleton](blabla: Wrapper[A]): Unit = ()
val value = Wrapper("yo")
test(value)
Hi :wave: I have a question about quotes and splices. In scala2 I was able to create an Expr[CC]
for a case class CC(...)
which was equivalent to instantiating the class CC.apply(arguments:_*)
as
val symbol = weakTypeOf[CC].typeSymbol
val constructor = q"reify(${c.mirror.staticModule(symbol.fullName)}).tree"
q"Apply($constructor, List(..$arguments))"
The thing which I am struggling with is that in scala2 I could interpolate instances of Tree
into a quasiquote and reify
and use quotes without getting staging level errors.
Please, anyone has a quick hint on how to replicate the three lines of scala2 in scala3? 🙏🏻
"yo"
to be String
, not "yo"
.
A
is indeed a singleton
"yo"
(as manually specifying that type makes it work). But I do mean to recall there has been such a problem mentioned somewhere (some issue on the tracker?) where one had to store things in a val
and pass that val
to the method for it to type it correctly.
A
in Wrapper
is somehow being "altered" by test
, which makes summoning ValueOf[A]
fails. What seems to also work is moving the using
-clause to test
, so it obviously is a case of the test
-method making the parameter less specific.
A
within test
doesn't resolve to "yo"
, I guess it resolves to String & Singleton
instead.
ValueOf
for it.
Singleton
Please, anyone has a quick hint on how to replicate the three lines of scala2 in scala3? 🙏🏻
I will try to give a more specific example. I would like to have an Expr[CC]
which is equivalent to instantiating a new instance of CC
, yet generic.
case class CC(i:Int)
val expected = '{ new CC(1) }
Attempts to generalize that:
val ts = TypeRepr.of[CC] // or Type[CC] ...
val attempt1 = '{new ts(1)} // something as simple as this fails
val attempt2 = Apply(
Select.unique(New(Ident(TermRef(ts,"???"))),"<init>"),
List(Literal(IntConstant(1)))
).asExprOf[CC] // I have no idea how to instantiate this
List[Expr[_]]
)Type[CC]
)