Currying with pathways
Install the module from npm
npm i curry-map --save
How do I use this library?
Brace yourself. Not for the faint fo heart.
Okay maybe I'm exaggerating a bit, but it looks complicated bear with me. Currying is the ability to pass parameters to a function all at once or one at a time.
// all equivalent;'my-arg-2''my-arg-3';'my-arg-2' 'my-arg-3';'my-arg-3';
What if a different function were run depending on which arguments were passed, that is the goal of this library.
Building a CurryMap
Your only task at this moment as a developer is to build a CurryMap. Each argument takes you closer to a end result but at which end result will you arrive?
const CurryMap = ;const paths =batman:joker:;const myApi = ;;
Note: One single
() follows only the primary definition.
CurryMap requires an object containing api endpoints as a first parameter. Optionally provide
_ indicating any other input should it not be in the arguments list, for example a document id or database name should you need them. Things start to get complicated here be vigilant.
const mySecondApi =;;;;
#=> I am the night. #=> Hi Jacob! #=> Goodbye Brooke! :(
You can do this many times.
const ageify = name + ' is ' + age;const myThirdApi = ;;
#=> Felicity is 31
The following is equivalent to above.
const myFourthApi = CurryMap;;
#=> Felicity is 31
You can also keep things going with another CurryMap.
const myFifthApi = CurryMap;;
#=> Ruddiger is 112
Extending the prototype
Prototype extensions are passed with the
proto keyword. It's an object whose values are functions which accept the curry so far.
const superman =;const mySixthApi = ;;;;
#=> Forsooth bad guy! You are out of time. #=> WHAMMO bad guy #=> Dearest citizens. Celebrate!
CurryMap is a function accepting
(...curry) as its parameters returning a function whch can be used to traverse further.
When you compile a complex CurryMap it's going to look a bit like big mess. I'm not sure what to tell you about how to fix that. Some kind of extreme discipline is probably required in order to keep it looking sane and manageable, or if you have a robot eye you may be able to understand all of the paths.
If you like what you see please feel encouraged to get involved report problems and submit pull requests! As of the time of this writing the project is new with one maintainer.