Skip to content

feat: Add solution for exercise 13_variadic (#22) - #117

Merged
zhravan merged 3 commits into
zhravan:mainfrom
thearpankumar:solution/13_variadic-issue-22
Oct 2, 2025
Merged

feat: Add solution for exercise 13_variadic (#22)#117
zhravan merged 3 commits into
zhravan:mainfrom
thearpankumar:solution/13_variadic-issue-22

Conversation

@thearpankumar

@thearpankumar thearpankumar commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

This PR implements the solution for exercise 13_variadic, which teaches variadic functions in Go.

The Sum function accepts any number of integers using the ...int syntax and returns their total sum by iterating through the arguments with a for-range loop.

Implementation Details

  • Created internal/exercises/solutions/13_variadic/variadic.go with a simple, idiomatic implementation
  • The solution iterates through variadic integers and accumulates the sum
  • Code follows Go best practices: clear variable names, simple logic

Testing

  • ✅ Solution passes all tests: ./bin/golearn verify 13_variadic --solution
  • ✅ Template still fails as expected (ensures incomplete code for student learning)
  • ✅ Code is properly formatted with gofmt
  • ✅ Passes go vet checks

Checklist

  • Tests pass: make verify or golearn verify 13_variadic --solution
  • Docs updated (README/CONTRIBUTING) if needed (no updates needed)
  • No large new dependencies (no new dependencies added)

Output

$ ./bin/golearn verify 13_variadic --solution
==> 13_variadic: Variadic Functions (solution)
PASSED 13_variadic (solution)

Related issues

Fixes #22

The branch solution/13_variadic-issue-22 is already pushed to the remote repository.

Summary by CodeRabbit

  • New Features
    • Introduced a variadic sum utility that lets you add any number of integers in one call. Useful for aggregations, totals, and quick calculations without manual loops. Provides a straightforward way to compute totals across dynamic inputs, improving readability and reducing boilerplate in examples and apps.

Implement the Sum function that accepts variadic integers
and returns their total sum.

- Created solution in internal/exercises/solutions/13_variadic/
- Solution passes all tests: ./bin/golearn verify 13_variadic --solution
- Template still fails as expected for student learning

Fixes zhravan#22
@coderabbitai

coderabbitai Bot commented Oct 2, 2025

Copy link
Copy Markdown

Walkthrough

Introduces a new Go package with a variadic sum function. The function accepts a variable number of integers, iterates through them, accumulates a total, and returns the result.

Changes

Cohort / File(s) Summary of Changes
Variadic sum utility
internal/exercises/solutions/13_variadic/variadic.go
Added package variadic with exported function Sum(nums ...int) int that iterates over inputs and returns their sum.

Sequence Diagram(s)

sequenceDiagram
    actor Caller
    participant Variadic as variadic.Sum
    Caller->>Variadic: Sum(nums...int)
    note over Variadic: Initialize total = 0<br/>Loop over nums<br/>Accumulate total
    Variadic-->>Caller: int (total)
Loading

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

I hop through code with ears held high,
Counting carrots passing by—
One, two, many, gathered neat,
A variadic, crunchy treat.
Sum them up, then quickly run—
Totals tallied, job well done! 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly indicates the addition of the solution for exercise 13_variadic and follows a conventional commit prefix. It references the related issue number for context without including extraneous detail. The phrasing is concise and directly communicates the PR’s main objective.
Linked Issues Check ✅ Passed The PR implements the Sum function for exercise 13_variadic in the designated solutions directory and successfully verifies it passes all tests. It cross‐references issue #22 in the description and maintains idiomatic Go formatting and vet compliance. This meets the linked issue’s requirements for code implementation, test passing, and issue linking.
Out of Scope Changes Check ✅ Passed All changes in this PR are confined to adding a single solution file under internal/exercises/solutions/13_variadic and there are no modifications to unrelated modules or directories. The exercise template remains untouched to preserve the learning experience. Therefore, there are no out-of-scope changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5420af and 07340a4.

📒 Files selected for processing (1)
  • internal/exercises/solutions/13_variadic/variadic.go (1 hunks)
🔇 Additional comments (1)
internal/exercises/solutions/13_variadic/variadic.go (1)

1-10: LGTM! Clean and idiomatic variadic function implementation.

The Sum function correctly demonstrates Go's variadic parameter syntax and provides a clear, minimal implementation. The logic handles the empty-arguments case correctly (returns 0), and the code follows Go conventions.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zhravan
zhravan self-requested a review October 2, 2025 18:31
@zhravan zhravan added patch Bug fixes and small improvements hacktoberfest Hacktoberfest participation hacktoberfest-accepted hacktoberfest2025 labels Oct 2, 2025
@zhravan
zhravan merged commit 53403bd into zhravan:main Oct 2, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest Hacktoberfest participation hacktoberfest2025 hacktoberfest-accepted patch Bug fixes and small improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add solution: 13_variadic

2 participants