While implementing custom filtering values I has encountered the problem. It is appeared when I tried to combine results from filtered and not-filtered LazySequences.
Here is sample to illustrate the problem:
let queryModulus: Int? = 10 // Sometimes may be **nil**
let values = [1, 2, 3, 4, 5, 6].lazy // Actually comes from **external** source
let filteredValues = queryModulus.map { modulus in
values.filter { $0 % modulus == 0 }
} ?? values // Error appears on this statement
When compiling above snippet compiler gives me error:
.code.tio.swift:4:59: error: cannot convert value of type 'LazyFilterSequence<[Int]>' to closure result type 'LazySequence<[Int]>'
let filteredValues = queryModulus.map { modulus in values.filter { $0 % modulus == 0 } } ?? values // Error appears on this statement
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/srv/wrappers/swift4: line 5: ./.bin.tio: No such file or directory
The question is how to combine results of two expressions?
- filtered one
queryModulus.map { modulus in values.filter { $0 % modulus == 0 } }that has typeLazyFilterSequence<[Int]>? - initial one
valueswith typeLazySequence<[Int]>
With quick research I realized that error appears on any collection.
It means that LazySequence<T> and LazyFilteredSequence<T> is incompatible for Set, and others.
You can try.it