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

Print list #234

Merged
merged 5 commits into from
Feb 24, 2020
Merged

Print list #234

merged 5 commits into from
Feb 24, 2020

Conversation

Janther
Copy link
Contributor

@Janther Janther commented Feb 19, 2020

just playing with the idea of having a printList function (provided by @fvictorio) for most of our splitting and indenting cases.

The function just needs an array, but can also receive a firstSeparator (usually a softline used to separate from the previous character), a normal separator to put between items (usually a concat([',', line])), and finally the lastSeparator that in most cases is the same as firstSeparator with 2 exceptions (AssemblySwitch and StructDefinition).

const printList = (
  list,
  firstSeparator = softline,
  separator = concat([',', line]),
  lastSeparator = firstSeparator
) =>
  group(
    concat([
      indent(concat([firstSeparator, join(separator, list)])),
      lastSeparator
    ])
  );

Please have a look and see if it makes sense to use this pattern.

@Janther Janther added the refactor reorganising the code without changes label Feb 19, 2020
@codecov
Copy link

codecov bot commented Feb 19, 2020

Codecov Report

Merging #234 into master will increase coverage by 0.14%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #234      +/-   ##
==========================================
+ Coverage   99.06%   99.21%   +0.14%     
==========================================
  Files          78       79       +1     
  Lines         639      633       -6     
  Branches      106      106              
==========================================
- Hits          633      628       -5     
+ Misses          6        5       -1     
Impacted Files Coverage Δ
src/nodes/print-list.js 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 234790a...4cadc86. Read the comment docs.

@fvictorio
Copy link
Member

I think I like this. Most usages use default arguments, so that's nice.

The only problem I see is that when explicit arguments are added, it gets a little cryptic. What do you think about having just an options parameter, so that the calls are more explicit (the "javascript doesn't have named parameters so this is the best we can do" pattern):

const printList = (
  list,
  {
    firstSeparator = softline,
    separator = concat([',', line]),
    lastSeparator = firstSeparator,
  } = {}
) =>

@Janther
Copy link
Contributor Author

Janther commented Feb 20, 2020

done, this idea was on the back of my mind. Glad that you proposed it aswell.

@mattiaerre
Copy link
Member

this is really cool, let's merge and deploy a new version

@mattiaerre mattiaerre removed their assignment Feb 21, 2020
@mattiaerre mattiaerre merged commit 9bcb096 into master Feb 24, 2020
@mattiaerre mattiaerre deleted the print_list branch February 24, 2020 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor reorganising the code without changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants