A few days ago, I noticed that the Dart List class has a single property. Then I read the official API document and realized how this property works. This means that I know that List.single works as follows:
print(['a'].single); // outputs 'a' print(['a', 'b'].single) // throws StateError
But I can not find a practical example of using the single property. The baby codes shown above make no sense in real programming, of course.
What is the purpose of ownership? Why does this property throw an exception if the list contains two or more elements? Why is this not a boolean property, which means that List has only one element? How do Dart Language developers find it useful to include List.single in the main API?
If you have any knowledge about this, I would really appreciate it if you give me a hand.
user4364647
source share