New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mapMany Operator #154
mapMany Operator #154
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! A few minor changes here :)
print(result) | ||
}) | ||
|
||
stringsStream.mapMany { $0.lowercased() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add an example with a fake initializer (e.g. add a fake struct and initialize many� of it with mapMany
) ?
Source/RxSwift/mapMany.swift
Outdated
- returns: An observable collection whose elements are the result of invoking the transform function on each element of source. | ||
*/ | ||
|
||
public func mapMany<T>(_ transform: @escaping (E.Element) -> T) -> Observable<[T]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the transform
block needs to throw like map
itself: https://github.com/ReactiveX/RxSwift/blob/master/RxSwift/Observables/Map.swift#L20
What about the implementation example I put in #93 (comment) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bit unclear why it should throw 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the original map method accepts a throwing closure, so we should accept a throwing closure as well:
func map(_ transform: (Self.Element) throws -> T) rethrows -> [T]
Tests/RxSwift/MapManyTests.swift
Outdated
import RxTest | ||
|
||
class MapManyTests: XCTestCase { | ||
fileprivate func runAndObserve<C: Collection>(_ sequence: Observable<C>) -> TestableObserver<C> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here like the sample project - please add something that tests mass initialization of a data model, like a struct.
Thanks !
P.S @jdisho If you'll have time to do this in the next few days we can push it in the upcoming release :) Don't mind waiting since its a few minor fixes. |
Source/RxSwift/mapMany.swift
Outdated
@@ -16,7 +16,7 @@ extension ObservableType where E: Collection { | |||
- returns: An observable collection whose elements are the result of invoking the transform function on each element of source. | |||
*/ | |||
|
|||
public func mapMany<T>(_ transform: @escaping (E.Element) throws -> T) -> Observable<[T]> { | |||
public func mapMany<T>(_ transform: @escaping (E.Element) throws -> T) rethrows -> Observable<[T]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't mind reverting the commit, but a func can be a rethrowing func to show that it throws an error only if it’s function parameter throws an error. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm if that would be the case than the map throws without rethrow doesn’t make sense ? I think in general we’d want it to behave much like a regular map so I think It’s best to keep the signature similar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor changes and we're g2g
Tests/RxSwift/MapManyTests.swift
Outdated
} | ||
|
||
class MapManyTests: XCTestCase { | ||
fileprivate func runAndObserve<C: Collection>(_ sequence: Observable<C>) -> TestableObserver<C> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you get rid of fileprivate
here (and also on top) ?
It's irrelevant given the fact its part of a test suite, and the method is part of the class itself.
import RxSwift | ||
import RxSwiftExt | ||
|
||
fileprivate struct SomeModel: CustomStringConvertible { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, no reason for ACL at all given the fact its constrained to the playground page
toSortedArray operator
This reverts commit b9a699e.
@jdisho Did a bit of cleanup, let me know what you think :) Also noticed some issue with |
There seems to be a few missing operators in the playground page and README 🤔 not sure why. Need to find the time to look into it. |
OK so, there is some issue with documentation across other operators that were probably not reviewed properly before merge. We'll have to deal with it via a different PR but I think we can merge this regardless. |
I can update the documentation in a separate PR. |
I'm gonna merge this as soon as CI passes. And yeah that'd be great but to be honest i feel like we're going to have to add some automation to make sure documentation is synced across README -> Playgrounds -> Comments etc. Might be some work but we'll see later on :) |
Strange, CI is successfully passed.😕 |
Yeah, the fact CI passes is a bug that you should ignore - but the build clearly fails |
Ok, so CI is fixed - now time to fix your tests :) @jdisho |
c672c14
to
7a9135b
Compare
I don't understand, the test passed in Xcode 😕 |
@jdisho Tried bumping CI Xcode to 9.4.0, lets see if that helps |
Here we go :) @jdisho |
@jdisho Usually the author of the PR should not be the one to merge it, just FYI - but no biggie :) |
For the proposed operator #93 🎉