Dart Set followedBy()
Syntax & Examples
Set.followedBy() method
The `followedBy` method in Dart returns the lazy concatenation of this iterable with another iterable.
Syntax of Set.followedBy()
The syntax of Set.followedBy() method is:
Iterable<E> followedBy(Iterable<E> other)
This followedBy() method of Set returns the lazy concatentation of this iterable and other.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
other | required | An iterable to concatenate with this iterable. |
Return Type
Set.followedBy() returns value of type Iterable<E>
.
✐ Examples
1 Concatenating two integer iterables
In this example,
- We create two Iterable objects
first
andsecond
with values [1, 2, 3] and [4, 5, 6] respectively. - We use the
followedBy()
method to concatenatefirst
withsecond
. - We print the resulting combined Iterable.
Dart Program
void main() {
Iterable<int> first = [1, 2, 3];
Iterable<int> second = [4, 5, 6];
Iterable<int> combined = first.followedBy(second);
print(combined);
}
Output
(1, 2, 3, 4, 5, 6)
2 Concatenating two string iterables
In this example,
- We create two Iterable objects
fruits
andmoreFruits
with values ['apple', 'banana'] and ['cherry', 'orange'] respectively. - We use the
followedBy()
method to concatenatefruits
withmoreFruits
. - We print the resulting combined Iterable.
Dart Program
void main() {
Iterable<String> fruits = ['apple', 'banana'];
Iterable<String> moreFruits = ['cherry', 'orange'];
Iterable<String> allFruits = fruits.followedBy(moreFruits);
print(allFruits);
}
Output
(apple, banana, cherry, orange)
Summary
In this Dart tutorial, we learned about followedBy() method of Set: the syntax and few working examples with output and detailed explanation for each example.