Closed fuzzypixelz closed 3 months ago
I think find_all
would make sense, yes. I would go for option 2: because Nickel arrays aren't lazy as in, say, Haskell, the first solution is actually not really lazy, since @
will force pretty much everything. Also, regex are really a core string processing tool, and it's reasonable to have those operation primops for performance reasons in configuration language, IMHO. Happy to review a contribution for this
Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Currently there is no function in
std.string
to find all matches of a regular expression in a string. The existing functionstd.string.find
only returns the first match.Describe the solution you'd like A clear and concise description of what you want to happen.
I would like a new function
std.string.find_all
of the following type:Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
A pure-Nickel implementation would look like:
This could be added to
std
as is or re-implemented as primitive op usingregex::Regex::find_iter
. In order to turn theMatches
iterator into a Nickel array, we might need to consume the entire iterator at once.The downside of the first option is that we miss on the efficiency of a primitive op. The downside of the second option is more implementation work and a lack of laziness.
Additional context Add any other context or screenshots about the feature request here.
N/A