feat: Alternative instance + Generic work

This commit is contained in:
vegowotenks 2025-07-11 17:55:48 +02:00
parent 5723a92308
commit 7a20aeeca2
2 changed files with 25 additions and 1 deletions

View file

@ -4,6 +4,7 @@ module Language.Java.Classfile.Extract (Extract(), bytes) where
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as ByteString
import Control.Applicative (Alternative (empty, (<|>)))
data Extract a = Extract (Continuation a)
@ -28,6 +29,14 @@ instance Applicative Extract where
Fail -> Fail
Fail -> Fail
instance Alternative Extract where
empty :: Extract a
empty = Extract $ const Fail
(<|>) :: Extract a -> Extract a -> Extract a
(<|>) (Extract left) (Extract right) = Extract $ \ input -> case left input of
Fail -> right input
t -> t
-- | Get a specified count of bytes. Fail if there are not enough bytes available.