Wikifunctions:Suggest a function

From Wikifunctions

Do you have an idea for a new function? Suggest it here! It may help to refer to our glossary.

You can go and create a function right away if you have the user-rights, and it aligns with other work.

Note that for now we only support strings and booleans as input and output types of functions. More types are coming in the next few months.

Once created, consider adding new Functions to the catalogue.

Proposed functions requiring only String and Boolean types

String manipulation functions

String character discard functions

String character replacement functions

String search functions

String escaping and unescaping functions

String encoding and decoding functions

String presentation functions

String colour notation functions

  • complementary colour in RGB colour model ("#FF0000" ⇒ "#00FFFF")
    Great question. I don't think there is a position documented on Wikifunctions for how to handle invalid input to a function. Can we throw exceptions? Return null? Dhx1 (talk) 13:23, 6 August 2023 (UTC)Reply[reply]
    This shouldn't be a string function. This should be a type that represents a RGB color (with corresponding validation function (hopefully it can just be three unsigned 8bit integers)) and a function that returns the complementary color. 0xDeadbeef (talk) 12:38, 7 August 2023 (UTC)Reply[reply]

String notation validation checks

String validation checks

Wikitext string operations

  • Done italicise in Wikitext (Z11019) italicise (ABC -> ''ABC''), careful if the input has wikitext special characters in it
  • Done bold in Wikitext (Z11139) bold (ABC -> '''ABC'''), careful if the input has wikitext special characters in it
  • Escape all special characters in a string so that they don't become functional when in Wikitext. (Is this possible? Or would it always be better to wrap with <nowiki></nowiki>?)
  • If we do this, then someone doing italicise and then bold on the resulting string would run into problems. -wd-Ryan (Talk/Edits) 22:05, 1 September 2023 (UTC)Reply[reply]

CSV list operations

Morphological functions




Proposed functions requiring future types

Note these functions cannot be implemented yet as Wikifunctions currently only supports Boolean and String types for function definitions.

If one wishes to nevertheless attempt to define and implement them,

  • the functions and implementations should indicate prominently in their labels that their input/output types must be adjusted once support for the appropriate replacement types become available; and
  • the functions should not be used in the implementations of any other functions, as the later adjustment of input/output types to appropriate replacements will break those implementations.

String manipulation functions

  • right (returns a substring from the end of a specified string up to a number of characters)
  • left (returns a substring from the beginning of a specified string up to a number of characters)
  • duplicate string n times (e.g. dup("a",5) -> "aaaaa")

String analysis functions

  • string length (Hello -> 5)
  • count distance between two letters in given alphabet (default to 26-charcater western alphabet. case insensitive. e.g. "a" & "A" ⇒ 0; "K" & "N" ⇒ 3)
  • Done Hamming distance between two strings of equal length, e.g. "Wikipedia" & "Wikimedia" ⇒ 1. - (!) hamming distance between two strings (Z11328)

String encoding and decoding functions

(would be better with types representing a stream of bytes)

String validation checks

(alphabet needs to be specified when calling these functions)

  • check if string is a pangram for a specified alphabet
  • Could you just specify the "alphabet" in a second string "abcdefghijklmnopqrstuvwxyz" ?

Natural language functions

  • Choose singular or plural based on number (e.g. singularOrPlural("person",6") -> "people")

Cryptographic hash functions

(would be better with types representing a stream of bytes)

Colour functions

  • return colour contrast ratio (per [1]) of two RGB colours (provided as strings e.g. "#FF0000")

Date functions

  • check if year (for a specific calendar) is a leap year:
  • return weekday (2023-08-03 ⇒ Thursday (or should this return Q129, for Thursday (Q129)?))
  • date to weekday number (0-6)
  • advance n days (2023-08-03 & "69" ⇒ 2023-10-11)
  • go back n days
  • string to date
  • date to ISO 8601 string
  • date to year (yyyy)
  • date to month of the year (1-12)
  • date to month name (January-December)
  • date to day of the month (1-31)
  • date to hour of the day (0-23)
  • date to minutes (0-59)
  • date to seconds (0-59)

Basic list/iterable functions

  • map, return a list of elements resulted from a given function
  • filter, return elements meeting criteria given by a function
  • take, return n items of a list
  • skip, return a new list that don't have n first of items of the given list
  • reverse, return a reversed list of a given list
  • contains, if a list has a specific item
  • every/all, return true if all of items of a list meets criteria given by a function, otherwise false
  • any, return true if one the items of a list meets criteria given by a function, otherwise false
  • slice, a combination of take/skip
  • length, size of a list
  • fold/reduce
  • group
  • flat
  • sort, by a given function
  • apply a function to every element of a list, and get a list of answers

Basic numerical functions

  • round up ("1.289" & "2" ⇒ "1.29"; "5678" & "2" ⇒ "5700")
  • round down
  • return integer value (5678.678 ⇒ 5678)
  • decode Roman numerals ("X" ⇒ 10; 2023 ⇒ MMXXIII)
    22.5px Doing... : Roman to Arabic numeral (Z11023): Convert a Roman numeral to Arabic numeral
  • encode as Roman numerals (10 ⇒ "X"; MMXXIII ⇒ 2023)
    22.5px Doing... : Arabic to Roman numeral (Z11022): Convert a positive integer [1, 4999] to roman numeral
  • return cardinal (23 ⇒ "twenty-three")
  • return ordinal (23 ⇒ "twenty-third")
  • Body Mass Index (80kg and 1.80m ⇒ 24)
  • Convert money from US$ to anything else
  • Kronecker delta

Data serialization functions

  • parse a string as JSON
  • extract string from JSON object based on JSONPath ({"name":"Alice"}, "$.name" ⇒ "Alice")
    Why not first convert a JSON string to an object, and then have a function that extracts fields based on JSONPath? Doing Stringly-typed things like this proposal as defined isn't a good idea. 0xDeadbeef (talk) 16:16, 5 August 2023 (UTC)Reply[reply]
    This seems to be a good idea, thanks! I moved and splitted the proposal accordingly. --1-Byte (talk) 09:51, 6 August 2023 (UTC)Reply[reply]

CSV list operations

  • Convert a validly formatted CSV list to a list (new datatype) of strings.

External function lists

Wikititle function

See discussion at en:User talk:RMCD bot#Circular RM notice posted at talk page. Wbm1058 (talk) 02:11, 17 August 2023 (UTC)Reply[reply]