Coder Social home page Coder Social logo

Comments (9)

luke-clifton avatar luke-clifton commented on June 23, 2024 1

Ha, we posted at the same time. 👍

from waargonaut.

mankyKitty avatar mankyKitty commented on June 23, 2024

There isn't anything in the index for that position, so it is considered a failure. I don't think I have explicit documentation for this behaviour, I'll add some in.

from waargonaut.

luke-clifton avatar luke-clifton commented on June 23, 2024

So, what I want to do is, go down into an object, then do a foldCursor (or a rightwardSnoc). I'm perfectly happy for that to just give me the initial value of the accumulator if the object is empty. What is the alternative? If I check for failure on the down I still don't know why that is, it could be because it's a text or numeric field.

Or, rephrased, how can I check that my cursor is currently pointed at an object without parsing it all into a Json?

from waargonaut.

luke-clifton avatar luke-clifton commented on June 23, 2024

Which, looking at the code just now, is exactly what your listAt is trying to do. So, if you listAt and the cursor is sitting in front of a text or numeric field, it will result in an empty list, which seems slight counter-intuitive.

from waargonaut.

mankyKitty avatar mankyKitty commented on June 23, 2024

That listAt behaviour seems a bit more 'bug' than 'counter-intuitive', so thanks for that !

Currently there isn't a direct way to check if you're currently looking at an object or other specific type, without going to the Json structure then using the lenses and prisms to nose around. That's a useful feature though and wouldn't be difficult to include.

To keep you moving, you could take advantage of the Alt instance for Decoder to combine alternatives for what may exist at a given cursor position. Until I fix the listAt this will mean you need to be aware of ordering considerations, which isn't awesome.

Alternatively, you are able to use the functions from the library that powers the cursor itself hw-json. Specifically from the module HaskellWorks.Data.Json.Type.

jsonTypeAt (unJCurs cursor) :: Maybe JsonType

Using Alt would be my first preference though. Does any of that help?

from waargonaut.

luke-clifton avatar luke-clifton commented on June 23, 2024

It seems that exposing jsonTypeAt is what I want.

from waargonaut.

mankyKitty avatar mankyKitty commented on June 23, 2024

I'll leave this open until I've patched listAt others if I find more

from waargonaut.

luke-clifton avatar luke-clifton commented on June 23, 2024

@mankyKitty I've posted a patch.

from waargonaut.

luke-clifton avatar luke-clifton commented on June 23, 2024

Fixed by #39

from waargonaut.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.