awalterschulze / goderive

Derives and generates mundane golang functions that you do not want to maintain yourself
Apache License 2.0
1.23k stars 44 forks source link

deriveFilterInPlace plugin? #32

Closed rogpeppe closed 6 years ago

rogpeppe commented 7 years ago

It would be nice to have a filter plugin that modified the slice items in place rather than returning a newly allocated slice.

awalterschulze commented 7 years ago

Yes. I agree :) I think we can simply change the current deriveFilter function. Just like the plan is to do with fmap, when the input and output types are the same. https://github.com/awalterschulze/goderive/issues/14

I just first want to provide a clone function, so that people that want to have a copy can easily get one.

awalterschulze commented 7 years ago

deriveClone(T) T

awalterschulze commented 6 years ago

deriveFilter is now in place by default.

https://github.com/awalterschulze/goderive/commit/88cd557d060cb12c1abd91c89978d5a9d0c0e332

To get the old behavior call deriveFilter(deriveClone(list), predicate)