@@ -9,6 +9,7 @@ import type { TypeLambda } from "./HKT.js"
99import type { Inspectable } from "./Inspectable.js"
1010import * as doNotation from "./internal/doNotation.js"
1111import * as either from "./internal/either.js"
12+ import * as option_ from "./internal/option.js"
1213import type { Option } from "./Option.js"
1314import type { Pipeable } from "./Pipeable.js"
1415import type { Predicate , Refinement } from "./Predicate.js"
@@ -966,3 +967,38 @@ export {
966967 */
967968 let_ as let
968969}
970+
971+ /**
972+ * Converts an `Option` of an `Either` into an `Either` of an `Option`.
973+ *
974+ * **Details**
975+ *
976+ * This function transforms an `Option<Either<A, E>>` into an
977+ * `Either<Option<A>, E>`. If the `Option` is `None`, the resulting `Either`
978+ * will be a `Right` with a `None` value. If the `Option` is `Some`, the
979+ * inner `Either` will be executed, and its result wrapped in a `Some`.
980+ *
981+ * @example
982+ * ```ts
983+ * import { Effect, Either, Option } from "effect"
984+ *
985+ * // ┌─── Option<Either<number, never>>
986+ * // ▼
987+ * const maybe = Option.some(Either.right(42))
988+ *
989+ * // ┌─── Either<Option<number>, never, never>
990+ * // ▼
991+ * const result = Either.transposeOption(maybe)
992+ *
993+ * console.log(Effect.runSync(result))
994+ * // Output: { _id: 'Option', _tag: 'Some', value: 42 }
995+ * ```
996+ *
997+ * @since 3.14.0
998+ * @category Optional Wrapping & Unwrapping
999+ */
1000+ export const transposeOption = < A = never , E = never > (
1001+ self : Option < Either < A , E > >
1002+ ) : Either < Option < A > , E > => {
1003+ return option_ . isNone ( self ) ? right ( option_ . none ) : map ( self . value , option_ . some )
1004+ }
0 commit comments