@@ -994,3 +994,47 @@ export const transposeOption = <A = never, E = never>(
994
994
) : Either < Option < A > , E > => {
995
995
return option_ . isNone ( self ) ? right ( option_ . none ) : map ( self . value , option_ . some )
996
996
}
997
+
998
+ /**
999
+ * Applies an `Either` on an `Option` and transposes the result.
1000
+ *
1001
+ * **Details**
1002
+ *
1003
+ * If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.
1004
+ * If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.
1005
+ *
1006
+ * @example
1007
+ * ```ts
1008
+ * import { Either, Option, pipe } from "effect"
1009
+ *
1010
+ * // ┌─── Either<Option<number>, never>>
1011
+ * // ▼
1012
+ * const noneResult = pipe(
1013
+ * Option.none(),
1014
+ * Either.transposeMapOption(() => Either.right(42)) // will not be executed
1015
+ * )
1016
+ * console.log(noneResult)
1017
+ * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }
1018
+ *
1019
+ * // ┌─── Either<Option<number>, never>>
1020
+ * // ▼
1021
+ * const someRightResult = pipe(
1022
+ * Option.some(42),
1023
+ * Either.transposeMapOption((value) => Either.right(value * 2))
1024
+ * )
1025
+ * console.log(someRightResult)
1026
+ * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }
1027
+ * ```
1028
+ *
1029
+ * @since 3.15.0
1030
+ * @category Optional Wrapping & Unwrapping
1031
+ */
1032
+ export const transposeMapOption = dual <
1033
+ < A , B , E = never > (
1034
+ f : ( self : A ) => Either < B , E >
1035
+ ) => ( self : Option < A > ) => Either < Option < B > , E > ,
1036
+ < A , B , E = never > (
1037
+ self : Option < A > ,
1038
+ f : ( self : A ) => Either < B , E >
1039
+ ) => Either < Option < B > , E >
1040
+ > ( 2 , ( self , f ) => option_ . isNone ( self ) ? right ( option_ . none ) : map ( f ( self . value ) , option_ . some ) )
0 commit comments