<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Scala on あんぜんぴんの落書き帳</title>
    <link>https://annpin.com/tags/scala/</link>
    <description>Recent content in Scala on あんぜんぴんの落書き帳</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>ja</language>
    <copyright>© 2018-2024. All rights reserved.</copyright>
    <lastBuildDate>Wed, 17 Sep 2025 18:26:01 +0900</lastBuildDate><atom:link href="https://annpin.com/tags/scala/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Cats でデフォルトで導出される EitherT の Parallel インスタンスはエラーを集積しないという話</title>
      <link>https://annpin.com/posts/2025-09-17-20250917-182649eithert-parallel-instance-for-error-accumulation/</link>
      <pubDate>Wed, 17 Sep 2025 18:26:01 +0900</pubDate>
      
      <guid>https://annpin.com/posts/2025-09-17-20250917-182649eithert-parallel-instance-for-error-accumulation/</guid>
      <description>タイトルの通り. 「 Either ←→ Validated 間で行けるんだから EitherT でも行けるだろう…​」 と思っていたところ見事にハマった.
検索してもあまり説明している人がいなそうなので、とりあえずメモしておく.
TL;DR 自分の使っているエフェクトが F[_] であるならば、以下の 1 行をスコープ中に含めれば良い.
given Parallel[F] = EitherT.accumulatingParallel おわり.
以下は詳細.
Cats では Parallel 型クラスを介して Either と Validated の自動的な変換が提供されている まずは前置き.
例えば、 Scala には「エラーの可能性」を表現するデータ型として Either[E, A] 型が用意されている. Either はエラーを表すデータ型 E を固定することで Either[E, *] でモナドを成すため、 flatMap あるいは for 式を用いて複数の Either 値を合成することができる. 例えば、 val ea: Either[E, A] 、 val eb: Either[E, B] 、 val ec: Either[E, C] であるとき、以下のような for 式を書くことができる.
for { a &amp;lt;- ea b &amp;lt;- eb c &amp;lt;- ec } yield { /* a, b, c を使って何か計算 */ } しかし、 ea 、 eb 、 ec の中の 1 つ以上がエラー値である場合、それらのエラーを集めようとすると困ってしまうこととなる.</description>
    </item>
    
  </channel>
</rss>
