Skip to content

Instantly share code, notes, and snippets.

@pcperini
Created February 8, 2016 16:58
Show Gist options
  • Save pcperini/5a8ea37e8cbbe904a031 to your computer and use it in GitHub Desktop.
Save pcperini/5a8ea37e8cbbe904a031 to your computer and use it in GitHub Desktop.
public extension CollectionType {
// MARK: Flatteners
public func flatten(path: (Self.Generator.Element) -> [Self.Generator.Element]) -> [Self.Generator.Element] {
guard !self.isEmpty else { return [] }
return self + self.flatMap { path($0).flatten(path) }
}
}
public extension UIView {
// MARK: Properties
public var flatSubviews: [UIView] {
return self.subviews.flatten { $0.subviews }
}
public var flatConstraints: [NSLayoutConstraint] {
return (self.flatSubviews + [self]).flatMap { $0.constraints }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment