qtil
advanced-security/qtil-swift 0.0.3
Search

Module TypedListBuilderOf

A module that declares predicates of2(...) to of8(...) for building a type that extends string from a list of arguments of a custom type T, converted to strings via the toString predicate, using a custom separator.

The toString predicate should be a unary predicate that takes an argument of type T and returns a string. It should be declared with bindingset[result] and bindingset[arg], to have two way binding between the input and output, allowing conversion and deconversion via one predicate.

If you do not need to build types that extend string from non-string arguments, you can simply use the module TypedListBuilder<separator, S>. To build a string from non-string arguments, use ListBuilderOf<separator, T, toString>. You may also use the module ListBuilder<separator> to build a string from a list of string-valued arguments.

Example usage:

bindingset[this]
class MyString extends string {
  bindingset[this]
  string reverse() {
    result = concat(string c, int idx | c = this.charAt(idx) | c order by idx desc)
  }
}

bindingset[result] bindingset[arg]
string toString(MyString arg) {
  result = arg.toString() and
  result.toString() = arg
}

// Selects "43,21".
// Resulting type is of `MyString`, which allows for the `.reverse()` member predicate here.
select TypedListBuilderOf<Separator::comma/0, MyString, int, toString/1>
    ::of2(12, 34)
   .reverse()

Import path

import qtil.list.ListBuilder

Predicates

of1

Produces a CSV-like list of 1 item, cast to type S which extends string, using the custom separator.

of2

Produces a CSV-like list of 2 items, cast to type S which extends string, using the custom separator.

of3

Produces a CSV-like list of 3 items, cast to type S which extends string, using the custom separator.

of4

Produces a CSV-like list of 4 items, cast to type S which extends string, using the custom separator.

of5

Produces a CSV-like list of 5 items, cast to type S which extends string, using the custom separator.

of6

Produces a CSV-like list of 6 items, cast to type S which extends string, using the custom separator.

of7

Produces a CSV-like list of 7 items, cast to type S which extends string, using the custom separator.

of8

Produces a CSV-like list of 8 items, cast to type S which extends string, using the custom separator.

Parameters