# DRY Principle in statically typed Nextflow: reusing output path definitions in \`output:\` and \`script:\` sections

**URL:** <https://community.seqera.io/t/dry-principle-in-statically-typed-nextflow-reusing-output-path-definitions-in-output-and-script-sections/2642>\
**Category:** Ask for help\
**Tags:** nextflow\
**Created:** [April 25, 2026, 7:08am UTC](https://community.seqera.io/t/dry-principle-in-statically-typed-nextflow-reusing-output-path-definitions-in-output-and-script-sections/2642 "2026-04-25T07:08:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![valterschutz](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/valterschutz/32/2423_2.png) [@valterschutz](https://community.seqera.io/u/valterschutz)\
**Post date:** [April 25, 2026, 7:08am UTC](https://community.seqera.io/t/dry-principle-in-statically-typed-nextflow-reusing-output-path-definitions-in-output-and-script-sections/2642/1 "2026-04-25T07:08:41Z")

</div>

Hi all!

I’ve been really enjoying using Nextflow recently for setting up ML pipelines. I previously used Snakemake, but found that the path-based logic became too complex as the pipeline grew in complexity.

There is one quirk that irritates me slightly though. This is strongly related to a previous post, which asked the same question but for legacy, untyped synax: [DRY Principle in Nextflow: Reusing Output Path Definitions in `output:` and `script:` sections](https://community.seqera.io/t/dry-principle-in-nextflow-reusing-output-path-definitions-in-output-and-script-sections/2203)

According to [Processes (typed) | Seqera Docs](https://docs.seqera.io/nextflow/process-typed#outputs), I can define a process like

```auto
process myProcess {
    input:
    message: String

    output:
    out_file: Path = file("${message}.txt")

    script:
    """
    echo "${message}" > "${message}.txt"
    """
}

```

but this forces me to repeat the same output path logic twice. I would like to just use `${out_file}` in the script block, like this:

```auto
process myProcess {
    input:
    message: String

    output:
    out_file: Path = file("${message}.txt")

    script:
    """
    echo "${message}" > "${out_file}"
    """
}

```

but if I try this then I get the error

```auto
`out_file` is not defined

```

Is there any chance of this getting added in the future? I really like the new typed syntax and would like to use it to the greatest extent possible.

BR, Valter

---

<div class="post-metadata">

**Author:** ![bentsherman](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bentsherman/32/52_2.png) [@bentsherman](https://community.seqera.io/u/bentsherman)\
**Post date:** [April 26, 2026, 1:48am UTC](https://community.seqera.io/t/dry-principle-in-statically-typed-nextflow-reusing-output-path-definitions-in-output-and-script-sections/2642/2 "2026-04-26T01:48:21Z")

</div>

Rob’s answer in the other thread also applies here – you can assign the file pattern to a variable in the script block and use it in the output block. Using `out_file` in the script block wouldn’t make sense because `out_file` is being _defined_ in the output block, which is evaluated after the script block

---

<div class="post-metadata">

**Author:** ![valterschutz](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/valterschutz/32/2423_2.png) [@valterschutz](https://community.seqera.io/u/valterschutz)\
**Post date:** [April 26, 2026, 6:12am UTC](https://community.seqera.io/t/dry-principle-in-statically-typed-nextflow-reusing-output-path-definitions-in-output-and-script-sections/2642/3 "2026-04-26T06:12:37Z")

</div>

Thanks! This seems to work:

```auto
process myProcess {
    input:
    message: String

    output:
    out_file: Path = file(out_file)

    script:
    out_file = "${message}.txt"
    """
    echo "${message}" > "${out_file}"
    """
}

```

I still think that the desired behavior I posted looks slightly more succinct, but if the output block cannot be evaluated earlier then this is a fair tradeoff.

---

<div class="post-metadata">

**Author:** ![bentsherman](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bentsherman/32/52_2.png) [@bentsherman](https://community.seqera.io/u/bentsherman)\
**Post date:** [April 26, 2026, 1:32pm UTC](https://community.seqera.io/t/dry-principle-in-statically-typed-nextflow-reusing-output-path-definitions-in-output-and-script-sections/2642/4 "2026-04-26T13:32:18Z")

</div>

Some people even prefer to define the output block after the script block to better reflect the evaluation order:

```groovy
process myProcess {
    input:
    message: String

    script:
    out_file = "${message}.txt"
    """
    echo "${message}" > "${out_file}"
    """

    output:
    out_file: Path = file(out_file)
}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/system/32/2402_2.png) [@system](https://community.seqera.io/u/system)\
**Post date:** [May 3, 2026, 1:32pm UTC](https://community.seqera.io/t/dry-principle-in-statically-typed-nextflow-reusing-output-path-definitions-in-output-and-script-sections/2642/5 "2026-05-03T13:32:31Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
