Skip to content

List

Background

Given a file named "pen.json" with:

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

Create an empty list

Given a file named "Foo.pen" with:

f = \() [number] {
  [number]
}

When I run pen build

Then the exit status should be 0.

Create a list with an element

Given a file named "Foo.pen" with:

f = \() [number] {
  [number 1]
}

When I run pen build

Then the exit status should be 0.

Create a list with two elements

Given a file named "Foo.pen" with:

f = \() [number] {
  [number 1, 2]
}

When I run pen build

Then the exit status should be 0.

Join lists

Given a file named "Foo.pen" with:

f = \(xs [number]) [number] {
  [number ...xs, ...xs]
}

When I run pen build

Then the exit status should be 0.

Create a list of a union type

Given a file named "Foo.pen" with:

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

When I run pen build

Then the exit status should be 0.

Coerce elements of a spread list

Given a file named "Foo.pen" with:

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

When I run pen build

Then the exit status should be 0.

Use if-list expression

Given a file named "Foo.pen" with:

f = \(xs [number]) [number] {
  if [y, ...ys] = xs {
    [number y(), ...ys]
  } else {
    [number]
  }
}

When I run pen build

Then the exit status should be 0.

Use list comprehension

Given a file named "Foo.pen" with:

f = \(xs [number]) [number] {
  [number x() + 42 for x in xs]
}

When I run pen build

Then the exit status should be 0.

Permutate lists

Given a file named "Foo.pen" with:

f = \(xs [number], ys [number]) [number] {
  [number x() + y() for x in xs for y in ys]
}

When I run pen build

Then the exit status should be 0.

Flatten a list

Given a file named "Foo.pen" with:

f = \(xs [[number]]) [number] {
  [number y() for y in x() for x in xs]
}

When I run pen build

Then the exit status should be 0.

Filter a list

Given a file named "Foo.pen" with:

f = \(xs [number]) [number] {
  [number x() for x in xs if x() < 42]
}

When I run pen build

Then the exit status should be 0.

Zip lists

Given a file named "Foo.pen" with:

f = \(xs [number], ys [number]) [number] {
  [number x() + y() for x, y in xs, ys]
}

When I run pen build

Then the exit status should be 0.

Get a size of a list

Given a file named "Foo.pen" with:

f = \(xs [none]) number {
  size(xs)
}

When I run pen build

Then the exit status should be 0.