Another trick is pattern matching against an interpolated string: def greet(str: String) = str match { case s"Hello, ${name}" => println(s"$name has joined") case _ => println("Someone has joined") }
@katabd
4 жыл бұрын
Wow.. love the video. Been using Scala for a while at work and learning while I go but haven't seen these types of pattern matching tricks. Learnt a lot of value from this. thanks.
@simonfarre4907
3 жыл бұрын
This is why I *love* rust. A low level systems language with pattern matching. Pattern. matching. is. incredibly. ergonomic.
@jeremygiaco
2 жыл бұрын
Thanks for the tricks. I haven't used scala for a few years and am diving back into it. Pretty helpful!
@rheafernandeshallu
3 жыл бұрын
Thank you so much for your tips and tricks. I love scala, but I find very little quality content related to it.
@rockthejvm
3 жыл бұрын
I'm glad I'm fitting into that box!
@Peter-xn9bk
Жыл бұрын
I have learned two course of you at Udemy, nice guide. Thankyou
@davidsljukic9317
3 жыл бұрын
Awesome tutorial series. Really enjoying working out the examples alongside the video \m\
@rockthejvm
3 жыл бұрын
Glad it worked well for you!
@mourikogoro9709
3 жыл бұрын
Another nice tricks!
@youngming1314
4 жыл бұрын
Great tutorial, thank you!
@alanlewis1625
3 жыл бұрын
Hi Daniel, another very good video, as usual. Albeit, with a tiny error, in the numbers list, appending the "st", "nd",... would not work with 11 or 12... Please keep up the great work with the Rock the JVM content. Thanks
@rockthejvm
3 жыл бұрын
Yeah, I realized post-releasing - you get the idea. Thanks a lot, will definitely come back with more content!
@philipkononenko4942
3 жыл бұрын
Great video! Thanks!
@rockthejvm
3 жыл бұрын
Thanks!
@theanigos
4 жыл бұрын
Very useful in data engineering space as well for routing different data flow with some complex conditions. Liked it!
@rockthejvm
4 жыл бұрын
Glad it was useful!
@sergeikharchikov1157
4 жыл бұрын
Thank you for your work!
@RealEyalPerry
Жыл бұрын
Really useful!
@mahendrarimal6178
Жыл бұрын
you are best keep up good work
@mikepictor
Жыл бұрын
I am wondering in your alternative patterns example, could you end in "case n" instead of "case _" ... to keep the processing more visually consistent to the examples above it.
@Tangxx2
3 жыл бұрын
The video is superb! Thank you so much as I'm struggling to find quality content like this. Also, it would be more favourable if you could provide the source code as well! Thank you so much!
@rockthejvm
3 жыл бұрын
Glad you like it! Check out the blog post, as you'll have the code there.
@hinrikmarhreinsson1688
4 жыл бұрын
Would you use pattern matching when parsing stream of data from Kafka or other databases? Do you know of a good flink + Scala tutorial?
@rheafernandeshallu
3 жыл бұрын
Hey, so the company where i work we use Flink and scala. If you want to look at the source code, here's the github link github.com/project-sunbird/knowledge-platform-jobs
@vitorfilho3167
Жыл бұрын
Great video, but i had a question, assuming I have several objects and these objects have a main function, which receive parameters something like this: object a {def main {p1, p2} in my another object i want to pass for this object using a match case paramater match {case paramater => a{p1,p2}. Is there any way for me to parameterize this object call too, because in this case I will have several objects that depend on this parameter match case?
@rockthejvm
Жыл бұрын
Objects cannot be parameterized, unless you write your own unapply (check the Custom Pattern Matching video/lesson in the Scala Advanced course).
@drishtinishchhalsahu3316
4 жыл бұрын
Hi, I get the same error in trick 2 process method. My Code - def process(aList: List[Int]) = aList match { case Nil => "list is empty" case head :: tail => s"list starts with $head, tail is $tail" } Error - process: (aList: List[Int])String
@bitcoindaddy748
4 жыл бұрын
Video is great, the blog page in the description does not work btw.
@rockthejvm
4 жыл бұрын
Works now: rockthejvm.com/blog/8-scala-pm-tricks
@shumymikaball
3 жыл бұрын
Can I use this with type literals to build a parser, instead of using antlr?
@rockthejvm
3 жыл бұрын
You can do whatever you want - however ANTLR's power is the ability to generate parsers based on grammar specification. You can't do that in Scala very easily.
@gijduvon6379
4 жыл бұрын
Daniel, do you planning to make videos about cats?
@rockthejvm
4 жыл бұрын
yep - will soon!
@drishtinishchhalsahu3316
4 жыл бұрын
Hi Thanks for the amazing videos, i am beginner in scala. I have tried trick#2 example from above, but i am getting below error. I am practising above example in scala worksheet. My Code - val numberList = List(1,2,3,4) val startWithOne = numberList match { case 1 :: tail => s"list start with one, tail is $tail" } Error Message - numberList: List[Int] = List(1, 2, 3, 4) ^ warning: match may not be exhaustive. It would fail on the following inputs: List((x: Int forSome x not in 1)), Nil startWithOne: String = list start with one, tail is List(2, 3, 4)
@trainchen9861
4 жыл бұрын
That's just a warning, not an error. It's warning you if some List "numberList" doesn't start with 1, the pattern matching would fail.
@cryptodeveloper
4 жыл бұрын
you need to add a default case to catch other cases. i.e if the List is something like List(2,3,4,5), your code will still compile and run but there will be no matched cases for this list. So use this-> case (_) => "Other cases will be caught here"
@fakirrabih2860
4 жыл бұрын
Thank you for the videos, very concise and helpful, I have a situation where my stream generated column “value” has a composite number something like: 0112547.21 the first 4 digits are the ID (0112) the rest is the value 547.21 what is best to decompose the column tried to use the regex but without success and here is what I tried to do as the first item to be extracted: Item12: Regex = "((?s)(?
@thelatestartosrs
9 ай бұрын
ordinal is incorrect
@kailar19
5 ай бұрын
what is the purpose of your main method without showing results how a beginner will learn. Good Material with poor presentation for beginners. Your intension is people should not learn
@rockthejvm
5 ай бұрын
For beginners, go here: kzitem.info/news/bejne/jm6MnJaDo4aZgaQ
Пікірлер: 42