lib: Add string.find and object.{map,asNamedArray}#38
Conversation
Hermitise this repository as the version of golangci-lint used is not
compatible with more recent Go releases so we will either need to pin to
an older version of Go or upgrade golangci-lint. The former is tricky to
do simply, and the latter is painful with the churn in golangci-lint.
The alternative is to use hermit and pin the versions currently
required. This is what is done here:
hermit init --no-git
hermit install go-1.13.5
hermit install golangci-lint-1.37.0
Remove the custom version login for golangci-lint from the Makefile, and
add the hermit auto-activation. Note that the only 1.13 version of Go in
hermit is 1.13.5, while the latest point release is 1.13.15. I chose
1.13 as that is what is in the `go.mod` file.
Subsequent commits will bump these versions and adjust the code to work
with newer golangci-lint errors.
Update GitHub CI to rely on hermit for installing the right versions
instead of using specific actions. Also run on all PRs, not just those
to be merged to master. This allows CI to run for stacked PRs.
Rename `jx` to `jnx` as the jx binary name is already taken by jenkinsx. But jnx is also a better name since it sounds like jinx, and that's what you say when someone duplicates a word at the same time as you. jsonnet is about de-duplicating through templating, so jnx works. It can also be pronounced as a single syllable, which is also nice. Split the Go flag version of jnx into a completely separate program rather than having a `parseCLI()` function selected by build tags. The only reason for the flag version is to use the flag code path of jsonnext to demonstrate its use and to verify it works. jnx itself is going to evolve in future to contain subcommands which I do not intend to support in the flag version of jnx. So split it out so jnx can evolve on its own. Keep `jx.jsonnet` for now for backwards compatibility. It will be removed when I know I've removed all existing uses under that name.
Add some functions to the jnx library: * string.find: Returns the index of a substring within a string or -1 if not present. * map: Apply a function to each [k, v] pair of an object and return an array of values of the result of that function. * asNamedArray: Converts an object to an array of values from that object where each object has a field added with the key of that field (defaults to the 'name' field).
juliaogris
left a comment
There was a problem hiding this comment.
just out of curiosity:
so the standard library has no substring find method in jsonnet?
also: isn't map typically used on arrays?
other than that, no questions, one lil typo. lgtm.
| if !std.isString(str) then | ||
| error ('string.find first param must be a string, got ' + std.type(str)) | ||
| else if !std.isString(char) then | ||
| error ('string.find secomd param must be a string, got ' + std.type(char)) |
It looks like there is one now - I guess it was not there when I wrote this: Not quite the same, but if I needed my function signature, I could implemented my find in terms of this one. I'll remove this.
Probably. But it's still the same operation regardless of the data structure - apply a function to each element of the data structure. Perhaps I should call it |
Add some functions to the jnx library:
not present.
array of values of the result of that function.
object where each object has a field added with the key of that field
(defaults to the 'name' field).