Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`+` operator to create sequence of actions #172

Closed
jcornaz opened this issue Dec 7, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@jcornaz
Copy link
Contributor

commented Dec 7, 2018

I think a + operator to easily create a sequence of actions would be nice

Example:

val sequence = moveTo(200f, 200f, 0.5f) + rotateTo(90f, 0.5f) + fadeOut(0.5f) + remove()

@czyzby czyzby added this to the 1.9.9 milestone Dec 7, 2018

@czyzby

This comment has been minimized.

Copy link
Member

commented Dec 7, 2018

It could be similar to then infix method, but it should not mutate sequence actions.

@jcornaz

This comment has been minimized.

Copy link
Contributor Author

commented Dec 7, 2018

It could be similar to then infix method, but it should not mutate sequence actions.

Ooops, indeed I forgot about then.

However I personally think that + and then should do exactly the same. (and not mutate the receiver)

Using then or + would only be a style choice (like using crs or x with vectors)

But a += may mutate the receiver.

val sequence1 = moveTo(200f, 200f, 0.5f) + rotateTo(90f, 0.5f) + fadeOut(0.5f) 
val sequence2 = moveTo(200f, 200f, 0.5f) then rotateTo(90f, 0.5f) then fadeOut(0.5f) // should produce the same result as above

sequence2 += remove() // One could still mutate a sequence like this

EDIT: Let me also argue that the then infix functions overload is currently inconsistant:

  • Action.then(action: Action) does not mutate the action
  • SequenceAction.then(action: Action): SequenceAction does mutate the sequence
@czyzby

This comment has been minimized.

Copy link
Member

commented Dec 7, 2018

These are valid points. I believe when I was implementing this, I was in the LibGDX mindset of trying to go easy on the garbage collector, but I agree that idiomatic Kotlin approach is better in this case.

@czyzby

This comment has been minimized.

Copy link
Member

commented Dec 8, 2018

Thanks for your contribution @jcornaz. I just realized parallelTo has the same mutability issue. I'll change it similarly to then. Do you think it makes sense to add an operator for parallel actions? I'm afraid it would be less obvious than in case of sequences, but % or / could work.

@jcornaz

This comment has been minimized.

Copy link
Contributor Author

commented Dec 8, 2018

Do you think it makes sense to add an operator for parallel actions? I'm afraid it would be less obvious than in case of sequences, but % or / could work.

No. I don't see the point of a non-obvious operator for parallel actions. In this case parallelTo is fairly enough.

@czyzby

This comment has been minimized.

Copy link
Member

commented Dec 8, 2018

| would be more obvious, but it's not available in Kotlin 1.3.

czyzby added a commit that referenced this issue Dec 8, 2018

czyzby added a commit that referenced this issue Dec 8, 2018

@czyzby czyzby closed this Dec 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.