[Haskell-cafe] New STM Data Structures Collection

Chris Wong lambda.fairy at gmail.com
Fri Oct 23 03:33:53 UTC 2015


> The isEmpty is not out of date as STM will detect if it is and restart the
> transaction.  The take operation will block if the bag is empty.  If this
> isn't clear in the documentation we should make it clearer.  You can write a
> maybeTake using orElse:
>
>   maybeTake b = (Just <$> take b) `orElse` return Nothing

Note that this can also be written as

    maybeTake = optional . take

where optional comes from Control.Applicative.

-- 
Chris Wong (https://lambda.xyz)

"I fear that Haskell is doomed to succeed."
    -- Tony Hoare


More information about the Haskell-Cafe mailing list