Skip to content

Fluent PackBuilder #1207

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

Closed
wants to merge 1 commit into from
Closed

Fluent PackBuilder #1207

wants to merge 1 commit into from

Conversation

dahlbyk
Copy link
Member

@dahlbyk dahlbyk commented Oct 22, 2015

Extracted from #1205

Is supporting pb => pb.Add(obj1).Add(obj2) good or useful?

@ethomson
Copy link
Member

Do you have a use case in mind? My initial thought is that you would almost always do this in a loop and a fluent API wouldn't be particularly helpful.

@dahlbyk
Copy link
Member Author

dahlbyk commented Oct 22, 2015

My initial thought is that you would almost always do this in a loop and a fluent API wouldn't be particularly helpful.

Having actually written code using the API, I tend to agree. In fact, IEnumerable<> overloads are probably worth having.

Of course, supporting chaining is trivial to implement with zero downside that I can see.

         internal void AddingObjectsTestDelegate(IRepository repo, PackBuilder builder)
         {
-            foreach (Branch branch in repo.Branches)
-            {
-                foreach (Commit commit in branch.Commits)
-                {
-                    builder.AddRecursively(commit);
-                }
-            }
-
-            foreach (Tag tag in repo.Tags)
-            {
-                builder.Add(tag.Target);
-            }
+            builder.AddRecursively(repo.Branches.SelectMany(b => b.Commits))
+                   .Add(repo.Tags.Select(t => t.Target));
         }

(Of course the single expression is more useful if it were inline as a lambda rather than in a separate method.)

@bording bording closed this Apr 21, 2019
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