-
Notifications
You must be signed in to change notification settings - Fork 58
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
Conversation
CHANGELOG.md
Outdated
_None_ | ||
* Accept `LosslessStringConvertible` input for strings filters. | ||
[Antondomashnev](https://github.com/antondomashnev) | ||
[#59](https://github.com/SwiftGen/StencilSwiftKit/pull/63) |
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.
Please correct this.
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.
/// - 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 { |
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.
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.
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.
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 @AliSoftware ping 😄 |
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 usedLosslessStringConvertible
. 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 ofAny?
and justAny?
as it reduced the possible boilerplate code. I've also tried to use the same name for these two functions:but it lead to confusion for compiler as
Any?
could be anything, also an array ofAny?
😄I thought maybe we can have an
Extractor
instead of having these functions inFilters
, what do you think?