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

is sequence applying effects in backwards order? #140

Closed
aryairani opened this issue Feb 8, 2015 · 2 comments · Fixed by #142
Closed

is sequence applying effects in backwards order? #140

aryairani opened this issue Feb 8, 2015 · 2 comments · Fixed by #142
Assignees

Comments

@aryairani
Copy link
Contributor

Compare:

val initialId = 0
case class Person(id: Int, name: String)
def allocatePersonS(name: String) = State { id: Int => (id + 1, Person(id, name)) }

scala>     val allocateThreePeople = for {
     |       p0 <- allocatePersonS("Alice")
     |       p1 <- allocatePersonS("Bob")
     |       p2 <- allocatePersonS("Charlie")
     |     } yield (p0, p1, p2)
allocateThreePeople: cats.data.State[Int,(Person, Person, Person)] = cats.data.State@24407ee8

scala>     val (id3, (p0, p1, p2)) = allocateThreePeople(initialId)
id3: Int = 3
p0: Person = Person(0,Alice)
p1: Person = Person(1,Bob)
p2: Person = Person(2,Charlie)

to:

val (id3, List(p0, p1, p2)) =
  List("Alice","Bob","Charlie")
    .map(allocatePersonS)
    .sequence[State[Int,?],Person]
    .apply(initialId)

// Exiting paste mode, now interpreting.

id3: Int = 3
p0: Person = Person(2,Alice)
p1: Person = Person(1,Bob)
p2: Person = Person(0,Charlie)

I haven't had a chance to check whether it's a problem with sequence or with ListInstances.listInstance or if it's something wrong that I've done; confirmation would be appreciated :)

@non
Copy link
Contributor

non commented Feb 8, 2015

Confirmed, and I have a fix incoming.

@aryairani
Copy link
Contributor Author

Works for me; but I see I used the same test case as you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants