Last active
January 8, 2016 15:52
-
-
Save robnadin/8d01772cf5d241c7248f to your computer and use it in GitHub Desktop.
Custom Swift operators to handle array contents
This file contains 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
// | |
// Array+Operators.swift | |
// | |
// | |
// Created by Rob Nadin on 08/01/2016. | |
// Copyright © 2016 Rob Nadin. All rights reserved. | |
// | |
import Foundation | |
func <<<T>(inout lhs: [T], rhs: T) { | |
lhs.append(rhs) | |
} | |
func <<<T>(inout lhs: [T], rhs: [T]) { | |
lhs.appendContentsOf(rhs) | |
} | |
// MARK: Optionals | |
func <<<T>(inout lhs: [T]?, rhs: T?) { | |
if lhs == nil { | |
lhs = [T]() | |
} | |
if let rhs = rhs { | |
lhs! << rhs | |
} | |
} | |
func <<<T>(inout lhs: [T]?, rhs: [T]?) { | |
if lhs == nil { | |
lhs = [T]() | |
} | |
if let rhs = rhs { | |
lhs! << rhs | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment