You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 :)
The text was updated successfully, but these errors were encountered:
Compare:
to:
I haven't had a chance to check whether it's a problem with
sequence
or withListInstances.listInstance
or if it's something wrong that I've done; confirmation would be appreciated :)The text was updated successfully, but these errors were encountered: