frunk icon indicating copy to clipboard operation
frunk copied to clipboard

Implement applyl_at and applyr_at functions

Open redbaron opened this issue 2 years ago • 2 comments

It adds applyl_at and applyr_at functions which apply single argument function to the nth HList element. It is implemented as a fold function which carries target and current depth levels as well as function application result in the accumulator.

Because n can be outside of the hlist length, function returns Option<_> with None returned if n is larger than list size.

It also hasapply*_args_at variants which adds args param to the accumulator to be passed to the function as a poor replacement for missing self (and therefore closure) param.

This is a draft PR to collect early feedback, more specifically:

  • is it something you'd like to see in this crate?
  • should it be standalone function like it is now or you prefer it to be a method on the HCons?
  • functions/arguments naming suggestions.

redbaron avatar Feb 28 '23 22:02 redbaron

Added apply*_args_at variants

redbaron avatar Mar 02 '23 08:03 redbaron

Not everyting is known at compile time. In my experiments I have a "query plan" (list of operations) in the HList and need to execute them in order when right conditions arise, hence the runtime n param to pick one to run.

redbaron avatar Mar 04 '23 08:03 redbaron