plaid icon indicating copy to clipboard operation
plaid copied to clipboard

Added modifiableForEach extension method that allows for in place ListModification during traversal

Open tunjid opened this issue 5 years ago • 6 comments

:loudspeaker: Type of change

  • [x] Bugfix
  • [ ] New feature
  • [ ] Enhancement
  • [ ] Refactoring

:scroll: Description

Added modifiableForEach extension method that allows for in place List modification during traversal.

:bulb: Motivation and Context

Adresses #767

If the SlideInItemAnimator is running during an orientation change, a ConcurrentModificationException will be thrown. This change allows for traversal with an iterator, allowing for in place modifications to the list.

:green_heart: How did you test it?

I used the animator in another project where the SlideInItemAnimator runs continuously, and triggered Activity destruction by rotating the phone. Source for that class is here: https://github.com/tunjid/android-bootstrap/blob/develop/app/src/main/java/com/tunjid/androidbootstrap/fragments/ShiftingTileFragment.kt

:pencil: Checklist

  • [x] I ran ./gradlew spotlessApply before submitting the PR
  • [x] I reviewed submitted code
  • [ ] I added tests to verify changes
  • [x] All tests passing

:crystal_ball: Next steps

:camera_flash: Screenshots / GIFs

tunjid avatar Sep 11 '19 04:09 tunjid

Over to Nick since he's been working on the Animator.

keyboardsurfer avatar Nov 25 '19 11:11 keyboardsurfer

@nickbutcher thanks for the comments! Are rebases preferred to merges when there are changes upstream? I checked the contributing doc, but it doesn't seem to mention it.

tunjid avatar Nov 25 '19 16:11 tunjid

@tunjid rebase please. Thanks!

nickbutcher avatar Nov 25 '19 16:11 nickbutcher

I'm not sure of a better name than removableForEach, very much open to suggestions. I also narrowed the type on the extension to a MutableIterable to better communicate intent.

tunjid avatar Nov 26 '19 04:11 tunjid

Hmm, I can't think of a great name either and worry that removableForEach implies that the action may remove an item. What about onEach? It's similar enough to forEach to convey what it does without suggesting extra behavior?

nickbutcher avatar Nov 26 '19 13:11 nickbutcher

That works! What do you think about adding an iterator prefix so the mutable iterator backing is communicated? So iteratorOnEach?

tunjid avatar Nov 26 '19 14:11 tunjid