Skip to content

mapRights

mapRights<Xs, T>(xs, f): ArgRights<Xs> extends never[] ? Left<ArgLefts<Xs>[number]> : ArgLefts<Xs>[number] extends never[] ? Right<T> : Left<ArgLefts<Xs>[number]> | Right<T>

mapRights takes a tuple of Eithers and a function that takes the right values of the Eithers and returns a new Either that is either the left value of the first Either in the tuple or the result of the function

Example

mapRights([{ right: 'foo' }, { right: 'bar' }], ([x0, x1]) => `${x0}${x1}`)
// => { right: "foobar" }
mapRights([{ left: 'bar' }, { right: 'fooz' }], ([x0, x1]) => `${x0}${x1}`)
// => { left: "bar" }

Type Parameters

Xs extends Either<unknown, unknown>[]

T

The mapped type.

Parameters

xs

readonly [Xs]

The either values to map.

f

(rs) => T

The map function.

Returns

ArgRights<Xs> extends never[] ? Left<ArgLefts<Xs>[number]> : ArgLefts<Xs>[number] extends never[] ? Right<T> : Left<ArgLefts<Xs>[number]> | Right<T>

The mapped either object.