Skip to content

Instantly share code, notes, and snippets.

View shved's full-sized avatar
🦀

Vitalii Shvedchenko shved

🦀
View GitHub Profile
@shved
shved / run_state.rb
Created February 17, 2019 10:25 — forked from flash-gordon/run_state.rb
This shows that implementation of state effects doesn't require mutation. This example uses recursion that can be optimized after enabling TCO
require 'fiber'
class RunState
def call(fiber, state = {}, *xs)
result = fiber.resume(*xs)
if fiber.alive?
op, *args = result
case op
when :read