24 lines
409 B
Swift
24 lines
409 B
Swift
//
|
|
// Array+Extension.swift
|
|
//
|
|
//
|
|
// Created by Juraldinio on 9/15/22.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public extension Array {
|
|
|
|
subscript(safe index: Index) -> Element? {
|
|
return (self.startIndex..<self.endIndex) ~= index ? self[index] : nil
|
|
}
|
|
}
|
|
|
|
public extension Array where Element: Hashable {
|
|
|
|
func distinct() -> Array {
|
|
let set = Set(self)
|
|
return Array(set)
|
|
}
|
|
}
|