scala
Scala の学習用に Ammonite 環境 を AWS EC2 上に構築していて、Scala Exercises の例を試せるように紹介されている cats や shapeless のライブラリを追加していた。ただ、個人的に Ruby を使う機会が圧倒的に多いので pry は必須だし、Go もやってみたいと…
GitHub - kyagi/rod: REPLs On Docker を作っている中で Ammonite の起動が早くなるようにあらかじめライブラリをキャッシュさせておくため .ammonite/predef.sc にライブラリを追加したあとに echo exit | amm -s を実行するようにしたところ、docker build…
Safari Books Online で検索したところ、以下の記述が見つかった。 Disjunction is conceptually similar to Either, which can be used to represent one of two possible types. Disjunction is different from Either because its operations are right-b…
会社の Scala エキスパートから、better-fs, fs2 というライブラリを教えていただいたので書き直してみる。とても短くなりました。(^q^)。 GitHub - pathikrit/better-files: Simple, safe and intuitive Scala I/O ayakumo.hatenablog.com @ import better.…
9.4 WRITING NEW CONTROL STRUCTURES を読んでいて、複数ファイルに対して「ファイルを開いて特定の処理を行う」ことができるはずと思って実装した。Scala でメソッドをメソッドの引数に取るのは HOF(Higher Order Functions) というらしい。 C でいう関数ポ…
だいたい Ammonite に書いてある。Magic Imports はとてもありがたい。 インストール $ sudo curl -L -o /usr/local/bin/amm https://git.io/vdNv2 && sudo chmod +x /usr/local/bin/amm && amm REPL として使う $ amm (... snip the greeting message ...) …
sbt は優秀なツールだけれども、さくっと Scala のスクリプトを書くには Ammonite のほうがお気に入り。シェルからは -c オプションで気軽に Scala をスクリプトとして実行可能。 $ amm -c 'import scala.io.Source; val file = Source.fromFile("/home/kyag…
Singleton objects are sort of a shorthand for defining a single-use class, which can’t directly be instantiated, and a val member at the point of definition of the object, with the same name. Indeed, like vals, singleton objects can be def…
A sequence of cases (i.e., alternatives) in curly braces can be used anywhere a function literal can be used.Essentially, a case sequence is a function literal, only more general. Instead of having a single entry point and list of paramete…
case class は abstract class の派生でなくてもいい。コップ本だと Expr の派生クラスとして UnOp や BinOp クラスを定義しているが別に親がいなくてもいい。 パターンマッチのブロックの中の e はパターンに束縛される一時変数。「この e はどこから出てき…
def の後の body の前に = を置かない場合と置く場合の違いが気になっていた。 = を置かない場合はメソッド/関数の戻り値は Unit になる。 = を置く場合はメソッド/関数の戻り値を任意に指定する。 The equals sign that precedes the body of a function hi…