Types, Kinds and Type Constructors in Scala | Rock the JVM

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2024

ความคิดเห็น • 35

  • @daniellopes6874
    @daniellopes6874 4 ปีที่แล้ว +6

    Next stop: type lambdas and partially applied types, which I personally still find hard to grasp. Some people refer to type constructors as types with holes you need to fill to get a well formed type. As you mentioned lifting functions mentally to the type level can help understand the concepts. What I found interesting about generics and generic functions in particular is that they limit the possible implementations and help alot when it comes to reasoning by only looking at the types.

    • @rockthejvm
      @rockthejvm  4 ปีที่แล้ว

      Yep - type lambdas coming in the next video tomorrow!

  • @ravisubramanian919
    @ravisubramanian919 2 ปีที่แล้ว

    Superb explanation! Thank you!

  • @HPA97
    @HPA97 ปีที่แล้ว +1

    Great explanation!

  • @AmitPrasadbangalore
    @AmitPrasadbangalore 2 ปีที่แล้ว

    Thank you Daniel, this is very crisp and clear , however I'm just wondering for
    Option[Seq[]] , why my code is not compiling
    It is something like
    trait CustomContainer[F[C[_]]] {
    def filterByQueryParameters[A, B](container: F[A])(f: A => B): F[B]
    }
    But this is not working for Option[Seq[CaseClass]], could you please spot what I'm missiing here. Thanks

  • @joan38
    @joan38 4 ปีที่แล้ว +1

    Really good videos. Super clear, super detailed.

    • @rockthejvm
      @rockthejvm  4 ปีที่แล้ว

      Glad to hear it!

  • @PlatinumDragonProductions999
    @PlatinumDragonProductions999 3 ปีที่แล้ว

    Thank you for all of your Scala videos, I am learning a lot from them :-)

    • @rockthejvm
      @rockthejvm  3 ปีที่แล้ว

      Glad they're useful!

  • @hotharvey2
    @hotharvey2 ปีที่แล้ว

    So, considering an Option[+A] - where I can create an Option[List[Int]], would it be correct that Option[+A] is only a level 1 type because the API of Option never interacts with the inner type?

    • @rockthejvm
      @rockthejvm  ปีที่แล้ว

      It's a "level-1" type in the video, yes - not sure what you mean by "never interacts with the inner type".

    • @hotharvey2
      @hotharvey2 ปีที่แล้ว

      @@rockthejvm Thank you. I mean that no method on Option will need to call any method on the Int, only the List

  • @jogatavid
    @jogatavid 4 ปีที่แล้ว +1

    What an incredible explanation thank you

    • @rockthejvm
      @rockthejvm  4 ปีที่แล้ว

      Happy it clicked!

  • @imranhossainfaruk5445
    @imranhossainfaruk5445 4 ปีที่แล้ว +1

    Hi Daniel,
    Thanks a lot for the nice video.
    I am confused about a particular scenario, I have tried to summarize the scenario in dummy code( it does not compile). Could you please help me understand how can the scenario be achieved?
    trait GenericFlatten[F[G[T]]]{ // sample concrete type List[Set[Int]] or Seq[List[String]]
    def flatten(input: F[G[T]]): F[T]
    // F[G[T]] => List[Set[Int]] , F[T] => List[Int]
    }

    implicit object GenericFlattenListSetInt extends GenericFlatten[List[Set[Int]]]{
    override def flatten(input: List[Set[Int]]): List[Int] = input.flatMap(_.toList)
    }

    def getFlattenCollection[F[G[T]]](input : F[G[T]])(implicit gf : GenericFlatten[F[G[T]]]): F[T] ={
    gf.flatten(input)
    }
    val listOfSet: List[Set[Int]] = List(Set(1,2), Set(2,3))
    val flattenList = getFlattenCollection(listOfSet)

    // expected output is 1,2,2,3

    • @rockthejvm
      @rockthejvm  4 ปีที่แล้ว +1

      Hi Imran, it's certainly possible, only that you can't pass all the type arguments nested like that. You can do this:
      trait GenericFlatten[F[_], G[_], T] {
      def flatten(input: F[G[T]]): F[T]
      }
      implicit object GenericFlattenListSetInt extends GenericFlatten[List, Set, Int]{
      override def flatten(input: List[Set[Int]]) = input.flatMap(_.toList)
      }
      def getFlattenCollection[F[_], G[_], T](input : F[G[T]])(implicit gf : GenericFlatten[F, G, T]): F[T] ={
      gf.flatten(input)
      }

    • @imranhossainfaruk5445
      @imranhossainfaruk5445 4 ปีที่แล้ว

      @@rockthejvm Thank you very much, Daniel.

  • @dhirendrapandit5530
    @dhirendrapandit5530 4 ปีที่แล้ว +1

    I loved this explanation

    • @rockthejvm
      @rockthejvm  4 ปีที่แล้ว

      Glad you liked it!

  • @ThePyroJoke
    @ThePyroJoke 4 ปีที่แล้ว +1

    Awesome video! Almost a super power of explaining complex abstract stuff in simple words :)
    One question to clarify: when you defined functorList as new Functor[List] that became level-1 type or level-0 type?

    • @rockthejvm
      @rockthejvm  4 ปีที่แล้ว +1

      If you can attach it to a value, that's a level-0 type in this terminology.

    • @daniellopes6874
      @daniellopes6874 4 ปีที่แล้ว +1

      I think they call it proper type or value type but I like your level scheme more intuitive. If you need a good reading before going to sleep 😬 scala-lang.org/files/archive/spec/2.13/03-types.html

  • @anticipayo
    @anticipayo 3 ปีที่แล้ว +1

    Can you put out a video that explains the placeholder ? or * for higher kind types as supposed to _? Thanks for the video

    • @rockthejvm
      @rockthejvm  3 ปีที่แล้ว

      Those placeholders will probably not be needed too much now with proper type lambda syntax in Scala 3 th-cam.com/video/b1C8ybLpzUc/w-d-xo.html

  • @pr0master
    @pr0master 4 ปีที่แล้ว +1

    Amazing video, thank you very much!!

    • @rockthejvm
      @rockthejvm  4 ปีที่แล้ว

      Glad you liked it!

  • @TheProximator
    @TheProximator 4 ปีที่แล้ว +1

    Very nice video, waiting next :)

  • @aviadshiber6232
    @aviadshiber6232 4 ปีที่แล้ว +1

    Great explanation! can you explain in other videos on shapeless?

    • @rockthejvm
      @rockthejvm  4 ปีที่แล้ว +2

      Noted - will have something on shapeless as well

  • @kevalan1042
    @kevalan1042 4 ปีที่แล้ว +2

    What would be awesome is to give code examples where a higher level type can simplify a codebase

    • @rockthejvm
      @rockthejvm  4 ปีที่แล้ว +2

      A subject for some 2-hour video! This would require some longer-form tutorial.

  • @RobinHillyard
    @RobinHillyard 2 ปีที่แล้ว

    Good description but you might want to show what you can actually do with something like your functorList.

  • @RomanArkharov
    @RomanArkharov 4 ปีที่แล้ว +1

    Thank you for the video and light theme in IDE :)

    • @WA9NNN
      @WA9NNN ปีที่แล้ว

      I find the light theme much easier to read. Thanks.

  • @robert33232
    @robert33232 2 ปีที่แล้ว

    HashMap - why not just call it Dict? 🙂