Skip to content

Instantly share code, notes, and snippets.

@mgadda
Created December 28, 2019 02:45
Show Gist options
  • Save mgadda/6e1e0a861279213c6bac79416ce5d2e2 to your computer and use it in GitHub Desktop.
Save mgadda/6e1e0a861279213c6bac79416ce5d2e2 to your computer and use it in GitHub Desktop.
protocol IO {
associatedtype CollectionType: Collection
init(_ source: CollectionType)
func go() -> AnyCollection<CollectionType.Element>
}
struct Print<T> : IO where T: Collection {
typealias CollectionType = T
let source: CollectionType
init(_ source: T) {
self.source = source
}
func go() -> AnyCollection<T.Element>? {
if let first = source.first {
print(first)
return AnyCollection(source).dropFirst()
}
return nil
}
}
Print().apply("abc")
struct AndThen<T: IO> : IO where T: Collection {
typealias CollectionType = T.CollectionType
let left: T
let right: T
init(_ left: T, _ right: T) {
self.left = left
self.right = right
}
func go() -> AnyCollection<T.CollectionType.Element> {
<#code#>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment