Giter VIP home page Giter VIP logo

Comments (8)

takeda avatar takeda commented on July 20, 2024 1

@pdrum generic.Number is currently an alias for float64, as mentioned in the ticket float64 can't be used as a slice index or len argument in make().

generic.Integer could be replaced with int, int8, int16, int32, int64, uint, uint8, unit16, uint32, uint64 I don't think it is any less meaningful than generic.Number, having said that I believe (I didn't test it) not using generic.* and just assigning the custom type to int would just work, so I'm thinking that creating generic.Integer would be just for completeness sake, since we already have generic.Number assigned to float64

from genny.

FlorianUekermann avatar FlorianUekermann commented on July 20, 2024

I would like to see "Integer" added instead changing Number to int.

Integers support more operators than floats, which means "type Integer int" is necessary if you want to use those operators.

Similar to how "type Type interface{}" is useful for indicating and ensuring support for a less specific set of types than "type Number float64", the latter is useful for indicating and ensuring support for integers and floats.

from genny.

pdrum avatar pdrum commented on July 20, 2024

I don't understand what generic.Integer is good for. As far as I understand this type can only be replaced with int so how is it different with just using int instead of sth like generic.Integer in templates? Will you elaborate please? @rwl

from genny.

rwl avatar rwl commented on July 20, 2024

IIRC, I was trying to support generating different types of int e.g. int32, int64 etc. In the end I dropped genny and just used text/template directly.

from genny.

dmoles avatar dmoles commented on July 20, 2024

Something like this would be useful for generating code for enum-type constants.

from genny.

dmoles avatar dmoles commented on July 20, 2024

@takeda — So I just tried this, and naively assigning the custom type to int (or uint32 or what have you) gets you an extra type declaration that you may not want — type T generic.Type gets deleted, type T int gets transformed to type MyType int.

As a workaround, if what you want is for your templates to compile, behave well in your IDE, etc., you can put the type declarations in a separate file in the same directory. As far as I can tell this just works—which is interesting, because it suggests the whole generic.Type mechanism is unnecessary.

from genny.

takeda avatar takeda commented on July 20, 2024

Ah I see, I forgot that genny removes it. In that case I agree that Integer type should be included. The workaround you gave is still a workaround and generic.* is more elegant I wouldn't call it unnecessary.

from genny.

dmoles avatar dmoles commented on July 20, 2024

It does make the templates more readable and more obviously templates.

from genny.

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.