Slide 13
Slide 13 text
FUNCTIONAL PROGRAMMING
game_state = {lives: 10,
secret: "foo",
guessed: [],
last_guess: ""
}.freeze
def lose_life_if_needed(state)
return state if state[:secret].include?(state[:last_guess])
state.clone.merge!(lives: state[:lives] - 1)
end
#...
while should_continue(game_state)
game_state = show_progress(
lose_life_if_needed(
take_guess(game_state)))
end
Monday, April 8, 13
that’s one approach, we’ll look at it again later