Martini Stream Functions
In Martini, the Stream class is equipped with a collection of functions tailored for stream-based operations within services. This section provides guidance on how to effectively utilize these functions in service development.
Accessing Stream Functions
Stream functions can be found under the 'functions' node in the Martini Navigator, specifically within the 'stream' folder. This directory houses a range of functions dedicated to stream operations. Integration of these functions into your services can be achieved through drag-and-drop actions or by using content assist with the “stream.” prefix.
Function Identification
When incorporating stream functions into your services, it's crucial to identify them correctly. Functions belonging to the stream class are consistently prefixed with "stream." This is an important aspect to consider, especially in environments where similar functions might exist. Always look for the "stream." prefix to ensure the correct application of these functions.
Application in Services
Stream functions in Martini are designed for service-level operations, complementing the Java Stream API supported by Groovy. These functions are essential for handling collections, such as data model arrays, streamlining processes like sorting or transforming data.
Implementing Stream Functions
An example application of stream functions could be in a service that sorts a collection based on certain attributes. For instance:
-
Sorting: Implement the “stream.sorted” function on a collection to organize its elements. You can specify the sorting criteria based on the attributes of the collection's elements.
-
Conversion to List: After sorting, the “stream.toList” function can be used to convert the stream back into a list format, thereby finalizing the sorted output.