import Ġkotlinx . coroutines . Global Scope Ċ import Ġkotlinx . coroutines . cancel Children Ċ import Ġkotlinx . coroutines . channels . Channel Ċ import Ġkotlinx . coroutines . channels . Receive Channel Ċ import Ġkotlinx . coroutines . channels . consume Each Ċ import Ġkotlinx . coroutines . channels . produce Ċ import Ġkotlinx . coroutines . run Blocking Ċ Ċ fun Ġmain () = Ġrun Blocking { ĊĠĠĠ Ġval Ġchannel Ġ= Ġfru its () ĊĠĠĠ Ġval Ġfl iter Color Ġ= fl iter Color ( channel ) ĊĠĠĠ Ġval Ġfinal F ruit Ġ= Ġfl iter F ur it ( fl iter Color ) ĊĊĠĠĠ Ġfinal F ruit . consume Each Ġ{ ĊĠĠĠĠĠĠĠ Ġprintln ( Ġ" final Ġ$ it ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġcoroutine Context . cancel Children () Ċ } Ċ data Ġclass ĠF ruit ( val Ġname Ġ: ĠString , Ġval Ġcolor : ĠString Ġ){ ĊĠĠĠ Ġoverride Ġfun ĠtoString (): ĠString Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġname ĊĠĠĠ Ġ} Ċ } Ċ suspend Ġfun Ġfru its () = ĠGlobal Scope . produce < F ruit > Ġ{ ĊĠĠĠ Ġval Ġlist Ġ= ĠlistOf < F ruit >( F ruit (" ba "," Y "), F ruit (" Cu "," R "), F ruit (" St "," R ")) ĊĠĠĠ Ġfor Ġ( fruit Ġin Ġlist ){ ĊĠĠĠĠĠĠĠ Ġprintln (" send $ fruit ") ĊĠĠĠĠĠĠĠ Ġsend ( fruit ) ĊĠĠĠ Ġ} Ċ } Ċ suspend Ġfun Ġfl iter Color ( channel : ĠReceive Channel < F ruit >): Receive Channel < F ruit > Ġ= ĠGlobal Scope . produce Ġ{ ĊĠĠĠ Ġfor Ġ( Ġfruit Ġin Ġchannel ){ ĊĠĠĠĠĠĠĠ Ġif Ġ( fruit . color . equals (" R ")) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġprintln (" col Ġ$ fruit ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsend ( fruit ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ suspend Ġfun Ġfl iter F ur it ( channel : ĠReceive Channel < F ruit >): Receive Channel < F ruit > Ġ= ĠGlobal Scope . produce Ġ{ ĊĠĠĠ Ġfor Ġ( Ġf ur it Ġin Ġchannel ){ ĊĠĠĠĠĠĠĠ Ġif Ġ( f ur it . name . equals (" St ")) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġprintln (" fruit Ġ$ f ur it ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsend ( f ur it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ