Skip to content

Instantly share code, notes, and snippets.

@gwennguihal
Created October 1, 2019 07:14
Show Gist options
  • Save gwennguihal/b18ae6b2e5e0e36468920eb47e3ff985 to your computer and use it in GitHub Desktop.
Save gwennguihal/b18ae6b2e5e0e36468920eb47e3ff985 to your computer and use it in GitHub Desktop.
public struct IfLet<T: OptionalType>: Content {
let data: T
let builder: (T.Wrapped) -> Content
public init(_ data: T, @ContentBuilder _ builder: @escaping (T.Wrapped) -> Content) {
self.data = data
self.builder = builder
}
public var contents: [Content]? {
guard let value = data.value else {
return nil
}
return [builder(value)]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment