On Thu, Aug 22, 2024 at 9:30 AM Adam Baratz <adam.bar...@gmail.com> wrote:
>
> I've been reading the iter pkg docs and I'm trying to understand a 
> distinction drawn there.
>
> It says that the iterator method on a collection type is conventionally named 
> All (and returns a Seq). However, the maps and slices packages handle this a 
> little differently. They have All funcs that return a Seq2, and separate 
> Values funcs that return a Seq.
>
> How come there's this difference? Looking at making an update to some 
> collection types, wondering if it's more appropriate to have a Values method 
> if it's going to return a Seq.

For a container type that contains only values, not keys, All should
return an iter.Seq.

For a container type that contains both keys and values, All should
return an iter.Seq2.

Slices and maps are container types that contain both keys and values,
so maps.All and slices.All return iter.Seq2.

Whether a Values method/function makes sense is going to depend on the
container type.  For both slices and maps it does make sense (and, of
course, maps also has a Keys function).

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXr5Ett3LRYi33Oufv2HCeEx3-%2B-rVSg2MrFogXYX-4XQ%40mail.gmail.com.

Reply via email to