lloydmeta / frunk

Funktional generic type-level programming in Rust: HList, Coproduct, Generic, LabelledGeneric, Validated, Monoid and friends.
https://beachape.com/frunk/
MIT License
1.24k stars 56 forks source link

Implement applyl_at and applyr_at functions #208

Open redbaron opened 1 year ago

redbaron commented 1 year ago

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:

redbaron commented 1 year ago

Added apply*_args_at variants

redbaron commented 1 year ago

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.