Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Representing Field Families #6

Closed
alanz opened this Issue · 3 comments

2 participants

@alanz

Another question. According to the Telehash protocol spec (http://telehash.org/proto.html), there can be multiple field in a given json message which are distinguished by a leading '+' character, followed by alpha-numerics. e.g. fields with names like "+end", or "+foo".

Without enumerating all possibilities, is there any way to gather these into a list or other structure in the underlying type?

e.g.

data TeleHashEntry = TeleHashEntry 
                     { teleRing :: Int
                     , teleSee  :: Maybe [T.Text]
                     , teleBr   :: Int
                     , teleTo   :: T.Text
                     , teleLine :: Maybe T.Text
                     , teleHop  :: Maybe T.Text
                     , teleSignals::[ (T.Text,T.Text)] 
                     } deriving (Eq, Show)

telexJson = $(deriveIsos ''TeleHashEntry)

instance Json TeleHashEntry where
  grammar = telexJson . object
    ( prop "_ring"
    . prop ".see"
    . prop "_br"
    . prop "_to"
    . optionalProp "_line"
    . optionalProp "_hop"
    . prop "+????"      -- What should go here?
    )

optionalProp :: Json a => String -> Iso (Object :- t) (Object :- Maybe a :- t)
optionalProp name = duck just . prop name <> duck nothing

Thanks
Alan

@MedeaMelana
Owner

Currently the closest you can get to this using the standard combinators is using rest which puts all the unprocessed properties on the stack as a map. When I've finished error reporting I'll give this some more thought. Perhaps a function like prop but with type Json a => (String -> Bool) -> Iso (Object :- t) (Object :- a :- t) would already be good enough for this.

@alanz

I think getting all the unprocessed properties in a map will be fine for me, and gives me a convenient check that I am not missing anything.

Thanks

@MedeaMelana
Owner

Alright. :-) Closing this issue then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.