We define key constructions to mix context and stateful computations in the aim of providing a compositional semantics for stateful stream functions. We mechanize the construction of this model of computation by leveraging the Yang-Baxter equation to define new distributive laws between monads and comonads, extending the result of Uustalu and Vene to the case of a distributive law of the listval comonad over the stateoption monad. We justify our construction with the proof of a no-go theorem for the distributive law of the nonempty list comonad over the state monad. We give a computational interpretation, and use the Kleisli category of the resulting distributive law to define a semantics for a minimal yet powerful calculus of imperative stream processing functions. Along the way, we provide illustrative examples to clarify key concepts of the calculus and demonstrate the applicability of its formalization in a stateful implementation of the infinite sieve of Eratosthenes using the Rocq proof assistant.