using DTLib.Ben.Demystifier.Enumerable; namespace InstaFollowersOverseer.Instagram; public readonly record struct FollowersDiff(IList Unfollowed, IList Followed) { public static readonly FollowersDiff Empty = new FollowersDiff(EnumerableIList.Empty, EnumerableIList.Empty); public bool IsEmpty() => Followed.Count + Unfollowed.Count == 0; /// /// generates message aouut followed and unfollowed users /// /// string builder to append the message to /// diff computation happens in this method because it enumerates yield returned enumerables public void AppendDiffMessageTo(HtmlMessageBuilder b, CancellationToken ct) { if (Followed.Count != 0) { b.BeginStyle(TextStyle.Italic).Text(Followed.Count).Text(" users followed:\n").EndStyle(); foreach (var u in Followed) { if (ct.IsCancellationRequested) return; // username with clickable link b.SetUrl("https://www.instagram.com/" + u).BeginStyle(TextStyle.Link).Text(u).EndStyle() .Text('\n'); } } if (Unfollowed.Count != 0) { b.BeginStyle(TextStyle.Italic).Text(Unfollowed.Count).Text(" users unfollowed:\n").EndStyle(); foreach (var u in Followed) { if (ct.IsCancellationRequested) return; // username with clickable link b.SetUrl("https://www.instagram.com/" + u).BeginStyle(TextStyle.Link).Text(u).EndStyle() .Text('\n'); } } } }