groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7540) Add StringGroovyMethods.collectReplacements(String, Map)
Date Wed, 05 Aug 2015 03:02:04 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-7540?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14654733#comment-14654733
] 

Paul King commented on GROOVY-7540:
-----------------------------------

There are existing ways to do most of what you want:
{code}
def r1 = ["o":"a", "a":"o"]
assert "foobar".toList().collectMany{ r1.containsKey(it) ? [r1[it]]: [it] }.sum() == 'faabor'

def r2 = ["foo":"bar", "bar":"baz"]
def ans = "foo"
r2.each { k, v -> ans = ans.replaceAll(k, v) }
assert ans == 'baz'
{code}
That doesn't mean we shouldn't provide some more Groovy shortcuts.

But I think we need to think about behaviour compared to other methods. Currently the existing
collectReplacements variants work a character at a time.

> Add StringGroovyMethods.collectReplacements(String, Map)
> --------------------------------------------------------
>
>                 Key: GROOVY-7540
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7540
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Jochen Kemnade
>            Priority: Minor
>
> It should be possible to use a map with {{collectReplacements}}, like in
> {code}
> "f006ar".collectReplacements(["0":"o", "6":"b"])
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message