Code Monkey home page Code Monkey logo

Comments (7)

mmalcek avatar mmalcek commented on August 22, 2024 1

I Agree with your point and it's better to do it this way.
I did rewrite latest functions replaceAll and replaceAllRegex as you suggested (release is the same v1.0.16 rebuilded)
I will not touch other functions (at least for now) because this is a "breaknig change" so I'll think about some alias or change to major release with HUGE warning.

from bafi.

mmalcek avatar mmalcek commented on August 22, 2024

Hi I've added functions replaceAll and replaceAllRegex to v1.0.16
I know sprig and functions are highly inspired by sprig (sprig is also mentioned in functions.go) - however I needed more flexibility on functions design so I've decided for own functions implementation

btw: You are welcome to contribute and add functions if missing and generally usefull ;)

from bafi.

kpym avatar kpym commented on August 22, 2024

@mmalcek Thenks for considering my request !
I think that replaceAll and replaceAllRegex do not have the right signature. For all template functions the main agrument should be the last one, in this way we can pipe it. For example if I have a french decimal number written as string like "3,14" and I want to replace the decimal separator by point I would like to do {{ "3,14" | replaceAll "," "." }}.

My suggestion is to replace the definitions with

func replaceAll(old, new, src string) string 
func replaceAllRegex(regex, new, src string) string

By the way some functions in sprig have the same problem (putting the main argument in first and not last position).

from bafi.

kpym avatar kpym commented on August 22, 2024

@mmalcek The same is true, IMO, for other functions in bafi. For example if I use {{ 7 | sub 2 }} I'll get -5 and not 5. I think that sub(a,b) should be read as "substract a from b" and not "substract b from a". Same for div, mod,...
I know that this may looks like personal preference, but it is not. It is how golang templates are supposed to work ;)

from bafi.

kpym avatar kpym commented on August 22, 2024

@mmalcek Thanks for considering my request and modifying so quickly ! 🙏 Indeed, when adding a template function, the best is to think about how it will be used with pipes. But there is one situation where this is not possible: when the function is variadic (accepting multiple last arguments with ...). IMO, this is a point where the golang team made a bad decision by piping to the last, not to the first argument. But anyway, we can't change this, so we have to adapt 😋.

from bafi.

kpym avatar kpym commented on August 22, 2024

release is the same v1.0.16 rebuilded

In general, every time you add some functionality which is backward compatible you should change the second number, for example adding replaceAll should be v1.16.0. And every time you correct something minor, you should change the last one, for example v1.16.1.
I say this because when I executed :

go install github.com/mmalcek/bafi@latest

nothing happened because the version number hasn't changed (v1.0.16).

In any case, thanks for your work !

from bafi.

mmalcek avatar mmalcek commented on August 22, 2024

from bafi.

Related Issues (3)

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.