@@ -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"
@@ -963,3 +964,38 @@ export {
963964 */
964965 let_ as let
965966}
967+
968+ /**
969+ * Converts an `Option` of an `Either` into an `Either` of an `Option`.
970+ *
971+ * **Details**
972+ *
973+ * This function transforms an `Option<Either<A, E>>` into an
974+ * `Either<Option<A>, E>`. If the `Option` is `None`, the resulting `Either`
975+ * will be a `Right` with a `None` value. If the `Option` is `Some`, the
976+ * inner `Either` will be executed, and its result wrapped in a `Some`.
977+ *
978+ * @example
979+ * ```ts
980+ * import { Effect, Either, Option } from "effect"
981+ *
982+ * // ┌─── Option<Either<number, never>>
983+ * // ▼
984+ * const maybe = Option.some(Either.right(42))
985+ *
986+ * // ┌─── Either<Option<number>, never, never>
987+ * // ▼
988+ * const result = Either.transposeOption(maybe)
989+ *
990+ * console.log(Effect.runSync(result))
991+ * // Output: { _id: 'Option', _tag: 'Some', value: 42 }
992+ * ```
993+ *
994+ * @since 3.14.0
995+ * @category Optional Wrapping & Unwrapping
996+ */
997+ export const transposeOption = < A = never , E = never > (
998+ self : Option < Either < A , E > >
999+ ) : Either < Option < A > , E > => {
1000+ return option_ . isNone ( self ) ? right ( option_ . none ) : map ( self . value , option_ . some )
1001+ }
0 commit comments