Skip to content

Instantly share code, notes, and snippets.

@natecook1000
Created July 19, 2018 06:59
Show Gist options
  • Save natecook1000/86b365d33c215a8459b4064392117231 to your computer and use it in GitHub Desktop.
Save natecook1000/86b365d33c215a8459b4064392117231 to your computer and use it in GitHub Desktop.
// These functions turn nested tuples into flat ones
func munge<T, U, V>(_ x: ((T, U), V)) -> (T, U, V) {
return (x.0.0, x.0.1, x.1)
}
func munge<T, U, V>(_ x: (T, (U, V))) -> (T, U, V) {
return (x.0, x.1.0, x.1.1)
}
func munge<T, U, V, W>(_ x: (T, (U, V, W))) -> (T, U, V, W) {
return (x.0, x.1.0, x.1.1, x.1.2)
}
func munge<T, U, V, W>(_ x: ((T, U, V), W)) -> (T, U, V, W) {
return (x.0.0, x.0.1, x.0.2, x.1)
}
func munge<T, U, V, W>(_ x: ((T, U), (V, W))) -> (T, U, V, W) {
return (x.0.0, x.0.1, x.1.0, x.1.1)
}
func munge<T, U, V, W>(_ x: (T, (U, V), W)) -> (T, U, V, W) {
return (x.0, x.1.0, x.1.1, x.2)
}
func munge<T, U, V, W>(_ x: (((T, U), V), W)) -> (T, U, V, W) {
return munge((munge(x.0), x.1))
}
func munge<T, U, V, W>(_ x: ((T, (U, V)), W)) -> (T, U, V, W) {
return munge((munge(x.0), x.1))
}
func munge<T, U, V, W>(_ x: (T, (U, (V, W)))) -> (T, U, V, W) {
return munge((x.0, munge(x.1)))
}
func munge<T, U, V, W>(_ x: (T, ((U, V), W))) -> (T, U, V, W) {
return munge((x.0, munge(x.1)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment