Adds Publisher.weaklyAssign(to:on:).#14
Adds Publisher.weaklyAssign(to:on:).#14jasdev wants to merge 2 commits intoCombineCommunity:masterfrom jasdev:weak-assign
Publisher.weaklyAssign(to:on:).#14Conversation
Codecov Report
@@ Coverage Diff @@
## master #14 +/- ##
==========================================
+ Coverage 95.77% 95.82% +0.05%
==========================================
Files 28 30 +2
Lines 1253 1270 +17
==========================================
+ Hits 1200 1217 +17
Misses 53 53
Continue to review full report at Codecov.
|
|
Interesting idea and quite small as well, I'm only trying to think if it's actually useful enough - I'm worried of adding too many "novelty" operators. I don't want tens of operators called |
|
Naming-wise, I'm not sure publisher.assign(to: \.foo, onWeak: bar)`This mirrors capture list syntax somewhat, where it would be spelled publisher.assign(to: \.foo, onUnowned: bar)I'm sympathetic to @freak4pc's point about generality though. Another option I considered was a function that returns a weak reference, e.g.: final class WeakBox<Object: AnyObject> {
weak var object: Object?
init(_ object: Object) {
self.object = object
}
}
func weak<Object: AnyObject>(_ object: Object) -> WeakBox<Object> {
WeakBox(object)
}
publisher.assign(to: \.foo, on: weak(bar))I don't love it, but I don't hate it. In Bindings I sidestepped this issue altogether by introducing the |
|
@freak4pc, @sharplet: Thank you both for the feedback, means a lot that y’all took the time. 🙏🏽 And totally agree on the ad-hoc’ness of Cheers! 🍻 |
|
(For any future souls stumbling upon this, wrote up some learnings from trying to implement the |
Would love any input on naming here—no strong opinions on
.weaklyAssign. 👌🏽Also, GitHub’s parsing of my commit message. 😂