Transcript from the "FPO" Lesson
>> Kyle Simpson: The last library I'm gonna show you is a bit self-serving cuz I'm gonna show you one that I wrote. But you notice that I didn't even recommended that you use this library, I've recommended that you use something like Ramda or Lodash. This library is called FPO and has a very specific use case that it was built for.
[00:00:16] It was, actually my goal was to create a ramper on top of Ramda. I set out trying to adapt the Ramda functions to do a very specific thing that I wanted. And I got about a third of the way through that work. And I found some implementation details of Ramda that we're gonna make it impossible for me to go forward, and that is the only reason why I and ended up creating a separate thing.
[00:00:40] So it's really not designed to be radically different from Ramda but just a different way of dealing with the function signatures. So I just wanna talk about this particular used case. If you ever run across this particular problem, maybe you might wanna go look at FPO, but otherwise use something that's much more well-established like a Ramda.
[00:00:58] The use case I'm talking about is if you are dealing with a function where there is an ordering of the arguments that is inconvenient for you and find yourself doing a bunch of flips or reverses or if you have functions that take parameters that you want to skip over and it's really annoying to use undefined in those parameter positions, there is a different style of programming.
[00:01:55] You literally, at the function call site, can say this value goes to this parameter. And one of the benefits of a named argument is that you can skip over them by just not listing them and you can also list them in whatever order is convenient to you. So you get rid of all those juggling that you often have to do with argument ordering.
>> Kyle Simpson: So here we see that FPO's.reduce allows us to skip over the initial value because we don't need to provide it, it doesn't clutter up the call site. Another example is when we have some argument order juggling that we're doing, like some kinda crazy flipping of a partial right of this utility or something like that.
[00:03:11] When we have these weird sorts of contortions that we have to go through to rearrange our argument ordering, sometimes a named argument style is better. So here with FPO, I just tell it, listen, I wanna start with the array, I don't need to do like a flip of a partial right to start with the array, and let me provide the function later.
[00:03:31] So FPO's style of curried implementation is named argument aware, which means you can pass in an object with whatever property named arguments you want and it's waiting for the rest of those arguments on the next column.
>> Kyle Simpson: I released this library a little like a year and a half ago and I got a whole bunch of people that were like, this is awesome, there are people like Red and others like talking about it, that we're all like scholar programmers.
[00:04:23] Just one last little note on it. FPO's namespace has all those methods with this named argument style but it also provides FPO.STD standard, which has all of the same method names but done in the original style you'd expect, just like in Ramda. So you should have, you have both of those in the same library if you ever end up wanting to use that, okay?
[00:04:46] So, definitely go check out the documentation for something like Lodash/fp, check out the documentation for Ramda, those are great places to start, really great places. If you ever run across a need for a named argument style, you can check out FPO in the documentation on that. But these are a great resource for you to get started playing with your functional programming.