I need a function that takes a sequence Int. Here is what I want to write:
Int
func process(items: Sequence<Int>) { items.forEach { ... } }
Error: "It is not possible to specialize the non-standard type" Sequence ".
Fixed (I think):
func process<S: Sequence>(items: S) where S.Iterator.Element == Int { items.forEach { ... } }
Pretty little more detailed.
I know that the Sequence protocol has an associated type Iteratorthat it has Element. But I'm not quite sure why I have to solve the requirement Intin such a strange way.
Iterator
Element
What are the basic concepts that make the first version inoperable, but the second? What does the error mean?
. . ( " ", " " ) Swift. , Sequence, , . , Sequence - .
Sequence
, , , . . , , , , , . , .
, , Sequence Iterator, IteratorProtocol, turn Element ( ).
Int?
func process(items: [Int]) { items.forEach { ... } }
You can use Variadic Parameters :
func process(items: Int...) { items.forEach { (item) in //do stuff with your 'item' } }
Source: https://habr.com/ru/post/1655857/More articles:Is concatenation possible in the ng model? - angularjsFunction Index with Preset Parameters - cHow can I concatenate the value of an ng model with the value from ng-repeat - javascriptConnect to the Microsoft Exchange IMAP4 messaging service using perl Mail :: IMAPClient - emailReactJS - MouseClick runs without clicking - javascriptКак избавиться от "process_begin: CreateProcess (NULL," ",...) не удалось." сообщение об ошибке в Android Studio 2.2 - androidHow to fix this error "E122: MyDiff function already exists, adds !, To replace it" after I fix the vimrc file? - vimКак установить и обработать язык в режиме реагирования? - urlHow to override boot mixin without changing source code? - mixinsC ++ Preprocessor String Wrapping - c ++All Articles