Add sub function to Spec #32

Merged
merged 1 commit into from Mar 24, 2016

Conversation

Projects
None yet
4 participants
Contributor

Horneth commented Mar 23, 2016

No description provided.

Horneth referenced this pull request in broadinstitute/cromwell Mar 23, 2016

Merged

Sub engine function Closes #597 #605

3 of 3 tasks complete

@scottfrazer scottfrazer commented on the diff Mar 24, 2016

@@ -2114,6 +2115,42 @@ task example {
Supported units are KiloByte ("K", "KB"), MegaByte ("M", "MB"), GigaByte ("G", "GB"), TeraByte ("T", "TB") as well as their [binary version](https://en.wikipedia.org/wiki/Binary_prefix) "Ki" ("KiB"), "Mi" ("MiB"), "Gi" ("GiB"), "Ti" ("TiB").
Default unit is Bytes ("B").
+
+## String sub(String, String, String)
+
+Given 3 String parameters `input`, `pattern`, `replace`, this function will replace any occurence matching `pattern` in `input` by `replace`.
+`pattern` is expected to be a [regular expression](https://en.wikipedia.org/wiki/Regular_expression). There are different implemetations of regular expression evaluators, different sets of rules etc... This choice is left to the implementor.
+
+Example 1:
+
+```wdl
+ String chocolike = "I like chocolate when it's late"

@scottfrazer scottfrazer and 1 other commented on an outdated diff Mar 24, 2016

@@ -86,6 +86,7 @@
* [File write_objects(Array\[Object\])](#file-write_objectsarrayobject)
* [File write_json(mixed)](#file-write_jsonmixed)
* [File size(File, \[String\])](#float-sizefile-string)
+ * [File sub(String, String, String)](#string-substring-string-string)
@scottfrazer

scottfrazer Mar 24, 2016

Contributor

link is not correct, should be #string-sub-string-string-string I think

@scottfrazer

scottfrazer Mar 24, 2016

Contributor

I don't really advertise this much, but I wrote a tool called mdtoc which is useful for stuff like this

$ pip install mdtoc
$ mdtoc SPEC.md

Seems that the size() function link might be wrong too?

@scottfrazer

scottfrazer Mar 24, 2016

Contributor

bah, I guess I was wrong, but the two headers are still not quite right

-  * [File size(File, \[String\])](#float-sizefile-string)
-  * [File sub(String, String, String)](#string-substring-string-string)
+  * [Float size(File, \[String\])](#float-sizefile-string)
+  * [String sub(String, String, String)](#string-substring-string-string)
@Horneth

Horneth Mar 24, 2016

Contributor

Oh nice catch. For the link the way I do it is I create the section, generate an html preview and then use whatever link the anchor points to.

Contributor

scottfrazer commented Mar 24, 2016

Besides the table of contents changes, 👍

Approved with PullApprove

@mcovarr mcovarr and 2 others commented on an outdated diff Mar 24, 2016

@@ -2114,6 +2115,42 @@ task example {
Supported units are KiloByte ("K", "KB"), MegaByte ("M", "MB"), GigaByte ("G", "GB"), TeraByte ("T", "TB") as well as their [binary version](https://en.wikipedia.org/wiki/Binary_prefix) "Ki" ("KiB"), "Mi" ("MiB"), "Gi" ("GiB"), "Ti" ("TiB").
Default unit is Bytes ("B").
+
+## String sub(String, String, String)
+
+Given 3 String parameters `input`, `pattern`, `replace`, this function will replace any occurence matching `pattern` in `input` by `replace`.
+`pattern` is expected to be a [regular expression](https://en.wikipedia.org/wiki/Regular_expression). There are different implemetations of regular expression evaluators, different sets of rules etc... This choice is left to the implementor.
@mcovarr

mcovarr Mar 24, 2016

Contributor

implemetations => implementations

That spelling of implementor may be a passing fad?

Do we really want to leave regexes so nebulously specified?

@cjllanwarne

cjllanwarne Mar 24, 2016

Contributor

I guess the problem is, the Python equivalent of WDL Cromwell might have a different regex evaluator? I guess it could be made more specific, e.g.:
Details of regex evaluation will depend on the execution engine running the WDL

@Horneth

Horneth Mar 24, 2016

Contributor

If not, how much more specific do we want to be ? I personally am no regex expert and I don't have any really strong opinion about which standard we should encourage/enforce :/

@mcovarr

mcovarr Mar 24, 2016

Contributor

Yeah I get that we'll have different impls under the hood, I just worry about setting up incompatibility issues. Maybe not a big deal

@mcovarr mcovarr commented on an outdated diff Mar 24, 2016

@@ -2114,6 +2115,42 @@ task example {
Supported units are KiloByte ("K", "KB"), MegaByte ("M", "MB"), GigaByte ("G", "GB"), TeraByte ("T", "TB") as well as their [binary version](https://en.wikipedia.org/wiki/Binary_prefix) "Ki" ("KiB"), "Mi" ("MiB"), "Gi" ("GiB"), "Ti" ("TiB").
Default unit is Bytes ("B").
+
+## String sub(String, String, String)
+
+Given 3 String parameters `input`, `pattern`, `replace`, this function will replace any occurence matching `pattern` in `input` by `replace`.
@mcovarr

mcovarr Mar 24, 2016

Contributor

occurence => occurrence

@mcovarr mcovarr commented on an outdated diff Mar 24, 2016

+
+Given 3 String parameters `input`, `pattern`, `replace`, this function will replace any occurence matching `pattern` in `input` by `replace`.
+`pattern` is expected to be a [regular expression](https://en.wikipedia.org/wiki/Regular_expression). There are different implemetations of regular expression evaluators, different sets of rules etc... This choice is left to the implementor.
+
+Example 1:
+
+```wdl
+ String chocolike = "I like chocolate when it's late"
+
+ String chocolove = sub(chocolike, "like", "love") # I love chocolate when it's late
+ String chocoearly = sub(chocolike, "late", "early") # I like chocoearly when it's early
+ String chocolate = sub(chocolike, "late$", "early") # I like chocolate when it's early
+}
+```
+
+The sub function will also accept `input` and `replace` parameters that can be coereced to a String (eg File). This can be useful to swap the extension of a filename for example
@mcovarr

mcovarr Mar 24, 2016

Contributor

eg => e.g.

@mcovarr

mcovarr Mar 24, 2016

Contributor

coereced => coerced

Contributor

mcovarr commented Mar 24, 2016

👍

Approved with PullApprove

@Horneth Horneth merged commit 00b4629 into develop Mar 24, 2016

1 check passed

code-review/pullapprove Approved by all reviewer groups.
Details

mcovarr deleted the subFunction branch Jul 25, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment