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