Giter Site home page Giter Site logo

Comments (5)

krissrex avatar krissrex commented on June 7, 2024

Label: feature request

from http4k.

dzappold avatar dzappold commented on June 7, 2024

Have you tried to use a Lens as second parameter?
I guess it could look similar to Lens(myMeta) { _ -> LocalTime.now() }

from http4k.

krissrex avatar krissrex commented on June 7, 2024

Have you tried to use a Lens as second parameter? I guess it could look similar to Lens(myMeta) { _ -> LocalTime.now() }

Yes, but I might have done it wrong. I struggled with the constructor, because I couldn't create a Meta object.
I looked at the official defaulted, which did:

        defaulted(name, Lens(Meta(false, location, paramMeta, name, description)) { default }, description)

, but I dont have access to location and paramMeta when I want to create myMeta.

  Query.instant().defaulted("start", Lens(meta = ???, { _ -> Instant.now() }))

The source code isn't obvious either, so I have no clue what location and meta are, and if I can construct them myself easily, or what data should even go into them. If you have any advice, I would appreciate it.

from http4k.

krissrex avatar krissrex commented on June 7, 2024

It seems the location and paramMeta come from the Query object, so something like this?

  Query.instant()
      .defaulted(
          "start",
          Lens(
              meta =
                  Meta(
                      required = false,
                      location = Query.location,
                      paramMeta = ParamMeta.StringParam,
                      name = "start",
                      description = "My description of start"),
              { _ -> Instant.now() }))

Quite verbose compared to e.g. a Query.instant().defaultFactory("start", { Instant.now() })

from http4k.

daviddenton avatar daviddenton commented on June 7, 2024

I've made the defaulted mechanism take a LensExtractor (Request) -> T and made it a fun interface, so you can now do: ```
Query.int().defaulted("foo", { 123 })


Will be out in the next version

from http4k.

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.