Skip to content

Commit bbf0ace

Browse files
Added cast extension for collections.
1 parent 7c334df commit bbf0ace

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

onixlabs-corda-core-contract/src/main/kotlin/io/onixlabs/corda/core/contract/Extensions.StateAndRef.kt

+11
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,14 @@ import net.corda.core.contracts.TransactionState
3030
inline fun <reified T> StateAndRef<*>.cast(): StateAndRef<T> where T : ContractState = with(state) {
3131
StateAndRef(TransactionState(T::class.java.cast(data), contract, notary, encumbrance, constraint), ref)
3232
}
33+
34+
/**
35+
* Casts an iterable of [StateAndRef] of an unknown [ContractState] to a list of [StateAndRef] of type [T].
36+
*
37+
* @param T The underlying [ContractState] type to cast to.
38+
* @return Returns a list of [StateAndRef] of type [T].
39+
* @throws ClassCastException if the unknown [ContractState] type cannot be cast to [T].
40+
*/
41+
inline fun <reified T> Iterable<StateAndRef<*>>.cast(): List<StateAndRef<T>> where T : ContractState {
42+
return map { it.cast<T>() }
43+
}

0 commit comments

Comments
 (0)