As you know casbah mongodb driver has an update function like this :
def update [A, B] (q: A, o: B)(implicit arg0: (A) ⇒ DBObject, arg1: (B) ⇒ DBObject) : WriteResult
I think i understand currying concept of scala. However, As far as I know this update function is supposed to be used like this :
collection.update(MongoDBObject(...), MongoDBObject(...))
This confuses me. As I do not fill second argument list of the update method, I would think above expression would return a function like :
(implicit arg0: (A) ⇒ DBObject, arg1: (B) ⇒ DBObject) => WriteResult
However it does not. Is it because of the implicit definiton for the arguments in the second function argument list ?
The Casbah library subscribes to the "pimp my library" pattern. It extends the official MongoDB Java driver and adds implicits and other functionality to make using the Java driver feel "native" in scala.
The
update
method looks like this:The Java driver requires
DBObject
for its update operation, but Casbah provides a Scala helper for creating DBObjects inMongoDBObject
. To provide interop between the Scala types and the Java type we can make use of implicit parameters.As the compiler will know
A
at compile time, it can determine whether an implicit definition oftype A => DBObject
is in scope. Casbah then uses that methodqueryView(q)
which convertsq
toDBObject
and passes it to the underlying update.