Skip to content

Question: Simple example of a functional process with state mutation (and error handling) #1434

Closed Answered by louthy
OlliMartin asked this question in Q&A
Discussion options

You must be logged in to vote

@OlliMartin There's quite a bit to unpack here, so I'll try and cover what I can.

If you're just learning FP then be a little wary of going all-in with monad-transformers (OptionT, StateT, etc.) - they're quite advanced topics... very powerful, but can be a bit of a head-scratcher to start with. My Higher Kinds series will help, but if you get stuck, know that there's a simpler route to functional programming without going quite all the way in like this. The code ends up less elegant, but is cognitively easier to start...

  1. Pass state as arguments:
static X foo(..., YourState state) =>
   ...
  1. Return updated state:
static (YourState State, X Value) foo(..., YourState state) =>
   ...

Thi…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by OlliMartin
Comment options

You must be logged in to vote
5 replies
@louthy
Comment options

@OlliMartin
Comment options

@louthy
Comment options

@OlliMartin
Comment options

@louthy
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1433 on December 27, 2024 15:45.