Skip to content

Instantly share code, notes, and snippets.

@frgomes
Last active April 29, 2016 13:49
Show Gist options
  • Select an option

  • Save frgomes/7e38d9a30b31792a44a9791b766b93f7 to your computer and use it in GitHub Desktop.

Select an option

Save frgomes/7e38d9a30b31792a44a9791b766b93f7 to your computer and use it in GitHub Desktop.
Scala - Dynamically mixin a trait to an instance
/** This is a marker trait intended to provide independence of FIX version. */
trait SecurityListLike extends quickfix.Message
object SecurityListLike {
implicit def mixin(o: Mixin) = o.o
def ::(o: quickfix.Message) = new Mixin(o)
final class Mixin private[SecurityListLike](val o: quickfix.Message) extends SecurityListLike {
import quickfix.field.MsgType
require(o.getHeader.getString(MsgType.FIELD) == MsgType.SECURITY_LIST)
}
}
@frgomes
Copy link
Author

frgomes commented Apr 29, 2016

Usage:

val message: quickfix.Message = getMessageFromSomewhere
val x: SecurityListLike = message :: SecurityListLike

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment