Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I access fields in gogol records? Lens and regular fieldselectors don't work #179

Open
tonyalaribe opened this issue Aug 15, 2022 · 2 comments

Comments

@tonyalaribe
Copy link

Hi, this is likely a trivial question, but i've been banging my head on this for a bit too long.

How do I access the fields in a Pubsub RecievedMessage record?

I had this line of code before the updates:

let rmMsg = msg ^? rmMessage . _Just . psData . _Just

But this doesn't work anymore.

So i saw tried what I saw from the generic-lens package and from diving into gogol-pubsub codebase:

let rmMsg = msg ^? #message . _Just . #data . _Just

Which gives the error:

    • No instance for (IsLabel
                         "message"
                         (p0 (Maybe a0) (f0 (Maybe b0))
                          -> ReceivedMessage -> Const (First ByteString) ReceivedMessage))
        arising from the overloaded label ‘#message’
        (maybe you haven't applied a function to enough arguments?)
    • In the first argument of ‘(.)’, namely ‘#message’
      In the second argument of ‘(^?)’, namely
        ‘#message . _Just . #data . _Just’
      In the expression: msg ^? #message . _Just . #data . _Just
    |
102 |           let rmMsg = msg ^? #message . _Just . #data . _Just
    |                              ^^^^^^^^

Is it that the lenses are not derived on the fields?

Next, I tried to fall back on regular haskell

let rmMsg = fromMaybe "" $ maybe (Nothing) (data') (message msg)

But then I get an error about the NoFieldSelectors extension. So it seems the fieldselectors are not exposed, so I can't query using them either.

   • Variable not in scope: data' :: a0 -> Maybe (Maybe ByteString)
    • Perhaps you want to add ‘data'’ to the import list
      in the import of ‘Gogol.PubSub.Types’
      (src/ProcessMessage.hs:12:1-74).
      NB: ‘data'’ is a field selector belonging to the type ‘PubsubMessage’
      that has been suppressed by NoFieldSelectors
    |
104 |           let rmMsg = fromMaybe "" $ maybe (Nothing) (data') (message msg)
    |                                                       ^^^^^

@tonyalaribe
Copy link
Author

I was able to get this to work with lenses, but like this:

let rmMsg = msg ^? field @"message" . _Just . field @"data'" . _Just . _Base64

field @"blabla" The intended way for accessing record fields on gogol?

@endgame
Copy link

endgame commented Jan 17, 2023

Yes. Or #message, using -XOverloadedLabels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants