Skip to content

Union

Given a file named “pen.json” with:

{
"type": "library",
"dependencies": {}
}

Given a file named “Foo.pen” with:

f = \() number | none {
42
}

When I run pen build

Then the exit status should be 0.

Given a file named “Foo.pen” with:

f = \() (\() number) | none {
\() number {
42
}
}

When I run pen build

Then the exit status should be 0.

Given a file named “Foo.pen” with:

f = \() [number] | none {
[number 42]
}

When I run pen build

Then the exit status should be 0.

Given a file named “Foo.pen” with:

f = \(x number | none) number {
if x = x as number {
x
} else if none {
0
}
}

When I run pen build

Then the exit status should be 0.

Given a file named “Foo.pen” with:

f = \(x number | none) number {
if x = x as none {
0
} else {
x
}
}

When I run pen build

Then the exit status should be 0.

Downcast a union type to another union type

Section titled “Downcast a union type to another union type”

Given a file named “Foo.pen” with:

f = \(x number | boolean | none) number | none {
if x = x as number | none {
x
} else {
none
}
}

When I run pen build

Then the exit status should be 0.