Branch link callbacks - adamjgrant/permutations GitHub Wiki

Branch callbacks can be used to come back to a permutation point after Branch links have run their course.

{
  "main": [
    "A",
    ["B", { "branch":  "other_letters" }],
    ["C", { "branch":  "other_letters", "then": [ "X", "Y", "Z", [ "1", "2", "3" ] ] }]
  ],
  "other_letters": [
    "D", [
      "E", "F"
    ]
  ]
}

This produces

ABDE
ABDF
ACDEX1
ACDEX2
ACDEX3
ACDEY1
ACDEY2
ACDEY3
ACDEZ1
ACDEZ2
ACDEZ3
ACDFX1
ACDFX2
ACDFX3
ACDFY1
ACDFY2
ACDFY3
ACDFZ1
ACDFZ2
ACDFZ3

Because then arrays are regular branch arrays, all the same features apply in them. So this is possible as well:

{
  "main": [
    "A",
    ["B", { "branch":  "other_letters" }],
    ["C", { "branch":  "other_letters", "then": [
      "X", "Y", "Z", [
        "1", "2", "3", { "branch": "other_letters", "then": [
          "$", "%", "&"
        ] }
      ]
    ] }]
  ],
  "other_letters": [
    "D", [
      "E", "F"
    ]
  ]
}

This feature is also useful for doing finite recursions.

This example would print out all of the more than 16 million hex color combinations:

{
  "main": [
    { "branch": "hex_digits",
      "then": { "branch": "hex_digits",
        "then": { "branch": "hex_digits",
          "then": { "branch": "hex_digits",
            "then": { "branch": "hex_digits",
              "then": { "branch": "hex_digits" }
            }
          }
        }
      }
    }
  ],
  "hex_digits": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
}