无法执行以下类型的选项映射操作:(Boolean,_57)=>R [英] Cannot perform option-mapped operation with type: (Boolean, _57) => R

查看:0
本文介绍了无法执行以下类型的选项映射操作:(Boolean,_57)=>R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个筛选器

type DatabaseID = Long   

val filter = moderators.filter(m =>
          (m.created < before) &&
          (m.userType inSet userTypeList) &&
          (if(true) m.mcID === mcIDFilter else true)
        )

其中m.mcID具有Rep[Option[models.DatabaseID]]类型和mcIDFilterOption[models.DatabaseID]

为什么我收到下一个错误?

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

_57这是什么?

为简单起见,我已将条件替换为true。如果我删除带有条件行或仅用true替换m.mcID === mcIDFilter,代码编译正常。

另外,如果我删除if语句,它编译时不会出现错误:

val filter = moderators.filter(m =>
      (m.created < before) &&
      (m.userType inSet userTypeList) &&
      m.mcID === mcIDFilter
    )

我发现当其中一个操作数类型不是同一类型时,会出现此错误。

我也试过

val filter = moderators.filter(m =>
      (m.created < before) &&
      (m.userType inSet userTypeList) &&
      (if(true) m.mcID === mcIDFilter else true:Rep[Boolean])
    )

但未成功。

推荐答案

好的,我找到了如何编译它。它很难看,但很管用。

val filter = moderators.filter(m =>
      (m.created < before) &&
      (m.userType inSet userTypeList) &&
      (if(true) m.mcID === mcIDFilter else Some(true):Rep[Option[Boolean]])
    )

这篇关于无法执行以下类型的选项映射操作:(Boolean,_57)=&gt;R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆