scala - Option and Future -


i in process of building ubercool application amazing amount of abstractions. going design over-engineered entitygetservice.

first thing want lot of abstract types, let this:

trait entitygetservice[id, entity, container] {   def get(id: id): container } 

container here type of contains (or not contains) requested entity. similar option[entity]. second thing want, container can future[entity].

so want write trait this:

trait entitygetservice[id, entity, container <: wrapper[entity]] {     def get(id: id): container } 

and specify in such ways:

trait entitysyncgetservice[long, entity, option[entity]] {     def get(id: long): option[entity] }  trait entityasyncgetservice[long, entity, future[entity]] {     def get(id: long): future[entity] } 

is there way without re-extending or mixing option , future?

it looks option , future have bit of in common (their both containers). related monads?

or product of insomnia?

not commenting on reasonableness of all, can use higher-order types :

trait wrappedgetservice[id, entity, wrapper[_]] {   def get(id: id) : wrapper[entity] } 

then can declare wrappedgetservice[long, entity, option].

update: references

the feature called higher-order types (possibly higher-kinded types too) or types constructors.

  • in the language specification, should appear in section 4.4, type parameters, there not lot it, works other type parameters.
  • the feature proposed in paper generics of higher kind paper may not implemented in language, should close. on other hand, collection library went way, may see why in fighting bit rot types.
  • you may have @ scalaz library (not faint of heart). if go way, might want have @ haskell too.

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -