lkakuser.blogg.se

Kotlin mapof
Kotlin mapof












kotlin mapof

Since UserView is on the outer layer of our application, we don’t want to add this function to our User class. What we need now is a mapping function, that will map User-> UserView. While it’s representing the same data in our domain, some fields are an aggregate of the fields of our User class and some fields simply have a different name: data class UserView( We’ve decided to call this class UserView and we can imagine it being used as a response send from a web controller. Now we want to provide a different view on this data. It’s also possible that it’s an entity we load from a relational database. When that function ends, we’ll know a bunch of keys and how many steps it took to get to them.Let’s use the following example: We have a class User, which might be a class from our core domain.

kotlin mapof

Otherwise, we can add the point we’re looking at now to the queue. Otherwise, if we are standing on a key and don’t already have it, collect it by adding a record into keyDistance. Next, if we’re standing at a door and we do not have the key, we’re done. Record its distance as one plus the distance it took to get to the spot that we came from. Otherwise, we need to do some work.Ĭongratulations, the neighboring spot we are looking at is something we can move to, and something we haven’t seen yet. We’ll filter out spots that aren’t open (walls), and spots that we’ve already examined (because we’re caching things in the distance map). So long as our work queue isn’t empty, we’ll get all the neighbors of the spot at the head of the queue. We also keep a distance map for any given point from the starting point, and map of keys to their location and how many steps they took to get there.

kotlin mapof

We set up a queue to order our work in increasingly deep steps. This function should look familiar - we’ve use a Depth First Traversal a few times this year.














Kotlin mapof