Created
December 28, 2019 02:45
-
-
Save mgadda/6e1e0a861279213c6bac79416ce5d2e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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