def swap_head

bendlib-kernel-list@1.0.0.0 · list.bend:5

import bendlib-kernel-list@1.0.0.0/list.bend as List
import Base

5# Swap the first two elements (no-op on lists shorter than two).
6def swap_head(-A: Data, xs: List<&2, A>) -> List<&2, A>:
7  match xs:
8    case Nil{}:
9      Nil{}
10    case +x <> t:
11      match t:
12        case Nil{}:
13          x <> Nil{}
14        case +y <> u:
15          y <> x <> u

Uses (1)

Used by (3)