dfg
dfg2y ago

DanielFGray – 20-58 Jan 8

im using a library with an api like foo.method(...args).run(pool) and i want to abstract it so i dont need to add .run(pool) to every call.. whats the best way to approach this, without having to change anything to the usage except for removing the .run(pool)? is a proxy useful here, or is there something else that doesnt require maintaining a list of methods on the original object?
8 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
dfg
dfgOP2y ago
im not sure how currying would help here, can you give an example?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
dfg
dfgOP2y ago
that would work if i knew what method to use ahead of time, but there are many and i dont want to map them in my own object i want to allow all possible methods without having to code them in my own object
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
dfg
dfgOP2y ago
Types are another matter, I want to replicate the same API foo[method](...args) without needing an object with every method
{
method1(...args) {
return foo.method1(...args).run(pool)
},
method2(...args) {
return foo.method2(...args).run(pool)
},
// yeah I don't wanna do this
}
{
method1(...args) {
return foo.method1(...args).run(pool)
},
method2(...args) {
return foo.method2(...args).run(pool)
},
// yeah I don't wanna do this
}
Pretty sure I need a proxy for this 🤔
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
reactibot
reactibot2y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1061750790068371487