Skip to content

Rework Generics of Transformer interface - #447

Merged
snuyanzin merged 2 commits into
datafaker-net:mainfrom
NarekDW:transformers-generic-issue
Oct 21, 2022
Merged

Rework Generics of Transformer interface#447
snuyanzin merged 2 commits into
datafaker-net:mainfrom
NarekDW:transformers-generic-issue

Conversation

@NarekDW

@NarekDW NarekDW commented Oct 18, 2022

Copy link
Copy Markdown
Contributor

@snuyanzin could you review generics in Transformer interface, please?

I've found a number of issues here:

  1. On the code below, Schema<?, ? extends OUT> means that OUT transform(IN input) function from Field interface could generate the value only of some specific type. For example for CsvTransformer class, OUT is defined as CharSequence, so it means that we can generate CSV only from CharSequence, we couldn't generate CSV (fields) from other objects (integer, double, boolean e.g.).
    Take a look on the test case testCsvWithDifferentObjects and testCsvWithDifferentObjectsFunction.
public interface Transformer<IN extends AbstractProvider<?>, OUT> {
    OUT apply(Object input, Schema<?, ? extends OUT> schema);
...
  1. Here, IN generic type should not extends AbstractProvider, because in fact that type corresponds to the
    Schema<IN, ...> interface then it is passed to the function OUT transform(IN input) from Field interface, that function takes an argument of IN type and feeds it to the functional interface, which generates the data based on the argument, therefore, the argument could be an object of any type.
    Take a look on the test case testCsvWithDifferentObjects and testCsvWithDifferentObjectsFunction.
public interface Transformer<IN extends AbstractProvider<?>, OUT> {
    ...
    String generate(List<IN> input, final Schema<IN, ? extends OUT> schema);
    ...
}
  1. I think all the functions from interface Transformer should return a data of type OUT

Otherwise, if we don't want to change the types definition, we have to try to adjust the code to that types.

@codecov-commenter

codecov-commenter commented Oct 18, 2022

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.03%. Comparing base (35651df) to head (fa62365).
Report is 1301 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #447      +/-   ##
============================================
+ Coverage     93.00%   93.03%   +0.02%     
- Complexity     2094     2098       +4     
============================================
  Files           233      233              
  Lines          4373     4377       +4     
  Branches        449      449              
============================================
+ Hits           4067     4072       +5     
+ Misses          190      186       -4     
- Partials        116      119       +3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@snuyanzin

Copy link
Copy Markdown
Collaborator

awesome, thanks

@snuyanzin
snuyanzin merged commit 2085cdf into datafaker-net:main Oct 21, 2022
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.

3 participants