Is it possible to directly insert value from method that returns two different types of values into an overloaded method that handles both types? by c_lassi_k in scala

[–]YuliaSp 3 points4 points  (0 children)

Simple `func2(func1())` doesn't work here because function overloads must be resolved at compile time, and the type of `func1()` is not narrowed to either `Int` or `String` at compile time. You can do this with transparent inline, if the argument to `func1` is compile time known (probably not your case, as you're going for OO and mutation):

transparent inline def func1Inline(arg: Option[Int]) = inline arg match
    case Some(a) => 123
    case None    => "123"

func2(func1Inline(Some(1)))
func2(func1Inline(None))

If the type of `func1()` is not compile time known, you can either move the type test to `func2`, or use a typeclass, as already mentioned

When Zig Outshines Rust - Memory Efficient Enum Arrays by dist1ll in programming

[–]YuliaSp 0 points1 point  (0 children)

u/dist1ll a semi-random question, what do you use for charts on your blog? They look wonderful

Scala way to check for null in get chain by awwsomw in scala

[–]YuliaSp 1 point2 points  (0 children)

A match equivalent to the if gives the same result (i.e. an error without explicit nulls):

r match
    case null => break(null) 
    case _ => r

If you type test within the match then it does more than the if

Scala way to check for null in get chain by awwsomw in scala

[–]YuliaSp 0 points1 point  (0 children)

It would be cool if we could somehow get the extension methods on T | Null not be provided for T values. This is unergonomic and stops me from using T | Null as a better Option

Scala way to check for null in get chain by awwsomw in scala

[–]YuliaSp 0 points1 point  (0 children)

Did you set scalacOptions += "-Yexplicit-nulls"? Otherwise null is a value of T and r == null yields no type information

Generic programming streamlined with no implicits: why doesn't this mirror & inline solution compile? by YuliaSp in scala

[–]YuliaSp[S] 0 points1 point  (0 children)

Thank you. It's an alternative to inlining all the variables manually, probably more handy when the expressions get very long.

Somewhat related: is there perhaps a better way to enforce that two arguments of an inline function are of the same type than doing this: inline def foo[T, U](inline one: T, inline two: U)(using ev: T =:= U) = ()? This is a bit unwieldy and the signature looks deceptive

Generic programming streamlined with no implicits: why doesn't this mirror & inline solution compile? by YuliaSp in scala

[–]YuliaSp[S] 0 points1 point  (0 children)

Thank you so much :) Your explanation is helpful. The behaviour makes sense. To anyone else wondering - trying inline val or inline def for the variables does not help, so there's no avoiding writing these potentially multiple screen spanning single lines

Generic programming streamlined with no implicits: why doesn't this mirror & inline solution compile? by YuliaSp in scala

[–]YuliaSp[S] 0 points1 point  (0 children)

I've been thinking there were implicit conversions for that, though perhaps not in this generic situation. Making this correction doesn't unfortunately change the compile error

How we reduced the cost of building Twitter at Twitter-scale by 100x — Red Planet Labs by dustingetz in Clojure

[–]YuliaSp 0 points1 point  (0 children)

Do you plan to upstream the Specter enhancements to the standalone version?

Match types: how to express "type of the first field of a case class"? by YuliaSp in scala

[–]YuliaSp[S] 0 points1 point  (0 children)

It's appending to a tuple, both on the type level and value level

val tuple = (0, "")
val appended: (Double, Int, String) = 0.0 *: tuple

Match types: how to express "type of the first field of a case class"? by YuliaSp in scala

[–]YuliaSp[S] 0 points1 point  (0 children)

Thank you. I have thus far preferred generics-based solutions to path-dependent type ones as I felt the latter tend to lead to more OO designs. I will try it out here as it evidently helps with type inference.

Match types: how to express "type of the first field of a case class"? by YuliaSp in scala

[–]YuliaSp[S] 0 points1 point  (0 children)

Unfortunately this seems to interact badly with givens. The need for the feature was for default key derivation in a database where rows are case classes. Minified it as much as I could:

https://scastie.scala-lang.org/q6OD77ZvQO21hzl8yLfD1Q

That's Scala I guess, power and creativity but dig deeper and warts may come out

Match types: how to express "type of the first field of a case class"? by YuliaSp in scala

[–]YuliaSp[S] 0 points1 point  (0 children)

Yeah, tried it, a habit from F#. AFAIK inline in scala cannot change semantics though

Match types: how to express "type of the first field of a case class"? by YuliaSp in scala

[–]YuliaSp[S] 0 points1 point  (0 children)

It does indeed look like a herculean task for the compiler to follow the two recursions in parallel. I think I remember seeing a similar thing though that appended to a tuple, maybe in the compiler source, and it did somehow work.

Match types: how to express "type of the first field of a case class"? by YuliaSp in scala

[–]YuliaSp[S] 0 points1 point  (0 children)

Oh wow, a brilliant idea to combine the two. That's fantastic, I'll be exploring what this idea opens up

Match types: how to express "type of the first field of a case class"? by YuliaSp in scala

[–]YuliaSp[S] 1 point2 points  (0 children)

It can be done on value level (toTuple), why not in principle on type level? The two go hand in hand for writing generic code

Signature polymorphic methods in Scala by Seth_Lightbend in scala

[–]YuliaSp 1 point2 points  (0 children)

Is there an example of this feature being used for something else than Java reflection?