DEV Community

Jesse Phillips
Jesse Phillips

Posted on

Hobby Project: Filter for Newest Articles

If you read my previous post which focused on test data for this functionality, you may find the effort disproportionate.

auto isNewerArticle(ArticleMe am, PullState ps) {
-    return null;
+    return > ps.lastArticle;
Enter fullscreen mode Exit fullscreen mode

That is the implementation. Given an article and the previous pull data, the newer articles are the ones with the greater ID number.

This assumes articles are given newest first and that article IDs are given increasingly. However if the first isn't true I won't have reason to attempt short circuit.

alias inPreviousPull = (x) => !x.isNewerArticle(lastPullState);

Enter fullscreen mode Exit fullscreen mode

You won't find the above code in the changes, I've taken the unittest and pulled out the complete concept to save new articles.

If I abstract the dev api into a range, I'll be using a normal range sequence and combined with the components I've already tested.

What is miss here is storing and retrieval of this lastPullState.

I wrote the test first. I almost didn't because the implications was so simple, but it is good to see the test fail.

Top comments (1)

jessekphillips profile image
Jesse Phillips

I've realized that this approach for filtering is seriously flawed because of the unpublished. Can you figure it out?