Skip to content
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

Merged
merged 15 commits into from Jul 8, 2018
Merged

mapMany Operator #154

merged 15 commits into from Jul 8, 2018

Conversation

jdisho
Copy link
Contributor

@jdisho jdisho commented May 6, 2018

For the proposed operator #93 🎉

@jdisho jdisho requested review from freak4pc and fpillet May 6, 2018 00:50
@jdisho jdisho changed the title mapMany mapMany Operator May 6, 2018
Copy link
Member

@freak4pc freak4pc left a 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() }
Copy link
Member

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) ?

- 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]> {
Copy link
Member

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) ?

Copy link
Contributor Author

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 🤔

Copy link
Member

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]

import RxTest

class MapManyTests: XCTestCase {
fileprivate func runAndObserve<C: Collection>(_ sequence: Observable<C>) -> TestableObserver<C> {
Copy link
Member

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 !

@freak4pc
Copy link
Member

freak4pc commented May 6, 2018

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.

@@ -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]> {
Copy link
Member

@freak4pc freak4pc May 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for a rethrow IMO.
Look at the original signature from RxSwift map:

e7bbb63d-ca2e-4f8e-b984-df05005af0b1

Copy link
Contributor Author

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. 🤔

Copy link
Member

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

Copy link
Member

@freak4pc freak4pc left a 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

}

class MapManyTests: XCTestCase {
fileprivate func runAndObserve<C: Collection>(_ sequence: Observable<C>) -> TestableObserver<C> {
Copy link
Member

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 {
Copy link
Member

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

@freak4pc
Copy link
Member

freak4pc commented May 7, 2018

@jdisho Did a bit of cleanup, let me know what you think :)
I'll do another pass of review tomorrow.

Also noticed some issue with toSortedArray playground page and missing CHANGELOG entry.

@freak4pc
Copy link
Member

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.

@jdisho
Copy link
Contributor Author

jdisho commented Jul 8, 2018

Can this operator be merged anytime soon @freak4pc ? 😊

Sent with GitHawk

@freak4pc
Copy link
Member

freak4pc commented Jul 8, 2018

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.

@jdisho
Copy link
Contributor Author

jdisho commented Jul 8, 2018

I can update the documentation in a separate PR.

@freak4pc
Copy link
Member

freak4pc commented Jul 8, 2018

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 :)

@freak4pc
Copy link
Member

freak4pc commented Jul 8, 2018

Something with your tests seem wrong, can you look into that?

5baeac03-cf2c-4959-8ec1-e0a5b3e3cc55

@jdisho
Copy link
Contributor Author

jdisho commented Jul 8, 2018

Strange, CI is successfully passed.😕

@freak4pc
Copy link
Member

freak4pc commented Jul 8, 2018

Yeah, the fact CI passes is a bug that you should ignore - but the build clearly fails

@freak4pc
Copy link
Member

freak4pc commented Jul 8, 2018

Ok, so CI is fixed - now time to fix your tests :) @jdisho

@freak4pc freak4pc force-pushed the feature/mapMany branch 2 times, most recently from c672c14 to 7a9135b Compare July 8, 2018 14:55
@jdisho
Copy link
Contributor Author

jdisho commented Jul 8, 2018

I don't understand, the test passed in Xcode 😕

@freak4pc
Copy link
Member

freak4pc commented Jul 8, 2018

@jdisho Tried bumping CI Xcode to 9.4.0, lets see if that helps

@jdisho
Copy link
Contributor Author

jdisho commented Jul 8, 2018

Apparently no
screen shot 2018-07-08 at 17 38 02

@freak4pc
Copy link
Member

freak4pc commented Jul 8, 2018

Here we go :) @jdisho

@jdisho jdisho merged commit 0ca281f into master Jul 8, 2018
@freak4pc freak4pc deleted the feature/mapMany branch July 8, 2018 17:59
@freak4pc
Copy link
Member

freak4pc commented Jul 8, 2018

@jdisho Usually the author of the PR should not be the one to merge it, just FYI - but no biggie :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants