-
|
I'm hard at work on porting https://github.com/ukushu/Ifrit to Skip Lite, and I've hit a roadblock. public func searchSync<S: Sequence>(_ text: String, in aList: S) -> [FuzzySrchResult] where S.Element == [FuseProp] {When I try to transpile that code, I get an error:
Reading the documentation, I think that error message is supposed to be fixable with a // SKIP DECLARE: open fun searchSync(text: String, in_: Sequence<Array<FuseProp>>): Array<FuzzySrchResult>
public func searchSync<S: Sequence>(_ text: String, in aList: S) -> [FuzzySrchResult] where S.Element == [FuseProp] {But that doesn't work, because You can repro the issue on the A simple How do I fix this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
|
What happens if you try to simplify the declaration to just use an Array? Like: public func searchSync(_ text: String, in aList: [[FuseProp]]) -> [FuzzySrchResult]There might be a way to get the |
Beta Was this translation helpful? Give feedback.
-
|
That works fine; it's what I'm doing on the main branch. public func searchSync(_ text: String, in aList: [[FuseProp]]) -> [FuzzySrchResult] {But that breaks backwards compatibility and prevents the user from passing in a lazy sequence. ( |
Beta Was this translation helpful? Give feedback.
-
|
Note that One way to work around this could be to externalize that constraint as a conditional typealias. Something like: #if !SKIP
typealias SequenceOfStrings<S> = S where S: Sequence, S.Element == [String]
#else
typealias SequenceOfStrings = Sequence<Array<String>>
#endif
public func searchSync<S>(_ text: String, in aList: SequenceOfStrings<S>) -> [FuzzySrchResult] {
}That way you won't need to use a |
Beta Was this translation helpful? Give feedback.
-
|
I did have to use #if !SKIP
public typealias SequenceOfArraysOfFuseProps<S> = S where S: Sequence, S.Element == [FuseProp]
#else
public typealias SequenceOfArraysOfFuseProps = Sequence<Array<FuseProp>>
#endif
// SKIP DECLARE: open fun searchSync(text: String, in_: Sequence<Array<FuseProp>>): Array<FuzzySrchResult>
public func searchSync<S: Sequence>(_ text: String, in aList: SequenceOfArraysOfFuseProps<S>) -> [FuzzySrchResult] { |
Beta Was this translation helpful? Give feedback.
Note that
SKIP DECLARE:does work, but the problem is that Skip is short-circuiting before it is even evaluated because it sees its limitation on the generic constraint. We don't parse the contents ofSKIP DECLARE, so we don't see that it is overcoming the generic constraint limitations by redefining the type parameter.One way to work around this could be to externalize that constraint as a conditional typealias. Something like:
That way y…