nextflow-io / nextflow-io/nextflow
Feature request: literal type
Nobody has claimed this yet.
- Dominant language
- Groovy
- Stars
- 3.5k
- Forks
- 811
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 61
Description
New feature
Hi, I would like to request the addition of a literal type to Nextflow, used to restrict a variable to a small set of specific values. A similar type already exists in Python.
Use case
This is generally useful, but it would especially help with parameter validation, in cases where the parameter must come from a list of options (e.g. the legacy publish_dir_mode, or step in nf-core/sarek).
Suggested implementation
This is largely based on the Python implementation
Definition
The contract allows Literal<v> or Literal<v1, v2, ...>, where v and vn are constants or literals. When multiple vn are passed, they must be of the same type. v cannot be a dataflow (channel or value).
Examples:
x: Literal<42> = 42--> correctx: Literal<42> = 55--> errory: Literal<"a", "b", "c"> = "b"--> also correct
Allowed constant types
Literals are intended for "atomic" constants, so support for arbitrary values is not required.
The following types are expected to work with literals: Boolean, Duration, Float, Integer, MemoryUnit, Path, String, VersionNumber.
The following types are not expected to work with literals: Iterable and its subtypes (List, Set, etc.), Map, Record.
The following types are categorically forbidden in literals: Channel, Value.
Nested literals
Nested literals are flattened before evaluation. For example:
Literal<Literal<1>, Literal<2>> === Literal<1, 2>
The resulting literal must comply with all assumptions for non-nested literals, in particular type equality.
Behaviour
A variable of type Literal<v> behaves like the type of v. In particular, operations on literals (except setting to a value) return the underlying type. For example:
x: Literal[1] = 1
y: Literal[2] = 2
z = x + y
// the type of z is `Integer`
Equivalence
Literals are equivalent if their underlying values are of the same type and are equal.
Params
Parameters of type Literal[v] default to v when no default value is passed (although this is useless in practice). Parameters of type Literal[v1, v2, ...] default to null.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no implementation files, tests, or entry points. Start by locating Nextflow's type-checking and parameter-validation code, then compare its existing type behavior with the linked Python Literal specification. Done means Literal values follow the stated allowed types, nesting, equivalence, assignment, operations, and parameter-default rules, with coverage for the examples and restrictions described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100