SequenceUtils.swift (415B)
1 // 2 // SequenceUtils.swift 3 // damus 4 // 5 // Created by Daniel D’Aquino on 2023-11-24. 6 // 7 8 import Foundation 9 10 extension Sequence { 11 func just_one() -> Element? { 12 var got_one = false 13 var the_x: Element? = nil 14 for x in self { 15 guard !got_one else { 16 return nil 17 } 18 the_x = x 19 got_one = true 20 } 21 return the_x 22 } 23 }