DEV Community

Discussion on: "Parse, don't validate" using ViewPatterns

Collapse
 
freuk profile image
Valentin Reis • Edited

here's one way using the Alternative instance for Maybe:

readOp :: Word8 -> ByteString -> Maybe Opcode
readOp word bs =
  readDUP word
    <|> readSWAP word
    <|> readLOG word
    <|> readPUSH word bs
    <|> case word of
      0x00 -> pure STOP
      ...
      _ -> Nothing
Collapse
 
sshine profile image
Simon Shine

Thanks!