我正在尝试使用Scalacheck生成随机数据.我有一个包含许多属性的case类的层次结构.我到目前为止找到填充案例类的唯一方法是这样的:
case class Data(a: String,
b: String,
c: String)
val genLigneDecompte: Gen[Data] = for {
ag <- Gen.alphaStr
bg <- Gen.alphaStr
cg <- Gen.alphaStr
} yield Data(
a = ag,
b = bg,
c = cg
)
Run Code Online (Sandbox Code Playgroud)
对于具有10-20个属性的案例类,这非常繁琐.我想知道是否有办法以某种方式自动化它...
我在NixOS下工作,到目前为止我都喜欢它.
对于我的编码项目,我正在尝试实现单独的开发环境.因此,例如对于我的Scala/node.js项目,我为nix-shell编写了default.nix:
with import <nixpkgs> {}; {
tarifs2Env = stdenv.mkDerivation {
name = "webapp";
buildInputs = with pkgs; [
sbt
nodejs
nodePackages.gulp
];
shellHook = ''
'';
};
}
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.现在我想添加一个数据库,例如posgtres.有没有办法将服务添加到nix-shell?
我正在尝试使用Kleisli编写返回monad的函数。它适用于Option:
import cats.data.Kleisli
import cats.implicits._
object KleisliOptionEx extends App {
case class Failure(msg: String)
sealed trait Context
case class Initial(age: Int) extends Context
case class AgeCategory(cagetory: String, t: Int) extends Context
case class AgeSquared(s: String, t: Int, u: Int) extends Context
type Result[A, B] = Kleisli[Option, A, B]
val ageCategory: Result[Initial,AgeCategory] =
Kleisli {
case Initial(age) if age < 18 => {
Some(AgeCategory("Teen", age))
}
}
val ageSquared: Result[AgeCategory, AgeSquared] = Kleisli {
case AgeCategory(category, age) => Some(AgeSquared(category, age, age …Run Code Online (Sandbox Code Playgroud)