Cons on new topic before filtering the last used topics

Because the there is a hard limit on the number of items in the topic
history now, it makes sense to first cons on the topic and then filter
the result (so setLastFocusedTopic can be used to exclude certain topics
from ever entering the history).
This commit is contained in:
slotThe 2020-11-16 12:43:07 +01:00
parent 6079c61063
commit 1400d167ad

View File

@ -270,14 +270,14 @@ getLastFocusedTopics :: X [String]
getLastFocusedTopics = XS.gets getPrevTopics
-- | Given a 'TopicConfig', a topic, and a predicate to select topics that one
-- wants to keep, this function will filter the list of last focused topics
-- according to the predicate and cons the topic in front of that list. Note
-- that we prune the list in case its length exceeds 'maxTopicHistory'.
-- wants to keep, this function will cons the topic in front of the list of
-- last focused topics and filter it according to the predicate. Note that we
-- prune the list in case that its length exceeds 'maxTopicHistory'.
setLastFocusedTopic :: TopicConfig -> Topic -> (Topic -> Bool) -> X ()
setLastFocusedTopic tc w predicate =
XS.modify $ PrevTopics
. take (maxTopicHistory tc)
. nub . (w :) . filter predicate . getPrevTopics
. nub . filter predicate . (w :) . getPrevTopics
-- | Reverse the list of "last focused topics"
reverseLastFocusedTopics :: X ()