问题
I have next filter
type DatabaseID = Long
val filter = moderators.filter(m =>
(m.created < before) &&
(m.userType inSet userTypeList) &&
(if(true) m.mcID === mcIDFilter else true)
)
where m.mcID
has Rep[Option[models.DatabaseID]]
type and mcIDFilter
Option[models.DatabaseID]
.
Why i'm getting next error?
Cannot perform option-mapped operation
with type: (Boolean, _57) => R
for base type: (Boolean, Boolean) => Boolean
_57
? What is it?
I have replaced condition with true
for simplicity. If i remove line with condition or replace m.mcID === mcIDFilter
with just true
, code compiles fine.
Also if i remove if
statement, it compiles without error:
val filter = moderators.filter(m =>
(m.created < before) &&
(m.userType inSet userTypeList) &&
m.mcID === mcIDFilter
)
I found that this error appears when type one of operands have not the same type.
I also tried
val filter = moderators.filter(m =>
(m.created < before) &&
(m.userType inSet userTypeList) &&
(if(true) m.mcID === mcIDFilter else true:Rep[Boolean])
)
but without success.
回答1:
Ok, i found how compile this. It's ugly, but work.
val filter = moderators.filter(m =>
(m.created < before) &&
(m.userType inSet userTypeList) &&
(if(true) m.mcID === mcIDFilter else Some(true):Rep[Option[Boolean]])
)
来源:https://stackoverflow.com/questions/41290575/cannot-perform-option-mapped-operation-with-type-boolean-57-r