2019-10-11から1日間の記事一覧

implicit classes

https://docs.scala-lang.org/overviews/core/implicit-classes.html ここみればだいたい分かるが、、、

CanBuildFrom

TraversableLikeの暗黙パラメータにおったやつ こんなん //A -> a private implicit class Converter(l: Traversable[A]) { //https://gamaspecial.hatenablog.com/entry/2019/10/11/165653 def to: Seq[a] = l.map( r => a( value = r.value ) )(collection…

Unit

val u1 = () // => u1: Unit = () val u2 = Unit // => u2: Unit.type = object scala.Unit Unitは、Unitオブジェクトらしい

Trait

先ほど例で使用したfunc変数は「(Int,Int) => Int」という型を宣言していましたが、次のように記述しても同様の関数オブジェクトが定義可能です。 ``` scala> val func:Function2[Int,Int,Int] = (x:Int, y:Int) => x + yfunc: (Int, Int) => Int = <function2> ```この</function2>…

型パラメータ

型パラメータ def post: Action[Request] = Action.async(DtoParser.parse[Request]) { implicit request => final def async[A](bodyParser: BodyParser[A])(block: R[A] => Future[Result]): Action[A] = composeAction(new Action[A] { def executionCont…

toNel

List#toNel NotEmptyListを返す。 NonEmptyListを使えば空リストでは無いことが保証されるのでhead, tailが必ず成功する。 reduceLeft, reduceRightでも同様に確実に成功する。 val hoges = List(hoge1, hoge2) //def toNel: Option[NonEmptyList[A]] = l.to…