Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 21:09

    SethTisue on 2.12.x

    2.12: new Scala SHA (#1511) (compare)

  • 21:09
    SethTisue closed #1511
  • 16:32
    apointeau opened #2245
  • 16:04
    badrinathpatchikolla commented #10129
  • 15:28
    arata-honda opened #2244
  • 15:09
    arata-honda commented #2235
  • 15:07
    arata-honda synchronize #2235
  • 15:04
    SethTisue commented #10129
  • 15:03
    SethTisue commented #10129
  • 15:03
    SethTisue commented #10129
  • 15:02
    SethTisue commented #10129
  • 14:40

    SethTisue on 2.13.x

    2.12: advance project SHAs (#14… 2.12: new Scala SHA 2.12: advance project SHAs (#15… and 5 more (compare)

  • 14:40
    SethTisue closed #1512
  • 14:23
    badrinathpatchikolla commented #10129
  • 14:22
    badrinathpatchikolla commented #10129
  • 11:30
    marksmithson opened #2243
  • 10:45
    Sporarum edited #9792
  • 08:57
    yikf commented #12504
  • 08:52
    lrytz closed #12504
  • 08:52
    lrytz commented #12504
gitleet
@gitleet
function that takes 2 params, string and T, and returns a String?
Rob Norris
@tpolecat
Yeah I would say something like "String T to String"
The parameter types are inferred on the RHS so you can say ... = (a, b) => b.toString which shortens it a bit.
gitleet
@gitleet
how can I add this inline function to a value? val f = .... ?
Are inline function parameters in a def optional?
zeroexcuses
@zeroexcuses
Is https://www.artima.com/shop/programming_in_scala_5ed still "draft", or is the book done:? (I can not find this book at any other website, and I have never purchased from this website, and this website's design does not look very modern.)
Martijn
@martijnhoekstra:matrix.org
[m]
What do you mean with adding to a funtion in this context @gitleet ? If you have some val f: Int => String, you can pass it to a method just by its name. Say, you have a val l = List(1, 2, 3), then you can pass it to its map method with l.map(f)
or do you maybe want to compose to functions, where you have a val g: Double => Int and also a val f: Int => String, and you want a function that first does g and then f, you can compose that as g.andThen(f)
(or as f.compose(g), which has the downside that you'll look more mathy and the upside that everyone finds it harder to read)
(bonus points on insisting it's way more natural for you)
gitleet
@gitleet
I tried to do: val f = (String, T) => String = (a: String, b: T) => b.toString
Martijn
@martijnhoekstra:matrix.org
[m]
you're going wrong with the syntax. The geneal syntax when defining a value is val name: Type = value
name here is f, the type is (String, T) => String, and the value is (a: String, b: T) => b.toString
that gives you val f: (String, T) => String = (a: String, b: T) => b.toString
there's a few things to notice here
if you already have a fully expected type, you can leave the ascriptions of the parameters off:
//instead of 
val f: (String, T) => String = (a: String, b: T) => b.toString
//you can do
val f: (String, T) => String = (a, b) => b.toString //because you already know the expected type, you don't need to repeat it
I get a not found type T error
Martijn
@martijnhoekstra:matrix.org
[m]
another thing to note is that you're not using a at all! that's probably a bug. This is a toy example, but be mindful
if T is intended to be a type parameter, in scala 2, you can't do that, and in scala 3, there is special syntax for that
gitleet
@gitleet
this is scala2
Martijn
@martijnhoekstra:matrix.org
[m]
in scala 2, unfortunately you can't have a function with a type parameter
gitleet
@gitleet
as a value...so it works inline ok
Martijn
@martijnhoekstra:matrix.org
[m]
there are workarounds, but they're not very pretty. Best for now to forget about it
there isn't really any difference between inline and not inline
in your situation, it probably works because T is defined when you call it inline, and not if you don't
e.g. given def foo[T](f: T => Int), you can do foo((t: T) => 7) because T is defined there
It's good to note that you can't really do anything with it, precisely because it's abstract: in my example I ignore it entirely
in your example, you call toString on it, which you can always do
but that's about it for the things you can do with T of a type you don't know
it could just as well have been Any, you can't do anything more with it
gitleet
@gitleet
i see ok
thanks for your help
Martijn
@martijnhoekstra:matrix.org
[m]
glad to help
feel free to keep asking about whatever you run into
Luis Miguel Mejía Suárez
@BalmungSan
Note that if you need a generic function, you can use a method instead. Thanks to eta-expansion the method will be converted to a function when you use it; and in that moment it will pick a concrete type for the generic (like it was inlined).
So you can do this
def foo[T](t: T): T = t

List(1, 2, 3).map(foo)
gitleet
@gitleet
if I have a method that takes a function as a parameter...how do I make it optional?
I'm looking at some code that takes a function as an arguement...and in some cases this function is called w/o passing in the function paramter...
so parameters that are functions are optional?
Martijn
@martijnhoekstra:matrix.org
[m]
No, they're not. Maybe there is another method with the same name that doesn't take the function argument
Rob Norris
@tpolecat
It can have a default argument, maybe that's what's happening.
@ def foo(f: Int => Int = _ + 1): Int = f(42) 
defined function foo

@ foo() 
res1: Int = 43

@ foo(_ * 2) 
res2: Int = 84
gitleet
@gitleet
I searched for multiple def defintions..but only 1. I see no default argument either. Has to be something I am missing :)
Luis Miguel Mejía Suárez
@BalmungSan
If you want / can, you may share the definition and how it is being called.
gitleet
@gitleet
its too complicated to paste...let me figure it out or at least try thanks!!
giiita
@giiita
Hi, I have two questions about Scala3 macro.
  1. Has the equivalent of Parsers been removed?
    https://www.scala-lang.org/api/current/scala-reflect/scala/reflect/macros/Parsers.html
  2. Has the deployment of the variable length formula in splicing been disabled?
    https://docs.scala-lang.org/overviews/quasiquotes/intro.html#splicing
Jack Koenig
@jackkoenig
I'm hitting a weird error message
class Fizz
class Apple { def x: Fizz = new Fizz }
class Pear { def y: Fizz = new Fizz }

class Foo[A, B]
object Foo {
   def mapping[A, B](mapping: (A, B) => List[(Fizz, Fizz)]): (Foo[A, B], Foo[B, A]) =
     (new Foo[A, B], new Foo[B, A])
}

object Bar {
  implicit val (a, b) = Foo.mapping[Apple, Pear]({ case (a, b) => List(a.x -> b.y)})
//              ^ recursive value x$1 needs type
}
Scastie: https://scastie.scala-lang.org/sHBdYSkzR4iMljG7dNgotQ
Possible compiler bug? Seems to effect any version of 2.13 or 2.12 that I try