package Ġio . red green . on ew ay . catalog ue . signup . use cases Ċ Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . Observable Source Ċ import Ġio . reactivex . Observable Transformer Ċ import Ġio . reactivex . rx kotlin . with Latest From Ċ import Ġio . red green . on ew ay . catalog ue . signup . Enter Input Int ention Ċ import Ġio . red green . on ew ay . catalog ue . signup . Lo se Focus Int ention Ċ import Ġio . red green . on ew ay . catalog ue . signup . SignUp Int ention Ċ import Ġio . red green . on ew ay . catalog ue . signup . SignUp State Ċ import Ġio . red green . on ew ay . catalog ue . signup . form .* Ċ import Ġio . red green . on ew ay . catalog ue . signup . form . Which Field . PHONE _ NUMBER Ċ import Ġio . red green . on ew ay . catalog ue . signup . form . Which Field . USERNAME Ċ Ċ class ĠValidate Input UseCase ( ĊĠĠĠ Ġprivate Ġval Ġsource Copy : ĠObservable < SignUp State >, ĊĠĠĠ Ġprivate Ġval Ġvalidator : ĠValidator Ċ ) Ġ: ĠObservable Transformer < SignUp Int ention , ĠSign Up State > Ġ{ ĊĠ Ġoverride Ġfun Ġapply ( ĊĠĠĠĠĠ Ġsign Up Intent ions : ĠObservable < SignUp Int ention > ĊĠ Ġ): ĠObservable Source < SignUp State > Ġ{ ĊĠĠĠ Ġval Ġenter Input Intent ions Ġ= Ġsign Up Intent ions ĊĠĠĠĠĠĠĠ Ġ. of Type ( Enter Input Int ention :: class . java ) ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġit . which Field Ġto Ġit . text Ġ} ĊĊĠĠĠ Ġval Ġlose Focus Intent ions Ġ= Ġsign Up Intent ions ĊĠĠĠĠĠĠĠ Ġ. of Type ( Lo se Focus Int ention :: class . java ) ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġit . which Field Ġto Ġit . text Ġ} ĊĊĠĠĠ Ġreturn ĠObservable . merge ( ĊĠĠĠĠĠĠĠ Ġget PhoneNumber Validation States ( enter Input Intent ions ) Ġ{ Ġstate , Ġun met Conditions Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġstate . phoneNumber Un met Conditions ( un met Conditions ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĊĠĠĠĠĠĠĠ Ġget Username Validation States ( enter Input Intent ions ) Ġ{ Ġstate , Ġun met Conditions Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġstate . username Un met Conditions ( un met Conditions ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĊĠĠĠĠĠĠĠ Ġget PhoneNumber Validation States ( lose Focus Intent ions ) Ġ{ Ġstate , Ġun met Conditions Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġstate . phoneNumber Un met Conditions ( un met Conditions ). phoneNumber Display Error ( true ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĊĠĠĠĠĠĠĠ Ġget Username Validation States ( lose Focus Intent ions ) Ġ{ Ġstate , Ġun met Conditions Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġstate . username Un met Conditions ( un met Conditions ). username Display Error ( true ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġget PhoneNumber Validation States ( ĊĠĠĠĠĠ Ġenter Input Intent ions : ĠObservable < Pair < Which Field , ĠString >>, ĊĠĠĠĠĠ Ġstate Reducer : Ġ( SignUp State , ĠSet < PhoneNumber Condition >) Ġ-> ĠSign Up State ĊĠ Ġ): ĠObservable < SignUp State > Ġ{ ĊĠĠĠ Ġreturn Ġvalidate Field ( PHONE _ NUMBER , Ġenter Input Intent ions , Ġstate Reducer ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġget Username Validation States ( ĊĠĠĠĠĠ Ġenter Input Intent ions : ĠObservable < Pair < Which Field , ĠString >>, ĊĠĠĠĠĠ Ġstate Reducer : Ġ( SignUp State , ĠSet < Username Condition >) Ġ-> ĠSign Up State ĊĠ Ġ): ĠObservable < SignUp State > Ġ{ ĊĠĠĠ Ġreturn Ġvalidate Field ( USERNAME , Ġenter Input Intent ions , Ġstate Reducer ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġinline Ġfun Ġ< re ified ĠT > Ġvalidate Field ( ĊĠĠĠĠĠ Ġfield : ĠWhich Field , ĊĠĠĠĠĠ Ġenter Input Intent ions : ĠObservable < Pair < Which Field , ĠString >>, ĊĠĠĠĠĠ Ġcross inline Ġstate Reducer : Ġ( SignUp State , ĠSet < T >) Ġ-> ĠSign Up State ĊĠ Ġ): ĠObservable < SignUp State > Ġwhere ĠT Ġ: ĠEnum < T >, ĠT Ġ: ĠCondition Ġ{ ĊĠĠĠ Ġreturn Ġenter Input Intent ions ĊĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . first Ġ== Ġfield Ġ} ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġvalidator . validate < T >( it . second ) Ġ} ĊĠĠĠĠĠĠĠ Ġ. with Latest From ( source Copy ) Ġ{ Ġun met Conditions , Ġstate Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġstate Reducer ( state , Ġun met Conditions ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ