Skip to content
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

Add tryencode and trydecode #238

Closed
wants to merge 3 commits into from

Conversation

jakobnissen
Copy link
Member

Add tryencode and trydecode

The encode and decode methods are not allowed to produce invalid data. Instead,
they throw an error when encountering invalid input data.
This can lead to some frustration when checking if a symbol is permitted in an
alphabet.
One way to solve it is by checking symbol in symbols(A), but this is not
particularly effective.

This PR adds a tryencode and trydecode method to existing alphabets. These
methods return nothing when given invalid data.
Methods encode and decode now internally call their try-variants.

May solve #219

Types of changes

This PR implements the following changes:

  • ✨ New feature (A non-breaking change which adds functionality).

📋 Additional detail

  • tryencode and trydecode introduced, returning Union{Nothing, E}
  • encode and decode now uses a fallback implementation which calls these try- methods internally
  • There is no performance difference
  • Alphabet docstring has been changed in a backwards compatible way to mention these new methods.

☑️ Checklist

  • 🎨 The changes implemented is consistent with the julia style guide.
  • 📘 I have updated and added relevant docstrings, in a manner consistent with the documentation styleguide.
  • 📘 I have added or updated relevant user and developer manuals/documentation in docs/src/.
  • 🆗 There are unit tests that cover the code changes I have made.
  • 🆗 The unit tests cover my code changes AND they pass.
  • 📝 I have added an entry to the [UNRELEASED] section of the manually curated CHANGELOG.md file for this repository.
  • 🆗 All changes should be compatible with the latest stable version of Julia.
  • 💭 I have commented liberally for any complex pieces of internal code.

The encode and decode methods are not allowed to produce invalid data. Instead,
they throw an error when encountering invalid input data.
This can lead to some frustration when checking if a symbol is permitted in an
alphabet.
One way to solve it is by checking `symbol in symbols(A)`, but this is not
particularly effective.

This PR adds a tryencode and trydecode method to existing alphabets. These
methods return nothing when given invalid data.
Methods encode and decode now internally call their try-variants.

May solve BioJulia#219
@codecov
Copy link

codecov bot commented Jun 16, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.28%. Comparing base (bf4aac5) to head (4fdfac9).
Report is 63 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #238      +/-   ##
==========================================
+ Coverage   89.25%   89.28%   +0.02%     
==========================================
  Files          31       31              
  Lines        2430     2426       -4     
==========================================
- Hits         2169     2166       -3     
+ Misses        261      260       -1     
Flag Coverage Δ
unittests 89.28% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jakobnissen
Copy link
Member Author

jakobnissen commented Jun 16, 2022

CodeCov is acting up. There is no code coverage difference as far as I can see.
... and now the check magically passed without me pushing anything? What on Earth?

@jakobnissen
Copy link
Member Author

Superseded by #324

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