3.1 General-Purpose Libraries
3.1.1 Global Utilities
3.1.2 Numbers
3.1.3 Strings
3.1.4 Booleans
3.1.5 option
3.1.6 either
3.1.7 pick
3.1.8 lists
3.1.9 sets
3.1.10 arrays
3.1.11 string-dict
3.1.12 Tables
3.1.13 gdrive-sheets
3.1.14 csv
3.1.15 color
3.1.16 The image libraries
3.1.17 reactors
3.1.18 chart
3.1.19 plot
3.1.20 statistics
3.1.21 math
3.1.22 matrices
3.1.23 Timing
3.1.24 fetch
3.1.7 pick
On this page:
3.1.7.1 The Pick Datatype
Pick
pick-none
pick-some
is-pick-none
is-pick-some
3.1.7 pick🔗

Usage:
include pick
import pick as ...

3.1.7.1 The Pick Datatype🔗

data Pick<a, b>:
| pick-none
| pick-some(elt :: a, rest :: b)
end

pick-none :: Pick<a, b>

pick-some :: (elt :: a, rest :: b) -> Pick<a, b>

is-pick-none :: (val :: Any) -> Boolean

is-pick-some :: (val :: Any) -> Boolean

The primary use of pick is as a way of obtaining values from sets. See the documentation of .pick.

However, nothing precludes other datatypes from also implementing the Pick interface. For instance, here’s a simple queue definition that provides a pick method:

import pick as P data Queue<T>: | queue(elts :: List<T>) with: method pick(self): cases (List) self.elts: | empty => P.pick-none | link(f, r) => P.pick-some(f, queue(r)) end end end

We can then write a function that uses that method to traverse the queue:

fun sum-queue(q :: Queue) -> Number: cases (P.Pick) q.pick(): | pick-none => 0 | pick-some(e, r) => e + sum-queue(r) end end

with the expected behavior:

Examples:

check: q = queue([list: 1, 2, 3]) sum-queue(q) is 6 end