I need to make an Observable with n number of item...
# announcements
s
I need to make an Observable with n number of items in it, but I don't know how to achieve this. Here's the code I'm using as an example:
Copy code
device.establishConnection(false)
    .flatMap(rxBleConnection -> Observable.combineLatest(
        rxBleConnection.readCharacteristic(firstUUID),
        rxBleConnection.readCharacteristic(secondUUID),
        YourModelCombiningTwoValues::new
    ))
    .subscribe(model -> {
        // Process your model.
    });
Here's the code I am trying to write:
Copy code
device.establishConnection(true)
    .flatMap { rxBleConnection ->
        val characteristicReads: MutableList<Single<ByteArray>> =
            mutableListOf()
        for (c in characteristics) {
            characteristicReads.add(rxBleConnection.readCharacteristic(c.uuid))
        }
        Observable.combineLatest(*characteristicReads)
    }
    .subscribe({ onConnectionSuccess(it) }, { onConnectionFailure(it) })
The error is:
Copy code
Type mismatch.
   Required: ObservableSource<out TypeVariable(R)!>!
   Found: Unit
v
Check the signature on Observable.combineLatest(*characteristicReads)
a
don’t you need
*(characteristicReads.toTypedArray())
?
(or use a different method signature that takes a collection rather than a vararg)