-
Notifications
You must be signed in to change notification settings - Fork 57
mps.baseLanguageExtensions: New language with extensions to BaseLanguage
#1607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: maintenance/mps20223
Are you sure you want to change the base?
mps.baseLanguageExtensions: New language with extensions to BaseLanguage
#1607
Conversation
Add the ElvisOperation to the new base language extensions
--------- Co-authored-by: Dennis Albrecht <[email protected]>
…zip-operator Add zip operator to the new BaseLanguage extensions
Add the GroupByOperation to the new base language extensions
BaseLanguage
BaseLanguageBaseLanguage
…seq-operations-with-index Add sequence operations with index to new BaseLanguage extensions
The following `[0..10].zip([10..inf]).zip([0..inf])` was returning the wrong result.
…zip-bug Fix bug in zip operation
|
Can/should this language be integrated with com.mbeddr.mpsutil.blutil, located in the blutil folder? |
|
Also, the 2022.3 MPS version is quite old, are you prepared to handle cascading merges up to master? |
Add ScopeFunctionOperations to the new base language extensions
Fix insufficient type inference for groupBy
|
I didn't take a look at the implementation, but please don't forget the data flow aspect for the new concepts. |
|
Is there a schedule for when this feature should be ready? @dalbrecht1 , @alamqadem |
I realized that I would need a few things that I only have access to downstream to make that pretty (so I will probably contribute some more than initially planned), as well as there are some housekeeping things still open to do on that branch. On top other responsibilities were more important. I'll see what I can do in the next days. But I'd really want to target prior to end of year to get this off my plate. |
This language adds a series of extension to
BaseLanguage.The extensions are described in the following table:
maybeNullStr ?: "fallback"[0..n]s1.zip(s2)s1.groupBy({~it => // select key;})s.selectIdx({~it, int index => ...})s.whereIdx({~it, int index => ...})s.forEachIdx({~it, int index => ...})Elvis operation
When handling nullable values and you want to prevent NullPointerExceptions and have a "safe fallback value" of sorts, you can use the Elvis Operation to achieve a semantic similar to the ternary operation expression that will select and return your fallback, should the nullable value actually be null.
The operation will also be able to widen the typing to a common supertype, in case the fallback isn't immediately a subtype of the left hand side.
Integer sequence
[0 .. n]would produce a sequence of integers containing all integers from0ton.These are the 3 types of integer sequences that are supported:
[0..n]finite with a fixed upper limit;[0..#e]finite with an expression as an upper limit;[0..]infinite syntax.Zip operation
The operation
s1.zip(s2)creates a sequence of tuples, given a tuple of sequences.The sequence is stopped as soon as one of the sequences is consumed.
Group by operation
When operating on sequences and you want to identify groups of elements that match the same criteria, or more specifically that return the same element when a certain "bucket-sorting-function" is applied, then groupBy is the correct way. This adds an eagerly evaluated operation on sequences that produces a map, where the keys are the "buckets" identified by the provided function and the values are sequences of elements in the original sequence that returned the respective key. All elements from the original sequence will have a single representation in the resulting map.
Select, where, forEach with index
These operation allow to access the current index when applying the operation
select,whereorforEach.These operations are lazy.