Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Variable Mapping #95

Merged
merged 2 commits into from Aug 15, 2018
Merged

Variable Mapping #95

merged 2 commits into from Aug 15, 2018

Conversation

bastienFalcou
Copy link
Contributor

I am suggesting this addition to Snail. This allows to map a Unique<T> into a Unique<U> that will receive the same notifications, with the value transformed from its initial type T to the expected new type U.

This is useful for me here when I use:

public enum ValidationField {
    case binding(Variable<String?>) // expects a Variable of type <String?>
    // ...
}

But in my case, I need to bind viewModel.showingAgent which is of type Unique<FullContact?>. I don't want to create a new enumeration member taking that type specifically. I prefer to reuse that existing enumeration member and map viewModel.showingAgent into a Unique<String?>.

I think this could be useful in multiple places as well along the way 馃憤

@bastienFalcou
Copy link
Contributor Author

Note: another suggestion of enhancement could be to support the Swift error handling system by adding the following:

func map<U>(transform: @escaping (T) throws -> U) rethrows -> Unique<U>

This would allow to handle throwing from the map closure, and would be consistent with the native map signature implemented by Foundation on the Collection protocol:

func map<T>(_ transform: (Element) throws -> T) rethrows -> [T]

This change will require to make onNext, onError and onDone support throws. I gave it a quick try and it seems like it will be quite an extensive change. Will keep that for the future, in another Pull Request 馃憤

@codecov-io
Copy link

codecov-io commented Aug 15, 2018

Codecov Report

Merging #95 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #95   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           7      7           
  Lines         160    164    +4     
=====================================
+ Hits          160    164    +4
Impacted Files Coverage 螖
Snail/Variable.swift 100% <100%> (酶) 猬嗭笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 7b280dd...f1e90bc. Read the comment docs.

@wesbillman wesbillman merged commit 18e73fb into master Aug 15, 2018
@wesbillman wesbillman deleted the variable-map branch August 15, 2018 13:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants