{"action":"created","issue":{"url":"https://api.github.com/repos/akka/akka-meta/issues/7","labels_url":"https://api.github.com/repos/akka/akka-meta/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/akka/akka-meta/issues/7/comments","events_url":"https://api.github.com/repos/akka/akka-meta/issues/7/events","html_url":"https://github.com/akka/akka-meta/issues/7","id":71362552,"number":7,"title":"How to compose akka-typed actors with akka-persistence?","user":{"login":"Horusiath","id":679705,"avatar_url":"https://avatars.githubusercontent.com/u/679705?v=3","gravatar_id":"","url":"https://api.github.com/users/Horusiath","html_url":"https://github.com/Horusiath","followers_url":"https://api.github.com/users/Horusiath/followers","following_url":"https://api.github.com/users/Horusiath/following{/other_user}","gists_url":"https://api.github.com/users/Horusiath/gists{/gist_id}","starred_url":"https://api.github.com/users/Horusiath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Horusiath/subscriptions","organizations_url":"https://api.github.com/users/Horusiath/orgs","repos_url":"https://api.github.com/users/Horusiath/repos","events_url":"https://api.github.com/users/Horusiath/events{/privacy}","received_events_url":"https://api.github.com/users/Horusiath/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-27T18:20:08Z","updated_at":"2015-05-26T17:00:25Z","closed_at":null,"body":"Right now we are able to define actor as a single function behavior - using akka-typed (JVM) or F# API (.NET). However this doesn't suit well with existing persistent actor design, for various reasons, mostly concerning actor's state. Few issues comes to my mind:\r\n\r\n- State could be potentially changed asynchronously by `persist` method's callback, which makes storing it as a behavior function parameter difficult. \r\n- The only logical alternative seems to be making dedicated `Persist` effect, but then we loose the ability to change behavior when returning from function.\r\n- Separate receive methods for events and commands also won't make things easier.\r\n\r\nSo my question to Typesafe guys - what are your thoughts about possible integration of akka typed and persistence in the future?"},"comment":{"url":"https://api.github.com/repos/akka/akka-meta/issues/comments/105602702","html_url":"https://github.com/akka/akka-meta/issues/7#issuecomment-105602702","issue_url":"https://api.github.com/repos/akka/akka-meta/issues/7","id":105602702,"user":{"login":"rkuhn","id":470469,"avatar_url":"https://avatars.githubusercontent.com/u/470469?v=3","gravatar_id":"","url":"https://api.github.com/users/rkuhn","html_url":"https://github.com/rkuhn","followers_url":"https://api.github.com/users/rkuhn/followers","following_url":"https://api.github.com/users/rkuhn/following{/other_user}","gists_url":"https://api.github.com/users/rkuhn/gists{/gist_id}","starred_url":"https://api.github.com/users/rkuhn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkuhn/subscriptions","organizations_url":"https://api.github.com/users/rkuhn/orgs","repos_url":"https://api.github.com/users/rkuhn/repos","events_url":"https://api.github.com/users/rkuhn/events{/privacy}","received_events_url":"https://api.github.com/users/rkuhn/received_events","type":"User","site_admin":false},"created_at":"2015-05-26T17:00:25Z","updated_at":"2015-05-26T17:00:25Z","body":"Recently I started experimenting with capturing “actor effects”, which is rather similar to defining a process algebra for our Actors, and «persist» was indeed one of the core effects I identified. Modeling it this way makes for a quite natural formulation: «persist» returns an Action that will loop the given event through the Journal and expose it as its output value, meaning that this will need to be composed with follow-up effects that describe the future behavior of this Actor. This scheme has the added benefit of avoiding the ambiguity with persist/persistAsync.\r\n\r\nThe more interesting question then becomes how to recover? My current design foresees another core effect for this purpose that takes the description of a folding process (initial value and state aggregation function) and returns the final state value from which the Actor can then take the next steps, typically by turning it into a Behavior (which just means describing the next steps using other actor effects).\r\n\r\nThe drawback of all this is that it will be rather allocation-heavy and the syntax is also not quite as nice as I’d like it to be—monads are not trivial to express in Scala and even more so in Java—therefore consider this as an intermediate snapshot of my thought process rather than a final result."}}