How Does RXSwift combineLatest Use, What Looks Like, An Anonymous Class In A Closure And Handle Additional...
So far as I understand it, Swift does not support anonymous classes.
I am working with an RXSwift codebase and there is a block of code I cannot fully grasp what is going on.
Here is the block:
sections = Observable.combineLatest(observable1,
observable2,
observable3)
{
(arg1: $1,
arg2: $0.0,
arg3: $0.1,
arg4: $2)
}
.map { arg1, arg2, arg3, arg4 -> [Section] in
// Do Stuff
}
The issue I have is the block where it converts the combineLatest into this, what looks like, anonymous class.
When I look at the signature for combineLatest it shows:
public static func combineLatest<O1, O2, O3>(_ source1: O1, _ source2: O2, _ source3: O3, resultSelector: @escaping (O1.E, O2.E, O3.E) throws -> Self.E) -> RxSwift.Observable<Self.E> where O1 : ObservableType, O2 : ObservableType, O3 : ObservableType
So as I read it, the @escaping closing takes in 3 arguments via the @escaping (O1.E, O2.E, O3.E)
It seems like a new anonymous object is being created, and its one with 4 arguments instead of 3.
Could you perhaps explain how a new observable of a seemingly anonymous class (which I don't fully understand as being possible) is being created, and being created with 4 arguments instead of 3?
swift observable rx-swift combinelatest
add a comment |
So far as I understand it, Swift does not support anonymous classes.
I am working with an RXSwift codebase and there is a block of code I cannot fully grasp what is going on.
Here is the block:
sections = Observable.combineLatest(observable1,
observable2,
observable3)
{
(arg1: $1,
arg2: $0.0,
arg3: $0.1,
arg4: $2)
}
.map { arg1, arg2, arg3, arg4 -> [Section] in
// Do Stuff
}
The issue I have is the block where it converts the combineLatest into this, what looks like, anonymous class.
When I look at the signature for combineLatest it shows:
public static func combineLatest<O1, O2, O3>(_ source1: O1, _ source2: O2, _ source3: O3, resultSelector: @escaping (O1.E, O2.E, O3.E) throws -> Self.E) -> RxSwift.Observable<Self.E> where O1 : ObservableType, O2 : ObservableType, O3 : ObservableType
So as I read it, the @escaping closing takes in 3 arguments via the @escaping (O1.E, O2.E, O3.E)
It seems like a new anonymous object is being created, and its one with 4 arguments instead of 3.
Could you perhaps explain how a new observable of a seemingly anonymous class (which I don't fully understand as being possible) is being created, and being created with 4 arguments instead of 3?
swift observable rx-swift combinelatest
Are you talking about the(arg1: $1, arg2: $0.0, arg3: $0.1, arg4: $2)
part?
– Sven
Nov 21 '18 at 18:48
Yes, isn't that creating a new object with 4 parameters? I don't understand how this is possible
– Aggressor
Nov 21 '18 at 18:51
add a comment |
So far as I understand it, Swift does not support anonymous classes.
I am working with an RXSwift codebase and there is a block of code I cannot fully grasp what is going on.
Here is the block:
sections = Observable.combineLatest(observable1,
observable2,
observable3)
{
(arg1: $1,
arg2: $0.0,
arg3: $0.1,
arg4: $2)
}
.map { arg1, arg2, arg3, arg4 -> [Section] in
// Do Stuff
}
The issue I have is the block where it converts the combineLatest into this, what looks like, anonymous class.
When I look at the signature for combineLatest it shows:
public static func combineLatest<O1, O2, O3>(_ source1: O1, _ source2: O2, _ source3: O3, resultSelector: @escaping (O1.E, O2.E, O3.E) throws -> Self.E) -> RxSwift.Observable<Self.E> where O1 : ObservableType, O2 : ObservableType, O3 : ObservableType
So as I read it, the @escaping closing takes in 3 arguments via the @escaping (O1.E, O2.E, O3.E)
It seems like a new anonymous object is being created, and its one with 4 arguments instead of 3.
Could you perhaps explain how a new observable of a seemingly anonymous class (which I don't fully understand as being possible) is being created, and being created with 4 arguments instead of 3?
swift observable rx-swift combinelatest
So far as I understand it, Swift does not support anonymous classes.
I am working with an RXSwift codebase and there is a block of code I cannot fully grasp what is going on.
Here is the block:
sections = Observable.combineLatest(observable1,
observable2,
observable3)
{
(arg1: $1,
arg2: $0.0,
arg3: $0.1,
arg4: $2)
}
.map { arg1, arg2, arg3, arg4 -> [Section] in
// Do Stuff
}
The issue I have is the block where it converts the combineLatest into this, what looks like, anonymous class.
When I look at the signature for combineLatest it shows:
public static func combineLatest<O1, O2, O3>(_ source1: O1, _ source2: O2, _ source3: O3, resultSelector: @escaping (O1.E, O2.E, O3.E) throws -> Self.E) -> RxSwift.Observable<Self.E> where O1 : ObservableType, O2 : ObservableType, O3 : ObservableType
So as I read it, the @escaping closing takes in 3 arguments via the @escaping (O1.E, O2.E, O3.E)
It seems like a new anonymous object is being created, and its one with 4 arguments instead of 3.
Could you perhaps explain how a new observable of a seemingly anonymous class (which I don't fully understand as being possible) is being created, and being created with 4 arguments instead of 3?
swift observable rx-swift combinelatest
swift observable rx-swift combinelatest
asked Nov 21 '18 at 18:42
AggressorAggressor
7,5631672133
7,5631672133
Are you talking about the(arg1: $1, arg2: $0.0, arg3: $0.1, arg4: $2)
part?
– Sven
Nov 21 '18 at 18:48
Yes, isn't that creating a new object with 4 parameters? I don't understand how this is possible
– Aggressor
Nov 21 '18 at 18:51
add a comment |
Are you talking about the(arg1: $1, arg2: $0.0, arg3: $0.1, arg4: $2)
part?
– Sven
Nov 21 '18 at 18:48
Yes, isn't that creating a new object with 4 parameters? I don't understand how this is possible
– Aggressor
Nov 21 '18 at 18:51
Are you talking about the
(arg1: $1, arg2: $0.0, arg3: $0.1, arg4: $2)
part?– Sven
Nov 21 '18 at 18:48
Are you talking about the
(arg1: $1, arg2: $0.0, arg3: $0.1, arg4: $2)
part?– Sven
Nov 21 '18 at 18:48
Yes, isn't that creating a new object with 4 parameters? I don't understand how this is possible
– Aggressor
Nov 21 '18 at 18:51
Yes, isn't that creating a new object with 4 parameters? I don't understand how this is possible
– Aggressor
Nov 21 '18 at 18:51
add a comment |
1 Answer
1
active
oldest
votes
The (arg1: $1, arg2: $0.0, arg3: $0.1, arg4: $2)
part inside the closure creates a Tuple. A tuple is a group of multiple values of any type. Each element of a tuple can have a name, but they always can be accessed by number. In your example the tuple has 4 elements with the names arg1, arg2, arg3 and arg4. The elements of a tuple can have any type.
The syntax to create tuples is a list of comma-separated values with optional names inside parenthesis:
let a = (1, "hello", true)
let b = (first: 1, second: "hello", true)
To access the values of a tuple you use a .
followed by the name or index:
print(a.0, a.1, a.2)
print(b.first, b.second, b.2)
let x = b.0
Note that you can also use the index, even if the element is named.
Ah I see, its a Tuple, NOT an anonymous class. Thank you very much for clarifying.
– Aggressor
Nov 21 '18 at 19:54
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418640%2fhow-does-rxswift-combinelatest-use-what-looks-like-an-anonymous-class-in-a-clo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The (arg1: $1, arg2: $0.0, arg3: $0.1, arg4: $2)
part inside the closure creates a Tuple. A tuple is a group of multiple values of any type. Each element of a tuple can have a name, but they always can be accessed by number. In your example the tuple has 4 elements with the names arg1, arg2, arg3 and arg4. The elements of a tuple can have any type.
The syntax to create tuples is a list of comma-separated values with optional names inside parenthesis:
let a = (1, "hello", true)
let b = (first: 1, second: "hello", true)
To access the values of a tuple you use a .
followed by the name or index:
print(a.0, a.1, a.2)
print(b.first, b.second, b.2)
let x = b.0
Note that you can also use the index, even if the element is named.
Ah I see, its a Tuple, NOT an anonymous class. Thank you very much for clarifying.
– Aggressor
Nov 21 '18 at 19:54
add a comment |
The (arg1: $1, arg2: $0.0, arg3: $0.1, arg4: $2)
part inside the closure creates a Tuple. A tuple is a group of multiple values of any type. Each element of a tuple can have a name, but they always can be accessed by number. In your example the tuple has 4 elements with the names arg1, arg2, arg3 and arg4. The elements of a tuple can have any type.
The syntax to create tuples is a list of comma-separated values with optional names inside parenthesis:
let a = (1, "hello", true)
let b = (first: 1, second: "hello", true)
To access the values of a tuple you use a .
followed by the name or index:
print(a.0, a.1, a.2)
print(b.first, b.second, b.2)
let x = b.0
Note that you can also use the index, even if the element is named.
Ah I see, its a Tuple, NOT an anonymous class. Thank you very much for clarifying.
– Aggressor
Nov 21 '18 at 19:54
add a comment |
The (arg1: $1, arg2: $0.0, arg3: $0.1, arg4: $2)
part inside the closure creates a Tuple. A tuple is a group of multiple values of any type. Each element of a tuple can have a name, but they always can be accessed by number. In your example the tuple has 4 elements with the names arg1, arg2, arg3 and arg4. The elements of a tuple can have any type.
The syntax to create tuples is a list of comma-separated values with optional names inside parenthesis:
let a = (1, "hello", true)
let b = (first: 1, second: "hello", true)
To access the values of a tuple you use a .
followed by the name or index:
print(a.0, a.1, a.2)
print(b.first, b.second, b.2)
let x = b.0
Note that you can also use the index, even if the element is named.
The (arg1: $1, arg2: $0.0, arg3: $0.1, arg4: $2)
part inside the closure creates a Tuple. A tuple is a group of multiple values of any type. Each element of a tuple can have a name, but they always can be accessed by number. In your example the tuple has 4 elements with the names arg1, arg2, arg3 and arg4. The elements of a tuple can have any type.
The syntax to create tuples is a list of comma-separated values with optional names inside parenthesis:
let a = (1, "hello", true)
let b = (first: 1, second: "hello", true)
To access the values of a tuple you use a .
followed by the name or index:
print(a.0, a.1, a.2)
print(b.first, b.second, b.2)
let x = b.0
Note that you can also use the index, even if the element is named.
answered Nov 21 '18 at 19:15
SvenSven
20.4k44568
20.4k44568
Ah I see, its a Tuple, NOT an anonymous class. Thank you very much for clarifying.
– Aggressor
Nov 21 '18 at 19:54
add a comment |
Ah I see, its a Tuple, NOT an anonymous class. Thank you very much for clarifying.
– Aggressor
Nov 21 '18 at 19:54
Ah I see, its a Tuple, NOT an anonymous class. Thank you very much for clarifying.
– Aggressor
Nov 21 '18 at 19:54
Ah I see, its a Tuple, NOT an anonymous class. Thank you very much for clarifying.
– Aggressor
Nov 21 '18 at 19:54
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418640%2fhow-does-rxswift-combinelatest-use-what-looks-like-an-anonymous-class-in-a-clo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you talking about the
(arg1: $1, arg2: $0.0, arg3: $0.1, arg4: $2)
part?– Sven
Nov 21 '18 at 18:48
Yes, isn't that creating a new object with 4 parameters? I don't understand how this is possible
– Aggressor
Nov 21 '18 at 18:51