Why do i get 'g.call is not a function' error in ramda?

32 views Asked by At

So I have a problem, I have two functions in ramda.js, they look like this:

const getDayName = flip(nth)(['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'])

const formatDay = ifElse(isNil, always(''), pipe(dec, getDayName, i18n.t('views.routing.dialogs.${__}')))

The first function returns name of the day by it's index, and second accepts id of day, if it's null it returns empty string, otherwise it decreaces id by 1, because index starts from 0 and id starts from 1.

Then it passes it through pipe to getDayName, returns day name, and then uses day name in i18n.t function, which is used for translating day using day name as a key

But I have a problem, when i use this function i get an error from ramda: g.call is not a function, I think this error comes from the i18n.t() in pipe, how could I fix it?

I can't pass arguments in pipe explicitly, like dayName => ..., so I should only use R.__ placeholder from ramda

1

There are 1 answers

0
Ori Drori On

R.pipe expects functions, and adding R.__ to a template string doesn't convert it to a function.

Create a translate function that wraps i18n.t(), and calls it with the dayName:

const translate = dayName =>  i18n.t(`views.routing.dialogs.${dayName}`)

And use it in the pipe:

pipe(dec, getDayName, translate))