![]() Val alphabet = Seq(abcd, efgj, ijkl, mnop, qrst, uvwx, yz) For me, it’s hard to describe this function without an example. Because its application is extremely specific. I bet, there is a huge chance that you haven’t heard about this function before! It’s easy to explain. If no, try to substitute filter function for filterNot in the first example. I guess, you know what it does by its name. What about more complex scenario? I want to choose books where number of pages more than 120.īook("Object Oriented Programming", 130),įiltering is not much harder to apply than the min & max functions, despite that filter is a function of the transformation type.Īlso there is a syntax sugar analogue of filter function. Let’s start with the popular example: filter a list of numbers and get only even elements. All this operations imply usage of filtering. ![]() Have you ever performed filtering of collections? For example you want to get items with price more than $10 or you need to select the youngest employees with age under 24 years. The only thing you need to do is to choose a data property by which you want to determine minimum or maximum value. So as you see, minBy & maxBy functions solve problem with non-trivial data. But let’s be honest, who don’t remember this lines of code in Java? Of course you may say that this kind of operations are helpful only for interview questions and algorithms. It’s so common task to find a minimum or maximum value in a sequence. I want to start from the action function. And in the end of the article I want to show you, how these functions can be combined in order to solve a concrete problem. ![]() Some of these functions aimed to transform collections, rest of them return a particular values after application. The second one type returns some value.Īfter this short introduction I want to focus on particular Scala collection functions, which I count the most useful and amazing in everyday work. The first type transforms a collection into some another collection. When I work with Scala collections, I always keep in mind that there are two types of operations which I can perform: transformation operations and actions or like someone call it aggregation operations. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |