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

Parse string function #65

Merged
merged 9 commits into from
Oct 1, 2017
Merged

Parse string function #65

merged 9 commits into from
Oct 1, 2017

Conversation

Antondomashnev
Copy link
Contributor

This resolves #64, but with one tweak, I've realised that CustomStringConvertible is too broad protocol, that has many adoptions which not really a fit to be a filter parameter, so I used LosslessStringConvertible. I think it's a good tradeoff between making input not that strict, but still with some sense.

Regarding the functions I've tried to follow the pattern in Filters.swift but I had to introduce two functions - parse array of Any? and just Any? as it reduced the possible boilerplate code. I've also tried to use the same name for these two functions:

func parseString(from value: Any?) throws -> String
func parseString(from arguments: [Any?], at index: Int = 0) throws -> String

but it lead to confusion for compiler as Any? could be anything, also an array of Any? 😄

I thought maybe we can have an Extractor instead of having these functions in Filters, what do you think?

CHANGELOG.md Outdated
_None_
* Accept `LosslessStringConvertible` input for strings filters.
[Antondomashnev](https://github.com/antondomashnev)
[#59](https://github.com/SwiftGen/StencilSwiftKit/pull/63)
Copy link
Member

Choose a reason for hiding this comment

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

Please correct this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I've also corrected previous entry, I think we missed it during the review of #63.
Check ad8c792

/// - arguments: an array of argument values, may be empty
/// - index: the index in the arguments array
/// - Throws: Filters.Error.invalidInputType
static func parseStringArgument(from arguments: [Any?], at index: Int = 0) throws -> String {
Copy link
Member

Choose a reason for hiding this comment

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

To keep the naming consistent with the other filters, we could consider making the index mandatory (no default value). And modify the other parse argument functions (bool/enum) to require an index as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly I don't see the benefit for this, we'll increase the number of repeatable code in order to have naming consistency. I think it doesn't worth it 😄

@djbe djbe changed the title Parse string function; Parse string function Aug 29, 2017
@Antondomashnev
Copy link
Contributor Author

Antondomashnev commented Sep 21, 2017

@djbe @AliSoftware ping 😄

@AliSoftware AliSoftware merged commit aa9646f into master Oct 1, 2017
@AliSoftware AliSoftware deleted the parse_string branch October 1, 2017 18:38
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.

Allow to use strings filters on CustomStringConvertable
3 participants