我试图通过猫电子书的scala中的一个简单示例。这是我的代码
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="cat-dropdown closed">
<div class="edit">
<label class="title">
<input class="edit-input1" type="checkbox"><span> Choose...</span>
</label>
<div class="cat-dropdown-menu">
<div class="cat-list" id="category">
<label class="cat-item" style="color:blue">
<input type="radio" name="cat1">Main 1</label>
<label class="cat-item" style="color:red">
<input type="radio" name="cat2">Main 2</label>
</div>
</div>
</div>
</div>
Sub Category:
<div id="subcategory">
<div class="sub-list main1" for="cat1">
<input type="radio" name="sub1" value="opt1">main1 opt1
<input type="radio" name="sub1" value="opt2">main1 opt2
<input type="radio" name="sub1" value="opt3">main1 opt3
</div>
<div class="sub-list main2" for="cat2">
<input type="radio" name="sub2" value="opt1">main2 opt1
<input type="radio" name="sub2" value="opt2">main2 opt2
<input type="radio" name="sub2" value="opt3">main1 opt3
</div>
</div>
我收到错误
import cats.Semigroupal
import cats.instances.option._
import cats.syntax.apply._
import cats.implicits._
case class Name(fName: String, lName: String)
(Some("foo"), Some("bar")).mapN(Name.apply)
我也试过导入
cmd4.sc:1: could not find implicit value for parameter functor: cats.Functor[Some]
val res4 = (Some("foo"), Some("bar")).mapN(Name.apply)
答案 0 :(得分:2)
问题是Functor在其类型参数中是不变的,因此您需要使Scala编译器将元组的类型视为(Option[String], Option[String])
而不是(Some[String], Some[String])
。您可以使用
("foo".some, "bar".some).mapN(Name.apply)