Iām in search of a method similar to Record.Do
with Record.bind
so I can perform actions like the following:
function getB: (a:A) => B
function getC: (b: B) => C
function getD: (c: C) => D
type Z = {
a: A,
b: B,
c: C,
d: D,
}
const getZ = (a: A): Z => pipe(
R.Do,
R.bind('a', () => a),
R.bind('b', () => getB(a)),
R.bind('c', (bindings) => getC(bindings.b)),
R.bind('d', (bindings) => getD(bindings.c)),
)
The objective is to construct an object containing diverse types while preserving all the inner objects of different types prior to applying certain transformations on them.
I am uncertain about how to achieve this. My intention is not to transport my types to other realms such as Option
, Either
, IO
; as this would involve more code utilizing O.some
(s), E.right
(s), or IO.of
(s) for non-error transformations.
This is the closest approach I could devise:
const getZ = (a: A): Z => pipe(
IO.Do,
IO.bind('a', () => () => a),
IO.bind('b', () => () => getB(a)),
IO.bind('c', (bindings) => () => getC(bindings.b)),
IO.bind('d', (bindings) => () => getD(bindings.c)),
)()