aboutsummaryrefslogtreecommitdiffhomepage
path: root/std/Pair.bruijn
blob: 46302cc148098b79548c7b2feeb11f8861cab45f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# MIT License, Copyright (c) 2022 Marvin Borner

:import std/Combinator .

# pairs two expressions into one
pair [[[0 2 1]]]

(:) pair

# extracts first expression from pair
fst [0 K]

# test fst with example pair of [[0]] and [[1]]
:test (fst ([[0]] : [[1]])) ([[0]])

# extracts second expression from pair
snd [0 KI]

# test snd with example pair of [[0]] and [[1]]
:test (snd ([[0]] : [[1]])) ([[1]])

# applies both elements of a pair to a function
uncurry [[1 (fst 0) (snd 0)]]

# test uncurry with example pair of [[0]] and [[1]] and some combinator
:test (uncurry W ([[0]] : [[1]])) ([[1]])

# applies a function to the pair of two values
curry [[[2 (1 : 0)]]]

# test curry with example pair of [[0]] and [[1]] and fst
:test (curry fst [[0]] [[1]]) ([[0]])

# swaps the values of a pair
swap [(snd 0) : (fst 0)]

# test swap with example pair of [[0]] and [[1]]
:test (swap ([[0]] : [[1]])) ([[1]] : [[0]])