javascript - Composing a function from an uncurried function -


i'm trying create curriable function returns whether or not supplied length equal length of supplied string. i'd work this:

checklength(3)('asdf') // => false checklength(4)('asdf') // => true 

i tried this, argument order reversed because returns curried equals function:

const checklength = r.compose(r.equals(), r.prop('length')) checklength('asdf')(4) 

i can fix wrapping in function this:

const checklength = (len) => r.compose(r.equals(len), r.prop('length')) 

but seems there way use functional library solve this. have ideas?

the simplest way go flip function found - unfortunately work properly, need add stage of uncurrying composed function:

const checklength = r.flip(r.uncurryn(2, r.compose(r.equals, r.prop('length')))) checklength(4)('asdf') // => true 

an alternative solution use usewith function:

const checklength = r.usewith(r.equals, [r.identity, r.prop('length')]); checklength(4)('asdf') // => true 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -