| 
									
										
										
										
											2021-02-19 16:28:05 +01:00
										 |  |  | // | 
					
						
							|  |  |  | //  Collection+safe.swift | 
					
						
							| 
									
										
										
										
											2021-06-21 22:42:46 +02:00
										 |  |  | //  mrousavy | 
					
						
							| 
									
										
										
										
											2021-02-19 16:28:05 +01:00
										 |  |  | // | 
					
						
							|  |  |  | //  Created by Marc Rousavy on 10.01.21. | 
					
						
							| 
									
										
										
										
											2021-06-01 13:07:57 +02:00
										 |  |  | //  Copyright © 2021 mrousavy. All rights reserved. | 
					
						
							| 
									
										
										
										
											2021-02-19 16:28:05 +01:00
										 |  |  | // | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import Foundation | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extension Collection { | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    Returns the element at the specified index if it is within bounds, otherwise nil. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   subscript(safe index: Index) -> Element? { | 
					
						
							|  |  |  |     return indices.contains(index) ? self[index] : nil | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |