D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22736 - Add destructuring bind for std.typecons.Tuple tuples
Summary: Add destructuring bind for std.typecons.Tuple tuples
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P5 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2022-02-04 19:41 UTC by Vladimir Panteleev
Modified: 2022-03-10 14:39 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vladimir Panteleev 2022-02-04 19:41:50 UTC
auto bind(alias fun, T)(auto ref T tuple)
if (isTuple!T && is(typeof(fun(tuple.expand))))
{
	return fun(tuple.expand);
}

unittest
{
	immutable t = tuple(1, 2);
	auto sum = t.bind!((one, two) => one + two);
	assert(sum == 3);
}
Comment 1 Vladimir Panteleev 2022-02-04 19:56:19 UTC
Why not just specify the names when constructing the tuple?

-> Sometimes, the tuple is constructed in more than one place. This would require specifying the same names at every construction site.

Why not declare the tuple type ahead of time?

-> The declaration may need to be placed far away from the construction and use sites, such as in long UFCS chains.
Comment 2 Dlang Bot 2022-02-04 20:01:51 UTC
@CyberShadow created dlang/phobos pull request #8372 "[RFC] Fix Issue 22736 - Add destructuring bind for std.typecons.Tuple tuples" fixing this issue:

- Fix Issue 22736 - Add destructuring bind for std.typecons.Tuple tuples

https://github.com/dlang/phobos/pull/8372
Comment 3 Dlang Bot 2022-02-07 23:18:10 UTC
@pbackus created dlang/phobos pull request #8376 "Add std.functional.bind" fixing this issue:

- Add std.functional.bind
  
  Fixes Issue 22736 - Add destructuring bind for std.typecons.Tuple tuples

https://github.com/dlang/phobos/pull/8376
Comment 4 Dlang Bot 2022-03-10 14:39:22 UTC
dlang/phobos pull request #8376 "Add std.functional.bind" was merged into master:

- 9d1aeeca2b0bcc5cf08f7eebd5283466444112ba by Paul Backus:
  Add std.functional.bind
  
  Fixes Issue 22736 - Add destructuring bind for std.typecons.Tuple tuples

https://github.com/dlang/phobos/pull/8376