Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Muhammad Sameer Ali
    @msali123
    Hi
    I'm new here. Is there any way to host a project built with scala. On github pages or etc?
    Dhruv Kapur
    @dhruvkapur91
    Hey folks. Glad to find this channel. Wish for everyone's safety in this crazy virus time!
    Noel Welsh
    @noelwelsh
    :+1:
    Josué
    @eusojk
    Hi all,
    I just started my Scala/FP learning journey with Creative Scala. Very fantastic and engaging so far :raised_hands: !
    For some reason, the images (figures) on the website don't render for me. I've tried multiple browsers with no luck. Has anyone experienced this by any chance? Thanks in advance!
    Adam Rosien
    @arosien
    @eusojk no, you're right, the images for the book on creativescala.com aren't loading. i'll let @noelwelsh know! thanks
    Josué
    @eusojk
    Thanks @arosien, appreciate it!
    Noel Welsh
    @noelwelsh
    Thanks for letting me know. I don't know why the images aren't working (nothing has changed in the build system) but the system we use to build the books is well past its use by date.
    Paul Carey
    @paulcarey
    hi, what does the [_] before the List in the following refer to?
    List(1).withFilter(_ > 0)
    val res63: scala.collection.WithFilter[Int,[_]List[_]] = scala.collection.IterableOps$WithFilter@cf76c0b
    I've been trying to google the answer, but without success. thanks
    Adam Rosien
    @arosien
    @paulcarey there are 2 type parameters to WithFilter, and the second one is List[_], where [_] is syntax for "the type parameter is missing". List is a type constructor with one type parameter, and if you supply the type parameter, like Int, you get back a type List[Int].
    note this syntax only applies to type parameters. if you have a value parameter def something(list: List[_]), then the [_] is a wildcard, meaning you can pass a list value whose elements are any type.
    ([_] there means "i don't care what the type is, so i'm going to forget its name", just like _ in places like pattern matching means "i don't care what this is, i'm not even going to name it")
    Alan Lewis
    @london-coder
    Hi All, just joined, so I hope I might get a bit of help, and not offend any members if my enquiry is too simple. I've looked at @davegurnell validation framework. A nice library, that I'm sure is useful in a number of scenarios. However, I have a much simpler need to validate values in a single case class. Is there a 'lighter weight' capability that will be suitable for a smaller requirement?
    Adam Rosien
    @arosien
    @london-coder you could just use "plain" functions to validate, perhaps in the case class or companion object. the functions could return Either or perhaps cats.Validated
    Alan Lewis
    @london-coder
    Hi @arosien thanks for the quick reply. I'll give that a try. But, I was hoping I could use the validation (of 2 case class field values, and for any duplicate entries) in a for comprehension. Yes, I realise that means the mechanism will require map and flatMap methods.... Therein lies my difficulty. I'm not confident in implementing those methods for non-collection types
    Adam Rosien
    @arosien
    ah i see. and the flatMap doesn't exist on Validation, and will "fail-fast", when you probably want to collect all the errors

    if you use cats you can follow the examples at https://typelevel.org/cats/typeclasses/parallel.html#parallel

    basically you write your validation functions to produce Either. but you "glue together" those functions to act using Validated, which then gets converted back to Either at the end

    that is, you can't use a for-comprehension if you want to collect all the errors. you need something like mapN from cats. it's like a mode: you switch from fail-fast (flatMap via Either) to collect-errors (mapN via Validated), and back.
    Adam Rosien
    @arosien
    let me know if any of that makes sense :)
    Paul Carey
    @paulcarey
    @arosien thanks, but doesn't your answer refer to the second [_] in [_]List[_]? I'm wondering about the first one.
    Adam Rosien
    @arosien
    ah. i think i mentally didn't see the first [_], which is some sort of toString artifact. it's not legal scala syntax.
    it should have printed val res63: scala.collection.WithFilter[Int, List] = ... to be correct
    (i think)
    Paul Carey
    @paulcarey
    ok, that's what I would have expected. I was a bit puzzled by the preceding [_].
    Adam Rosien
    @arosien
    yeah, i can guess that there's some anonymous parameter that it is choosing to also anonymize, which makes it extra confusing.
    REPL output should be valid REPL input!
    Paul Carey
    @paulcarey
    thanks
    Adam Rosien
    @arosien
    np
    Alan Lewis
    @london-coder
    @arosien Appreciate the help, it did make sense, thank you. If you have a bit of time, could you possibly elaborate slightly on what you meant by "glue together"? I don't want you to think I'm asking for a complete solution, just a thumb nail sketch? Or, will having a look at the cats example be enough?
    @arosien , I've had a look at the examples in the link you included. I see what you meant now... many thanks.
    Adam Rosien
    @arosien
    no problem.
    "glue together" = more than 1 Either => 1 Either. a for-comprehension does this, but mapN also does it.
    Paul Carey
    @paulcarey
    actually, I see the same syntax - [A]Foo[Int, String, A] - on this post about partial unification, so I guess it does have a specific meaning that I'm not familiar with
    Adam Rosien
    @arosien
    what REPL is that? from sbt?
    Adam Rosien
    @arosien
    i think it is a "type lambda": we need a name for a unsupplied type parameter, so you first name it ([A]), then refer to it later in the type expression
    Paul Carey
    @paulcarey
    yep, sbt, but it also appears in the standard Scala REPL (2.13.1)
    premsagarreddy
    @premsagarreddy
    is there a way to create case class from nested json
    Noel Welsh
    @noelwelsh
    @premsagarreddy Most JSON libraries will support that. I usually use Circe for JSON in Scala.
    jspielmann
    @jspielmann
    Hello, quick question, does anyone have an sbt file with node/npm/frontend JS integration that I can use as inspiration?
    Adam Rosien
    @arosien
    @jspielmann i'm not sure i understand. like for using scalaJS?
    jspielmann
    @jspielmann
    @arosien no, I want to build my front end JS code when I run sbt compile, serve the front end when I run sbt run, etc.
    I tried using sbt frontend plugin but I get node errors that are related to rollup JS (I’m using svelte in the front end, which uses rollup as bundler)
    Adam Rosien
    @arosien
    i really don't know anything about js development, but if you need to use sbt for some reason, you can define your own tasks that could, for example, run external processes. i don't think it's common to use sbt for a js-only project though, if i'm interpreting you correctly.
    jspielmann
    @jspielmann
    backend is scala of course :)
    Adam Rosien
    @arosien
    it sounds a bit strange to make compile and run in sbt work on the frontend code, in the sense that those commands are intended to work with scala code. but it also sounds like the js-related tasks that sbt-frontend makes available isn't working with your js code.
    Noel Welsh
    @noelwelsh
    You can define an sbt task to execute arbitrary shell commands. That might do it.
    Perry Dunn
    @perrydunn
    Hi there, is there an update on a hard copy version of Scala with Cats?
    Adam Rosien
    @arosien
    @perrydunn no update yet :( i think our next priority is to update the book for the latest cats and for scala 3
    Perry Dunn
    @perrydunn
    Thanks for the update