Skip to content

Conversation

@alamqadem
Copy link
Collaborator

@alamqadem alamqadem commented Sep 25, 2025

This language adds a series of extension to BaseLanguage.
The extensions are described in the following table:

Name Extension Description
elvis operation maybeNullStr ?: "fallback"
integer sequence [0..n]
zip operation s1.zip(s2)
group by operation s1.groupBy({~it => // select key;})
select with index s.selectIdx({~it, int index => ...})
where with index s.whereIdx({~it, int index => ...})
forEach with 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.

null ?: "fallback" -> result: "fallback"
"valid" ?: "fallback" -> "valid"
"valid" ?: null -> "valid"
null ?: null -> 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 from 0 to n.
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, where or forEach.
These operations are lazy.

@alamqadem alamqadem changed the title BaseLanguage Extensions mps.BaseLanguageExtensions: Sep 25, 2025
@alamqadem alamqadem changed the title mps.BaseLanguageExtensions: mps.BaseLanguageExtensions: New language with extensions to BaseLanguage Sep 25, 2025
@alamqadem alamqadem changed the title mps.BaseLanguageExtensions: New language with extensions to BaseLanguage mps.baseLanguageExtensions: New language with extensions to BaseLanguage Sep 25, 2025
dalbrecht1 and others added 5 commits September 25, 2025 14:56
…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.
@sergej-koscejev
Copy link
Collaborator

Can/should this language be integrated with com.mbeddr.mpsutil.blutil, located in the blutil folder?

@sergej-koscejev
Copy link
Collaborator

Also, the 2022.3 MPS version is quite old, are you prepared to handle cascading merges up to master?

@alexanderpann
Copy link
Collaborator

I didn't take a look at the implementation, but please don't forget the data flow aspect for the new concepts.

@arimer
Copy link
Collaborator

arimer commented Nov 19, 2025

Is there a schedule for when this feature should be ready? @dalbrecht1 , @alamqadem

@dalbrecht1
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants