We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi, I was taking a stab at a function that inserts an item into a set and returns whether it already existed prior to the operation.
-- The result is False if the item already exists in the set insertIfMissing :: item -> Set item -> STM Bool
Obviously this can be done as a lookup followed by insert. However, I was wondering if it ought to be possible via focus?
lookup
insert
focus
E.g.
do let insertIfMissing :: a -> Focus a m Bool insertIfMissing element = do F.cases (True, F.Set element) (const (False, F.Leave)) alreadyPresent <- focus insertIfMissing item set
focus expects Focus () STM result, which is explained in the docs:
Focus () STM result
The strategy is over a unit since we already know, which element we're focusing on and it doesn't make sense to replace it
Would it be fair to say that this use-case contradicts the rationale?
The text was updated successfully, but these errors were encountered:
Seems like a perfectly valid use-case to me :)
Sorry, something went wrong.
No branches or pull requests
Hi, I was taking a stab at a function that inserts an item into a set and returns whether it already existed prior to the operation.
Obviously this can be done as a
lookup
followed byinsert
. However, I was wondering if it ought to be possible viafocus
?E.g.
focus
expectsFocus () STM result
, which is explained in the docs:Would it be fair to say that this use-case contradicts the rationale?
The text was updated successfully, but these errors were encountered: