Copyright | Copyright 2014-2015, Matt Giles |
---|---|
License | Modified BSD License (see LICENSE file) |
Maintainer | matt.w.giles@gmail.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Some basic lenses for the Messages API. These are compatible with both lens and lens-family.
This package doesn't provide any lens combinators like ^.
or ^..
, so you'll need to use
ones from a lens package.
For example, the following code gets the values of the speed
fields
from all of the record
messages in the file:
Right fit <- readFileMessages "file.fit" let speeds = fit ^.. message 20 . field 6 . int
- messages :: Applicative f => (Message -> f Message) -> Messages -> f Messages
- message :: (Contravariant f, Applicative f) => Int -> (Message -> f Message) -> Messages -> f Messages
- messageNumber :: Functor f => (Int -> f Int) -> Message -> f Message
- fields :: Applicative f => (Field -> f Field) -> Message -> f Message
- field :: (Contravariant f, Applicative f) => Int -> (Field -> f Field) -> Message -> f Message
- fieldNumber :: Functor f => (Int -> f Int) -> Field -> f Field
- fieldValue :: Functor f => (Value -> f Value) -> Field -> f Field
- int :: Applicative f => (Int -> f Int) -> Field -> f Field
- real :: Applicative f => (Double -> f Double) -> Field -> f Field
- text :: Applicative f => (Text -> f Text) -> Field -> f Field
- byte :: Applicative f => (Word8 -> f Word8) -> Field -> f Field
- ints :: Applicative f => (Seq Int -> f (Seq Int)) -> Field -> f Field
- reals :: Applicative f => (Seq Double -> f (Seq Double)) -> Field -> f Field
- bytestring :: Applicative f => (ByteString -> f ByteString) -> Field -> f Field
Messages
messages :: Applicative f => (Message -> f Message) -> Messages -> f Messages Source
Traverse all the messages in a Messages
messages :: Traversal' Messages Message
message :: (Contravariant f, Applicative f) => Int -> (Message -> f Message) -> Messages -> f Messages Source
A Fold over the messages with the given message number
message :: Int -> Fold Messages Message
messageNumber :: Functor f => (Int -> f Int) -> Message -> f Message Source
Lens on the message number from a Message
messageNumber :: Lens' Message Int
Fields
fields :: Applicative f => (Field -> f Field) -> Message -> f Message Source
Traverse all the fields in a Message
fields :: Traversal' Message Field
field :: (Contravariant f, Applicative f) => Int -> (Field -> f Field) -> Message -> f Message Source
A Fold over the fields in a Message
with the given field number
field :: Int -> Fold Message Field
fieldNumber :: Functor f => (Int -> f Int) -> Field -> f Field Source
Lens on the field number from a Field
fieldNumber :: Lens Field Int
Values
Generally when you're looking up the value for a particular field you'll know
the expected type ahead of time. If you know the field you're looking at holds
integers, then you can use int
to directly get an Int
instead of a
Singleton (IntValue x)
.
These traversals are not prisms, because to reconstruct the Field
we need
the field number in addition to the wrapped value.
text :: Applicative f => (Text -> f Text) -> Field -> f Field Source
bytestring :: Applicative f => (ByteString -> f ByteString) -> Field -> f Field Source