Stream: cull-os

Topic: Junctions


view this post on Zulip RGBCube (Nov 16 2024 at 17:29):

\xs = [1, 2, 3];

# 1 | 2 | 3
\anyXs = foldLeft (|) (head xs) (tail xs);

# 1 & 2 & 3
\allXs = foldLeft (&) (head xs) (tail xs);

# Applies it to each element.
#   false | true | false
# becomes true.
\anyEven = allXs % 2 == 1;

# Same for anyEven.

Where this is actually useful it type checking:

\juncType = string | number;

# `string` is just an attribute set.
# So is `numbee`, and `check` is a child of both.
# So we lazily apply each one and when we reach the first true, we collapse our junction.
\isAnyOfTheseTypes = juncType.check 123;

view this post on Zulip RGBCube (Nov 16 2024 at 17:29):

This exists in Raku and I think it's really cool.


Last updated: Dec 05 2024 at 04:21 UTC