Added triplet() and triplet_wrap().

This commit is contained in:
Revar Desmera 2019-06-19 01:31:44 -07:00
parent 02da52c097
commit d069cf39ce

View file

@ -433,7 +433,7 @@ function subindex(v, idx) = [
// Usage: // Usage:
// pair(v) // pair(v)
// Description: // Description:
// Takes a list, and returns a list of adjacent pairs from it, with the last item paired with the first at the end. // Takes a list, and returns a list of adjacent pairs from it.
// Example: // Example:
// l = ["A","B","C",D"]; // l = ["A","B","C",D"];
// echo([for (p=pair(l)) str(p.y,p.x)]); // Outputs: ["BA", "CB", "DC"] // echo([for (p=pair(l)) str(p.y,p.x)]); // Outputs: ["BA", "CB", "DC"]
@ -444,13 +444,35 @@ function pair(v) = [for (i=[0:1:len(v)-2]) [v[i],v[i+1]]];
// Usage: // Usage:
// pair_wrap(v) // pair_wrap(v)
// Description: // Description:
// Takes a list, and returns a list of adjacent pairs from it, with the last item paired with the first at the end. // Takes a list, and returns a list of adjacent pairss from it, wrapping around from the end to the start of the list.
// Example: // Example:
// l = ["A","B","C",D"]; // l = ["A","B","C","D"];
// echo([for (p=pair_wrap(l)) str(p.y,p.x)]); // Outputs: ["BA", "CB", "DC", "AD"] // echo([for (p=pair_wrap(l)) str(p.y,p.x)]); // Outputs: ["BA", "CB", "DC", "AD"]
function pair_wrap(v) = [for (i=[0:1:len(v)-1]) [v[i],v[(i+1)%len(v)]]]; function pair_wrap(v) = [for (i=[0:1:len(v)-1]) [v[i],v[(i+1)%len(v)]]];
// Function: triplet()
// Usage:
// triplet(v)
// Description:
// Takes a list, and returns a list of adjacent triplets from it.
// Example:
// l = ["A","B","C","D","E"];
// echo([for (p=triplet(l)) str(p.z,p.y,p.x)]); // Outputs: ["CBA", "DCB", "EDC"]
function triplet(v) = [for (i=[0:1:len(v)-3]) [v[i],v[i+1],v[i+2]]];
// Function: triplet_wrap()
// Usage:
// triplet_wrap(v)
// Description:
// Takes a list, and returns a list of adjacent triplets from it, wrapping around from the end to the start of the list.
// Example:
// l = ["A","B","C","D"];
// echo([for (p=triplet_wrap(l)) str(p.z,p.y,p.x)]); // Outputs: ["CBA", "DCB", "ADC", "BAD"]
function triplet_wrap(v) = [for (i=[0:1:len(v)-1]) [v[i],v[(i+1)%len(v)],v[(i+2)%len(v)]]];
// Function: zip() // Function: zip()
// Usage: // Usage:
// zip(v1, v2, v3, [fit], [fill]); // zip(v1, v2, v3, [fit], [fill]);