Вы можете использовать сумму с тегами . Например:
// Generic functions
// B is the function compose combinator
const B = g => f => x => g (f (x))
const taggedSum = xs => Object.fromEntries (
xs.map(tag => [tag, value => ({ tag, value })])
)
const cata = matches => ({ tag, value }) => matches[tag] (value)
/////////////////////////
const Kind = taggedSum (['pipeline', 'ticket', 'product', 'local' ])
const path = cata ({
pipeline: x => `/pipeline/${x}`,
ticket: x => `/ticket/${x}`,
product: x => `/product/${x}`,
local: () => `/pipeline/local`
})
const output1 = B (path) (Kind.pipeline) (1)
const output2 = B (path) (Kind.ticket) (14)
const output3 = B (path) (Kind.product) (3421)
const output4 = B (path) (Kind.local) (0)
console.log ('pipeline:', output1)
console.log ('ticket:', output2)
console.log ('product:', output3)
console.log ('local:', output4)