Bug 22736 – Add destructuring bind for std.typecons.Tuple tuples
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P5
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-02-04T19:41:50Z
Last change time
2022-03-10T14:39:22Z
Keywords
pull
Assigned to
No Owner
Creator
Vladimir Panteleev
Comments
Comment #0 by dlang-bugzilla — 2022-02-04T19:41:50Z
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 by dlang-bugzilla — 2022-02-04T19:56:19Z
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 by dlang-bot — 2022-02-04T20:01:51Z
@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 by dlang-bot — 2022-02-07T23:18:10Z
@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 by dlang-bot — 2022-03-10T14:39:22Z
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