Skip to content

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Make state more flexible #22

wants to merge 4 commits into from

Conversation

mattfenwick
Copy link
Owner

New combinators

  • update
  • updateStateForKey
  • putStateForKey
  • getStateForKey

Refactoring

  • 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

Questions

  • effect on performance

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,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a great name.

@mattfenwick mattfenwick changed the title add new combinators and refactor Make state more flexible Jan 21, 2016
}
return new Parser(f);
}

function putState(s) {
Copy link
Owner Author

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);

@mattfenwick
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant