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

ParameterOptional/RequiredDescription
otherrequiredAn 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,

  1. We create two Iterable objects first and second with values [1, 2, 3] and [4, 5, 6] respectively.
  2. We use the followedBy() method to concatenate first with second.
  3. 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,

  1. We create two Iterable objects fruits and moreFruits with values ['apple', 'banana'] and ['cherry', 'orange'] respectively.
  2. We use the followedBy() method to concatenate fruits with moreFruits.
  3. 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.