murex icon indicating copy to clipboard operation
murex copied to clipboard

support for type constraints

Open lmorg opened this issue 2 years ago • 2 comments

Describe the problem: Add support for custom types with type constraints.

Possible ways to implement: eg

datatype yyyymmdd {
  inherit: str
  constraint: %({
    -> regexp 'm/[0-9]{4}-[0-9]{2}-[0-9]{2}/'
  })
}

Additional context:

  • inherit will be the built in data type (marshallers et al) to use for that data type.
  • contraint will be a Murex code block that takes the data as value from STDIN and returns a non-zero exitnum if the constraint isn't met. STDOUT and/or STDERR will be output to terminal if constraint isn't met.

lmorg avatar Jun 04 '23 00:06 lmorg

A little more thought on this feature:

  • The function should be called constraint
  • Which means we cannot have constraint as a property (gets a little repetitive otherwise). So I've opted for Validation instead
constraint yyyymmdd {
    Inherit: str
    Validation: '{
        -> regexp (m/[0-9]{4}-[0-9]{2}-[0-9]{2}/)
    }'
}

lmorg avatar Jul 08 '23 22:07 lmorg

Given how expressions are now first class citizens, Validation should probably be passed as a variable rather than a pipe. eg

constraint yyyymmdd {
    Inherit: str
    Expression: '$VALUE =~ "[0-9]{4}-[0-9]{2}-[0-9]{2}"'
}

lmorg avatar Dec 10 '23 11:12 lmorg