Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. protocol AnyArray{}/*<--Neat trick to assert if a value is an Array, use-full in reflection and when the value is Any but really an array*/
  2. extension Array:AnyArray{}//Maybe rename to ArrayType
  3. func recFlatMap<T>(_ arr:[AnyObject]) -> [T]{
  4. var result:[T] = []
  5. Swift.print("arr.count: " + "\(arr.count)")
  6. arr.forEach{
  7. if($0 is AnyArray){
  8. let a:[AnyObject] = $0 as! [AnyObject]
  9. result += recFlatMap(a)
  10. }else{
  11. result.append($0 as! T)
  12. }
  13. }
  14. return result
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement