> 5 maj 2015 kl. 21:32 skrev Michael Frank <syntaxjoc...@gmail.com>:
> 
> 
> 
> On Mon, May 4, 2015 at 11:04 PM, Roland Kuhn <goo...@rkuhn.info 
> <mailto:goo...@rkuhn.info>> wrote:
> Hi Michael,
> 
>> 5 maj 2015 kl. 00:24 skrev Michael Frank <syntaxjoc...@gmail.com 
>> <mailto:syntaxjoc...@gmail.com>>:
>> 
>> thank you konrad for the detailed explanation!  i have implemented this in 
>> various ways in the past, and thought it would be nice to have a unified, 
>> 'blessed' mechanism.  however, i understand how the cost-benefit tradeoff 
>> might weigh against it.
> 
> Saying “implemented” might be an overstatement given that it is not even 
> quite a full line:
> 
> val names = Iterator.from(1).map(i => s"foo-$i")
> 
> I'll overlook the snark because that really is a nice one-liner :)

Sorry, couldn’t resist ;-)

>   But boilerplate is boilerplate, yes?
> 
> My use case often involves child actors which have a well-known identity, but 
> need to have a unique name for lifecycle purposes.  so i might extract the 
> above into a trait:
> 
> trait UniqueNames {
> 
>     private val nameSource = Iterator.from(1)
>     def uniqueName(prefix: String): String = prefix + "-" + 
> nameSource.next.toString
> 
> }

Yes, this works, but inheritance can sometimes be a bit cumbersome. You could 
also put it in its own class and rename the method to `apply`:

val uniqueName = new NameFactory
...
context.actorOf(..., uniqueName("Bert"))

Regards,

Roland

> 
> Thank you Roland for your code example!
> 
> -Michael
> 
> -- 
> >>>>>>>>>> Read the docs: http://akka.io/docs/ <http://akka.io/docs/>
> >>>>>>>>>> Check the FAQ: 
> >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html 
> >>>>>>>>>> <http://doc.akka.io/docs/akka/current/additional/faq.html>
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user 
> >>>>>>>>>> <https://groups.google.com/group/akka-user>
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to akka-user+unsubscr...@googlegroups.com 
> <mailto:akka-user+unsubscr...@googlegroups.com>.
> To post to this group, send email to akka-user@googlegroups.com 
> <mailto:akka-user@googlegroups.com>.
> Visit this group at http://groups.google.com/group/akka-user 
> <http://groups.google.com/group/akka-user>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe <http://typesafe.com/> – Reactive apps on the JVM.
twitter: @rolandkuhn
 <http://twitter.com/#!/rolandkuhn>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to