[Haskell-beginners] Very little (golfing) question...
Brent Yorgey
byorgey at seas.upenn.edu
Thu Jul 26 02:31:26 CEST 2012
On Wed, Jul 25, 2012 at 11:02:39PM +0200, Corentin Dupont wrote:
>
This is a little better, it avoids all the record syntax for
extracting player numbers, and uses 'any' instead of 'find' since we
don't actually care about the player with the given number if they
exist:
> addPlayer :: PlayerInfo -> State Game Bool
> addPlayer pi = do
> pls <- gets players
> let exists = any (((==) `on` playerNumber) pi) pls
> when (not exists) $ modify (\game -> game { players = pi : pls})
> return $ not exists
-Brent
More information about the Beginners
mailing list