Tuples citizenship

Jonathan M Davis jmdavisProg at gmx.com
Fri Mar 2 01:08:43 PST 2012


On Friday, March 02, 2012 11:41:16 Dmitry Olshansky wrote:
> On 02.03.2012 6:06, bearophile wrote:
> > Jonathan M Davis:
> >> Yes, but chaining functions is the issue. It doesn't work well with
> >> tuples
> >> unless the function you're passing the result to wants the tuple. If all
> >> it
> >> wants is one piece of the tuple, then that doesn't work well at all.
> 
> just stick in .expand ?
> 
> void f(int x, int y){ }
> 
> void main()
> {
> 	Tuple!(int, int) a;
> 	f(a.expand);
> }

That's assuming that you're passing all of the pieces of the tuple to the 
function. Often, that's not the case at all. Take the findSplit trio, for 
instance. What are the odds that you're going to want to pass all of the 
elements in the tuples that any of the return to another function? About zero, 
I'd say. It's _much_ more likely that you're going to want to take the results 
and then pass _one_ of them to another function. So, as it stands, chaining 
with those functions just doesn't work unless you only care about one of the 
results in the tuple.

- Jonathan M Davis


More information about the Digitalmars-d mailing list