-
Notifications
You must be signed in to change notification settings - Fork 1
Make state more flexible #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
new: - `update` - `updateStateForKey` - `putStateForKey` - `getStateForKey` refactor: - don't make assumptions about what the state is - this requires changes to be made to count and position itemizers, because they had been assuming the state to be something. Now they just assume the state has a specific key with a value of the right type - write `put<X>`, `get<X>` in terms of `update<X>` - presented value of `put<X>` and `update<X>` is now the previous value, instead of null - pull helper functions out into separate module
'compose' : compose, | ||
'id' : id, | ||
'constF' : constF, | ||
'mapOverObject' : mapOverObject, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a great name.
} | ||
return new Parser(f); | ||
} | ||
|
||
function putState(s) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// s -> Parser e s (m t) a
var putState = F.compose(updateState, F.constF);
Alternate solution: think of parser in terms of a monad stack. Use one state layer for parse state, one for position counting. If the state needs to be more flexible, then just add more state layers. |
New combinators
update
updateStateForKey
putStateForKey
getStateForKey
Refactoring
because they had been assuming the state to be something. Now
they just assume the state has a specific key with a value of the
right type
put<X>
,get<X>
in terms ofupdate<X>
put<X>
andupdate<X>
is now the previous value,instead of null
Questions