fit-0.5.2: FIT file decoder

CopyrightCopyright 2014-2015, Matt Giles
LicenseModified BSD License (see LICENSE file)
Maintainermatt.w.giles@gmail.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Fit.Messages.Lens

Contents

Description

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

Synopsis

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

fieldValue :: Functor f => (Value -> f Value) -> Field -> f Field Source

Lens on the Value from a Field

fieldValue :: Lens Field Value

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.

int :: Applicative f => (Int -> f Int) -> Field -> f Field Source

Traverse the Singleton and IntValue constructors for a field value

int :: Traversal' Field Int

real :: Applicative f => (Double -> f Double) -> Field -> f Field Source

Traverse the Singleton and RealValue constructors for a field value

real :: Traversal' Field Double

text :: Applicative f => (Text -> f Text) -> Field -> f Field Source

Traverse the Singleton and TextValue constructors for a field value

text :: Traversal' Field Text

byte :: Applicative f => (Word8 -> f Word8) -> Field -> f Field Source

Traverse the Singleton and ByteValue constructors for a field value

byte :: Traversal' Field Word8

ints :: Applicative f => (Seq Int -> f (Seq Int)) -> Field -> f Field Source

Traverse the Array and IntArray constructors for a field value

ints :: Traversal' Field (Seq Int)

reals :: Applicative f => (Seq Double -> f (Seq Double)) -> Field -> f Field Source

Traverse the Array and RealArray constructors for a field value

reals :: Traversal' Field (Seq Double)

bytestring :: Applicative f => (ByteString -> f ByteString) -> Field -> f Field Source

Travese the Array and ByteArray constructors for a field value

bytestring :: Traversal' Field ByteString