📜 ⬆️ ⬇️

Good news! Meet the language for collections of ActionScript

Those who work a lot with arrays and vectors (almost all developers think this) will be pleased with the new features: Support for Collections Language appeared in the Realaxy ActionScript Editor.

image

In the light of the fact that in the future, RASE will learn to drive AS3 to js / cpp / php / android / ios, other developers will fall in love with this language sugar.

So, the language for collections.
')
The entire list of methods and capabilities on the examples of tests can be seen here and here .

In this article we briefly describe a few typical examples of work.

image

The first example shows brevity. The first part before the comment is written in collections language. Let's say we want to create a list ( list ), which can contain only the type int , select from it only those elements that satisfy the condition ( where ), do something with each element ( select ) , turn the elements into a string ( select ), and finally walk through the entire sheet and make a trace of what happened. All other lines are normal AS code that does the same. So succinctly describe how this code works will not work.

Where, select, selectMany, findFirst, findLast operations are very convenient to use when querying.

image

The all, any, containsAll, contains operations work fine under conditions.

image

To modify the sheet, you can use an extensive arsenal of actions - remove, removeAll, removeWhere, removeTail, removeHead and others.

image

For any distortions from the collections there are foldLeft / foldRight, reduceLeft / reduceRight, intersect, and more.

There are many operations in the language: there will be for every taste, and practically for any task.

In some operations, you simply pass the values; in others, you add code to the enclosure.

This is an essentially anonymous function, but with a few differences.

image

First of all, the coverture has a very short syntax - the parameters do not have a type declaration (they exist, but they are hidden). Secondly, the covert has the behavior of the “last statement - return ”. That is, it is not necessary to write return 1 . It is enough to write in the last line “1; ".

In addition, it has a special mapping for single lines of the cokure (which is usually the most) - no such semicolon appears at such coaches at the end - again for readability to brevity.

Unlike the anonymous function (as opposed to the built-in methods of working with collections, the campaign is aware of the type of the element and autolit works and checks).

Summarizing, we can say that the overlay is such a function on steroids that can do a lot and helps us to write quickly and compactly.

In order to easily embed collections in AS projects, we did conversion operations. You can take a regular array and convert it to a list through a toList operation. After working with it, you can pass it to the old-school AS code as a regular array using the toArray operation.

To work with vectors, you can use the same toList operation and the toVector operation.

And finally - in the collections of two types - list and maps . Maps is essentially a regular Dictionary, which has several useful methods — keys , values (return a list of keys and values), containsKey , containsValue (useful for conditions and checks), and pushMap (for combining values). Modification - removeKey , removeValue .

Mapy will not allow adding a key or value of the wrong type:

image

Mapy work fine with sheets and queries.

image

So, if summarizing, if you have a copious salivation looking at these beauties, run to the realaxy.com website and download the latest build. What is important, we report bugs, because the release is just around the corner and we need to feel your support.

Thanks for attention!

Source: https://habr.com/ru/post/127190/


All Articles