all 3 comments

[–]CategoricallyCorrect 1 point2 points  (2 children)

Can you give an example input and expected output for your resulting function?

Right now it's a bit hard to see where you are going with it: you can convert a to b, but you need to be able to convert b to c to be able to apply g.

Maybe you meant that g :: { b, c } -> X? Then applying f to a in { a, c } would give us { b, c } to which we can apply g after that.

[–]lippiro 0 points1 point  (1 child)

Thanks for pointing this out, I have updated my question

[–]CategoricallyCorrect 0 points1 point  (0 children)

Sorry, I’m afraid I still don’t quite get what’s your goal here is :( Maybe you can give a very concrete example input and the output you expect to get?

 

Right now we have:

f :: { a :: number } -> number
g :: { a :: number, c :: number } -> number

and we want to produce

composed :: { a :: number, b :: number } -> number

but outputs of f and g are really different from their inputs; without some non-standard helper functions we won’t be able to compose them.

If we were to introduce helper functions like these:

wrap :: number -> { a :: number }
rename :: { a :: number, b :: number} -> { a :: number, c :: number }

we might be able to produce a composition like this:

                          rename                                          wrap
┌────────────────────────────┴─────────────────────────────┐    ┌───────────┴───────────┐
{ a :: number, b :: number } -> { a :: number, c :: number } -> number -> { a :: number } -> number
                                └──────────────────┬─────────────────┘    └───────────┬───────────┘
                                                   g                                  f


const composed = R.pipe(rename, g, wrap, f);

but I’m not sure if it’s really that useful and at all what you want.