Let's unify all the data related actions (except 'Add a variable' and 'Set a data value') into the 'Calculate a value' action by implementing cases for string, list, and file data types alongside the existing integer support. Each calculation would support a pair of inputs or single value and NULL for each data type by performing the appropriate operation to calculate a desirable output based on the data types inputed. If a constructed logical operation isn't supported, then a graceful failure would be in order.
95% of the operations I a propose to incorporate here are already done and linked (a few of which twistor and I did for #745314: Action: transform text); what's left is to merge all of it into one very valuable action. Then we will also need an upgrade path for the existing 'Add / Remove an item to/from a list'.
This plan started out simply as an attempt to provide a simple, yet robust improvement to the current method of combining two strings, ie "[first name] + [last name]", using the token input with a space between two values. ...But then I thought about that other issue... investigated a little further, and everything seemed to line up perfectly...
The Plan
- Integers: Adding two numbers
- Two strings: Appending one string with another #1539452: how to make a rule to add (append) data to a longtext field
- A single list: combining multiple items of a list into one element Combine list items into a string
- Two lists: Put them together one after the other?, also #1386370: How to: sum of integer values in a loop?
- Two files: eg. pdf's could be merged
- Integers: Getting the difference between two numbers
- Strings / Long texts: Get two versions of a text Diff, #1343442: Condition : "Text contains any word in a list", and this python discussion
- Single list: Split a string into a list
- Multiple Lists: #1252860: Action: Differences between lists. Set difference and Calculus of subtraction
- Date/time intervals: could produce, user 1 posted [node:title] 10 min before he posted [node2:title] (or done manually with date to integer conversion).
- A single integer: #1525582: Action: generate a list from an integer
- A string and a number: Multiply the occurrences for an element of a list by a factor, ie repeat something a number of times (perhaps a great solution for repeating date field data, See Date API issue: #298334: Repeating dates in separate nodes)
- Two strings: stackoverflow: multiplying strings
- Strings and lists: Cartesian Product, see deck of cards example
- Two lists: Permutations, Multiplicative inverse of two lists (those two require implode then explode afaict)
- Previous two: I need to read up more on these. Related symbols / concepts: asterisk, dot product, tensor product | *, ·, ⊗
- Integers: Dividing two numbers, see #1479526: Action: modulus, ceiling, floor (rounding)
- List and integer: Divide a list into a group of strings
Related functions
It will also be possible to reuse the functions above for creating more complex operations, like mean and multiplicative inverse and Cartesian product, though these can also be directly implemented with the action. Sorting and reversing lists and strings is already implemented to work numerically and alphabetically would lend to this and is as well, see #745314: Action: transform text.
For more wiki reading, see String operations, String functions, Operations on Functions.
Comments
Comment #0.0
mitchell CreditAttribution: mitchell commentedadded link to issue
Comment #0.1
mitchell CreditAttribution: mitchell commentedadded link
Comment #0.2
mitchell CreditAttribution: mitchell commentedl
Comment #0.3
mitchell CreditAttribution: mitchell commentedl
Comment #0.4
mitchell CreditAttribution: mitchell commentedmultiplication of an integer
Comment #0.5
mitchell CreditAttribution: mitchell commentedstring and number multiplication
Comment #0.6
mitchell CreditAttribution: mitchell commentedexplode link to code
Comment #0.7
mitchell CreditAttribution: mitchell commentedrewriting intro text
Comment #0.8
mitchell CreditAttribution: mitchell commentedwc
Comment #1
mitchell CreditAttribution: mitchell commentedDate API issue: #298334: Repeating dates in separate nodes.Added.Comment #2
mitchell CreditAttribution: mitchell commentedCombining files.AddedComment #2.0
mitchell CreditAttribution: mitchell commentedfiles and conditions
Comment #2.1
mitchell CreditAttribution: mitchell commenteda
Comment #3
mitchell CreditAttribution: mitchell commentedChanging title and tagging 'lists and loops' related to #1525582: Action: generate a list from an integer.
Comment #4
mitchell CreditAttribution: mitchell commentedMarked #1342520: Calculate a value with an empty input as a duplicate of this issue.
Comment #4.0
mitchell CreditAttribution: mitchell commentedupdates
Comment #4.1
mitchell CreditAttribution: mitchell commentedlist addition link
Comment #4.2
mitchell CreditAttribution: mitchell commentedtwo lists