Cannot perform option-mapped operation with type: (Boolean, _57) => R

☆樱花仙子☆ 提交于 2019-12-23 23:18:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!