Validatorに (validateToEitherと同様な)validateToApみたいなのを作らずApplicativeValidatorを別に用意したのは何故なんでしょう?validateToValidationみたいな謎な名前になってしまうから?
- ApplicativeBuilder的な
ComposingNがあるのでFunctionNにcurriedを持たせなくても良さそうですね(実装は泥臭くなりますがオブジェクト生成数を抑制できます)- 逆にカリー化できる関数があると
ComposingNのようなものを不要にできたりもします。 - とは言えYAVIのユースケースだと
Validatorからメソッドチェーンで使うのが主だと思うので、ComposingNの方が有用そうですね。 - 完全に余談ですが、カリー化できる
FunctionNを別途定義するより、curriedを static メソッドにするとcurried(Foo::bar)みたいな使い方が可能になるので個人的にはそちらの方がお勧めです。(Functions的な1クラスのoverloadですませられますし)
- 逆にカリー化できる関数があると
Validation<E, >のapplyがValidation<List<E>, >を返すのがびっくりしますね。Applicative の挙動を期待するなら型としてはValidation<E, >になるので。- YAVI の利用範囲から考えると、エラーの集約方法を汎用化する必要もなさそうなので、error は最初から
Listに決め打ちしちゃってもいいかもしれません。以下のようなイメージです。
Java Stream API で foldLeft/foldRight で宿題にした StackOverflow しない実装の一例です。
面白ポイントとしては、foldRight/foldLeft の実装差分は Function::compose/Function::andThen が Endo::compose/Endo::andThen に変わっただけ、という所ですね。
(注意)ただしこれは不変な List の concat を Stream を使って実装しているため、非常に遅いです。 高速な実装については読者への宿題とします。
https://twitter.com/cero_t/status/1305994285897011200 の話。
Map<String, Integer> someKeyName2ValueName = new LinkedHashMap<>(Map.of(
"foo", 10,
"bar", 20,
"baz", 30
));こちらのツイート https://twitter.com/matarillo/status/1302048512771645440 をみて foldMap か foldLeft で簡単に書けるのでは?と思ったのが発端
case class OrganizationRecord(
id: Long,
organizationLv1: String,class Foo[+A]
class Bar[-A]
class Test1[A] {
def piyo(a: A): Unit = ??? // OK
def poyo(a: Foo[A]): Unit = ??? // OK
def puyo(a: Bar[A]): Unit = ??? // OK
def paya(): A = ??? // OKassociateの例 を Immutable Entity でどうするか
Employee_ e = new Employee_();
Task_ t = new Task_();
Address_ a = new Address_();
Map, Optional>> result = nativeql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object Sample { | |
| implicit def futureEitherTxBoundary[A, B](implicit ec: ExecutionContext): TxBoundary[Future[Either[A, B]]] = new TxBoundary[Future[Either[A, B]]] { | |
| def finishTx(result: Future[Either[A, B]], tx: Tx): Future[Either[A, B]] = { | |
| onFinishTx(result) { | |
| case Success(Right(_)) => tx.commit() | |
| case Success(Left(_)) => tx.rollback() | |
| case Failure(_) => tx.rollback() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package jp.t2v.lab; | |
| import java.util.function.Function; | |
| @FunctionalInterface | |
| public interface MyBiFunc<T, U, R> extends Function<T, Function<U, R>> { | |
| @Override | |
| default Function<U, R> apply(T t) { | |
| return u -> apply(t, u); |
NewerOlder