scala - How can I define a type to present a stream which can provide integers, but also may fail? -


suppose want define "numberloader", load integers place demand, can give type:

type numberloader = stream[integer] 

but may throw errors when loading (say, loads integers via network computer), there should networkerror in type.

finally, defined as:

type numberloader = stream[either[networkerror, integer]] 

if seems work, feel little strange. one?

you want represent

a stream of can either networkerror or integer   stream[                          either[  networkerror,      integer]] 

so type looks appropriate , well-suited.

you can alternatively use future or try in place of either, lose flexibility of specifying kind of exception expect, both future , try failures hold generic throwable.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -