shuffled(using:)
を試しているのですが、型にProcotolを書くと通らない... import Foundation class A: RandomNumberGenerator {} var a: RandomNumberGenerator = A() [1, 2, 3].shuffled(using: &a) // error: argument passed to call that takes no arguments // [1, 2, 3].shuffled(using: &a) var b = A() [1, 2, 3].shuffled(using: &b) // Success
shuffled
と似たような関数を自分で書くとimport Foundation func shuffled<T>(using generator: inout T) -> [Int] where T : RandomNumberGenerator { return [] } class A: RandomNumberGenerator {} var a: RandomNumberGenerator = A() shuffled(using: &a) // error: in argument type 'inout RandomNumberGenerator', 'RandomNumberGenerator' does not conform to expected type 'RandomNumberGenerator' // shuffled(using: &a) ^
'RandomNumberGenerator' does not conform to expected type 'RandomNumberGenerator'
ってなんだ...