1///|
2pub(open) trait 
trait Clone {
  clone(Self) -> Self
}
Clone
{
3
(Self) -> Self
clone
(

type parameter Self

Self
) ->

type parameter Self

Self
4} 5 6// scalar 7 8///| 9pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
Int
Int
with clone(self) = "%identity"
10 11///| 12pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
Int16
Int16
with clone(self) = "%identity"
13 14///| 15pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
Int64
Int64
with clone(self) = "%identity"
16 17///| 18pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
UInt
UInt
with clone(self) = "%identity"
19 20///| 21pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
UInt16
UInt16
with clone(self) = "%identity"
22 23///| 24pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
UInt64
UInt64
with clone(self) = "%identity"
25 26///| 27pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
Byte
Byte
with clone(self) = "%identity"
28 29///| 30pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
Float
Float
with clone(self) = "%identity"
31 32///| 33pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
Double
Double
with clone(self) = "%identity"
34 35///| 36pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
Bool
Bool
with clone(self) = "%identity"
37 38///| 39pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
Char
Char
with clone(self) = "%identity"
40 41///| 42pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
Unit
Unit
with clone(self) = "%identity"
43 44///| 45pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
String
String
with
(self : String) -> String
clone
(
String
self
) {
46 // Create new String 47
String
self
(self : String, other : String) -> String

Concatenates two strings, creating a new string that contains all characters from the first string followed by all characters from the second string.

Parameters:

  • self : The first string to concatenate.
  • other : The second string to concatenate.

Returns a new string containing the concatenation of both input strings.

Example:

test "String::op_add" {
  let hello = "Hello"
  let world = " World!"
  inspect(hello + world, content="Hello World!")
  inspect("" + "abc", content="abc") // concatenating with empty string
}
+
""
48} 49 50// compound 51 52///| 53pub impl[A :
trait Clone {
  clone(Self) -> Self
}
Clone
]
trait Clone {
  clone(Self) -> Self
}
Clone
for
struct Ref[A] {
  mut val: A
}
Ref
[

type parameter A

A
] with
(self : Ref[A]) -> Ref[A]
clone
(
Ref[A]
self
) {
54
struct Ref[A] {
  mut val: A
}
Ref
::
(x : A) -> Ref[A]

create a reference from value

new
(
Ref[A]
self
.
A
val
.
(A) -> A
clone
())
55} 56 57///| 58pub impl[A :
trait Clone {
  clone(Self) -> Self
}
Clone
]
trait Clone {
  clone(Self) -> Self
}
Clone
for

type parameter A

A
? with
(self : A?) -> A?
clone
(
A?
self
) {
59 match
A?
self
{
60
A?
None
=>
A?
None
61
(A) -> A?
Some
(
A
v
) =>
(A) -> A?
Some
(
A
v
.
(A) -> A
clone
())
62 } 63} 64 65///| 66pub impl[A :
trait Clone {
  clone(Self) -> Self
}
Clone
, B :
trait Clone {
  clone(Self) -> Self
}
Clone
]
trait Clone {
  clone(Self) -> Self
}
Clone
for
enum Result[A, B] {
  Err(B)
  Ok(A)
}
Result
[

type parameter A

A
,

type parameter B

B
] with
(self : Result[A, B]) -> Result[A, B]
clone
(
Result[A, B]
self
) {
67 match
Result[A, B]
self
{
68
(B) -> Result[A, B]
Err
(
B
v
) =>
(B) -> Result[A, B]
Err
(
B
v
.
(B) -> B
clone
())
69
(A) -> Result[A, B]
Ok
(
A
v
) =>
(A) -> Result[A, B]
Ok
(
A
v
.
(A) -> A
clone
())
70 } 71} 72 73///| 74pub impl[A :
trait Clone {
  clone(Self) -> Self
}
Clone
]
trait Clone {
  clone(Self) -> Self
}
Clone
for
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[

type parameter A

A
] with
(self : Array[A]) -> Array[A]
clone
(
Array[A]
self
) {
75
Array[A]
self
.
(self : Array[A], f : (A) -> A) -> Array[A]

Maps a function over the elements of the array.

Example

let v = [3, 4, 5]
let v2 = v.map(fn (x) {x + 1})
assert_eq(v2, [4, 5, 6])
map
(
trait Clone {
  clone(Self) -> Self
}
Clone
(_ : A) -> A
::clone
)
76} 77 78///| 79pub impl[A :
trait Clone {
  clone(Self) -> Self
}
Clone
]
trait Clone {
  clone(Self) -> Self
}
Clone
for
enum @list.T[A] {
  Empty
  More(A, tail~ : @list.T[A])
}
@list.T
[

type parameter A

A
] with
(self : @list.T[A]) -> @list.T[A]
clone
(
@list.T[A]
self
) {
80
@list.T[A]
self
.
(self : @list.T[A], f : (A) -> A) -> @list.T[A]

Maps the list.

Example

assert_eq(@list.of([1, 2, 3, 4, 5]).map(fn(x){ x * 2}), @list.of([2, 4, 6, 8, 10]))
map
(
trait Clone {
  clone(Self) -> Self
}
Clone
(_ : A) -> A
::clone
)
81} 82 83///| 84pub impl[A :
trait Clone {
  clone(Self) -> Self
}
Clone
]
trait Clone {
  clone(Self) -> Self
}
Clone
for
type FixedArray[A]
FixedArray
[

type parameter A

A
] with
(self : FixedArray[A]) -> FixedArray[A]
clone
(
FixedArray[A]
self
) {
85
FixedArray[A]
self
.
(self : FixedArray[A], f : (A) -> A) -> FixedArray[A]

Applies a function to each element of the array and returns a new array with the results.

Example

let arr = [1, 2, 3, 4, 5]
let doubled = arr.map(fn(x){ x * 2 })
assert_eq(doubled, [2, 4, 6, 8, 10])
map
(
trait Clone {
  clone(Self) -> Self
}
Clone
(_ : A) -> A
::clone
)
86} 87 88///| 89pub impl
trait Clone {
  clone(Self) -> Self
}
Clone
for
Bytes
Bytes
with
(self : Bytes) -> Bytes
clone
(
Bytes
self
) {
90
Bytes
self
.
(self : Bytes) -> Bytes

Creates a new byte sequence by copying all bytes from the input sequence.

Parameters:

  • bytes : The byte sequence to be copied.

Returns a new Bytes containing the same sequence of bytes as the input.

Example:

test "Bytes::copy" {
  let original = b"\x01\x02\x03"
  let copy = original.copy()
  inspect(copy, content="b\"\\x01\\x02\\x03\"")
}
copy
()
91} 92 93///| 94pub impl[K :
trait Clone {
  clone(Self) -> Self
}
Clone
+
trait Eq {
  op_equal(Self, Self) -> Bool
}

Trait for types whose elements can test for equality

Eq
+
trait Hash {
  hash_combine(Self, Hasher) -> Unit
  hash(Self) -> Int
}

Trait for types that can be hashed

Hash
, V :
trait Clone {
  clone(Self) -> Self
}
Clone
]
trait Clone {
  clone(Self) -> Self
}
Clone
for
type Map[K, V]

Mutable linked hash map that maintains the order of insertion, not thread safe.

Example

let map = { 3: "three", 8 :  "eight", 1 :  "one"}
assert_eq(map.get(2), None)
assert_eq(map.get(3), Some("three"))
map.set(3, "updated")
assert_eq(map.get(3), Some("updated"))
Map
[

type parameter K

K
,

type parameter V

V
] with
(self : Map[K, V]) -> Map[K, V]
clone
(
Map[K, V]
self
) {
95 let
Map[K, V]
res
=
type Map[K, V]

Mutable linked hash map that maintains the order of insertion, not thread safe.

Example

let map = { 3: "three", 8 :  "eight", 1 :  "one"}
assert_eq(map.get(2), None)
assert_eq(map.get(3), Some("three"))
map.set(3, "updated")
assert_eq(map.get(3), Some("updated"))
Map
::
(capacity~ : Int) -> Map[K, V]

Create a hash map. The capacity of the map will be the smallest power of 2 that is greater than or equal to the provided [capacity].

new
(
Int
capacity
=
Map[K, V]
self
.
(self : Map[K, V]) -> Int

Get the number of key-value pairs in the map.

size
())
96 for
K
k
,
V
v
in
Map[K, V]
self
{
97
Map[K, V]
res
(Map[K, V], K, V) -> Unit
[
k.
(K) -> K
clone
()] =
V
v
.
(V) -> V
clone
()
98 } 99
Map[K, V]
res
100} 101 102///| 103pub impl[V :
trait Clone {
  clone(Self) -> Self
}
Clone
+
trait Eq {
  op_equal(Self, Self) -> Bool
}

Trait for types whose elements can test for equality

Eq
+
trait Hash {
  hash_combine(Self, Hasher) -> Unit
  hash(Self) -> Int
}

Trait for types that can be hashed

Hash
]
trait Clone {
  clone(Self) -> Self
}
Clone
for
type @set.Set[K]

Mutable linked hash set that maintains the order of insertion, not thread safe.

Set
[

type parameter V

V
] with
(self : @set.Set[V]) -> @set.Set[V]
clone
(
@set.Set[V]
self
) {
104 let
@set.Set[V]
res
=
type @set.Set[K]

Mutable linked hash set that maintains the order of insertion, not thread safe.

Set
::
(capacity~ : Int) -> @set.Set[V]

Create a hash set. The capacity of the set will be the smallest power of 2 that is greater than or equal to the provided [capacity].

new
(
Int
capacity
=
@set.Set[V]
self
.
(self : @set.Set[V]) -> Int

Get the number of keys in the set.

size
())
105 for
V
v
in
@set.Set[V]
self
{
106
@set.Set[V]
res
.
(self : @set.Set[V], key : V) -> Unit

Insert a key into the hash set.

add
(
V
v
.
(V) -> V
clone
())
107 } 108
@set.Set[V]
res
109} 110 111///| 112pub impl[A :
trait Clone {
  clone(Self) -> Self
}
Clone
]
trait Clone {
  clone(Self) -> Self
}
Clone
for
type @deque.T[A]
@deque.T
[

type parameter A

A
] with
(self : @deque.T[A]) -> @deque.T[A]
clone
(
@deque.T[A]
self
) {
113
@deque.T[A]
self
.
(self : @deque.T[A], f : (A) -> A) -> @deque.T[A]

Maps a function over the elements of the deque.

Example

let dv = @deque.of([3, 4, 5])
let dv2 = dv.map(fn (x) {x + 1})
assert_eq(dv2, @deque.of([4, 5, 6]))
map
(
trait Clone {
  clone(Self) -> Self
}
Clone
(_ : A) -> A
::clone
)
114} 115 116///| 117pub impl[K :
trait Clone {
  clone(Self) -> Self
}
Clone
+
trait Eq {
  op_equal(Self, Self) -> Bool
}

Trait for types whose elements can test for equality

Eq
+
trait Hash {
  hash_combine(Self, Hasher) -> Unit
  hash(Self) -> Int
}

Trait for types that can be hashed

Hash
, V :
trait Clone {
  clone(Self) -> Self
}
Clone
]
trait Clone {
  clone(Self) -> Self
}
Clone
for
type @hashmap.T[K, V]

Mutable hash map, not thread safe.

Example

let map = @hashmap.of([(3, "three"), (8, "eight"), (1, "one")])
assert_eq(map.get(2), None)
assert_eq(map.get(3), Some("three"))
map.set(3, "updated")
assert_eq(map.get(3), Some("updated"))
@hashmap.T
[

type parameter K

K
,

type parameter V

V
] with
(self : @hashmap.T[K, V]) -> @hashmap.T[K, V]
clone
(
118
@hashmap.T[K, V]
self
119) { 120 let
@hashmap.T[K, V]
res
=
(capacity~ : Int) -> @hashmap.T[K, V]

Creates a new empty hash map with the specified initial capacity. The actual capacity will be rounded up to the next power of 2 that is greater than or equal to the requested capacity, with a minimum of 8.

Parameters:

  • capacity : The desired minimum capacity of the hash map. Must be a non-negative integer. Defaults to 8 if not specified.

Returns a new empty hash map of type T[K, V], where K is the key type and V is the value type.

Example:

test "new" {
  let map : @hashmap.T[String, Int] = @hashmap.new(capacity=16)
  inspect(map.capacity(), content="16")
  inspect(map.is_empty(), content="true")
}
@hashmap.new
(
Int
capacity
=
@hashmap.T[K, V]
self
.
(self : @hashmap.T[K, V]) -> Int

Returns the number of key-value pairs currently stored in the hash map.

Parameters:

  • self : The hash map to get the size from.

Returns the number of key-value pairs in the hash map.

Example:

test "size" {
  let map = @hashmap.of([("a", 1), ("b", 2), ("c", 3)])
  inspect(map.size(), content="3")
}
size
())
121 for
K
k
,
V
v
in
@hashmap.T[K, V]
self
{
122
@hashmap.T[K, V]
res
(@hashmap.T[K, V], K, V) -> Unit

Sets the value associated with a key in the hash map. If the key already exists, updates its value; otherwise, adds a new key-value pair. This function is automatically called when using the index assignment syntax map[key] = value.

Parameters:

  • map : The hash map to modify.
  • key : The key to associate with the value. Must implement Hash and Eq traits.
  • value : The value to associate with the key.

Example:

test "op_set" {
  let map : @hashmap.T[String, Int] = @hashmap.new()
  map["key"] = 42
  inspect(map.get("key"), content="Some(42)")
}
[
k.
(K) -> K
clone
()] =
V
v
.
(V) -> V
clone
()
123 } 124
@hashmap.T[K, V]
res
125} 126 127///| 128pub impl[V :
trait Clone {
  clone(Self) -> Self
}
Clone
+
trait Eq {
  op_equal(Self, Self) -> Bool
}

Trait for types whose elements can test for equality

Eq
+
trait Hash {
  hash_combine(Self, Hasher) -> Unit
  hash(Self) -> Int
}

Trait for types that can be hashed

Hash
]
trait Clone {
  clone(Self) -> Self
}
Clone
for
type @hashset.T[K]

Mutable hash set, not thread safe.

Example

let set = @hashset.of([(3, "three"), (8, "eight"), (1, "one")])
set.add((4, "four"))
assert_eq(set.contains((4, "four")), true)
@hashset.T
[

type parameter V

V
] with
(self : @hashset.T[V]) -> @hashset.T[V]
clone
(
@hashset.T[V]
self
) {
129 let
@hashset.T[V]
res
=
(capacity~ : Int) -> @hashset.T[V]

Create new hash set.

@hashset.new
(
Int
capacity
=
@hashset.T[V]
self
.
(self : @hashset.T[V]) -> Int

Get the number of keys in the set.

size
())
130 for
V
v
in
@hashset.T[V]
self
{
131
@hashset.T[V]
res
.
(self : @hashset.T[V], key : V) -> Unit

Insert a key into hash set.

add
(
V
v
.
(V) -> V
clone
())
132 } 133
@hashset.T[V]
res
134} 135 136///| 137pub impl[K :
trait Clone {
  clone(Self) -> Self
}
Clone
+
trait Eq {
  op_equal(Self, Self) -> Bool
}

Trait for types whose elements can test for equality

Eq
+
trait Compare {
  compare(Self, Self) -> Int
}

Trait for types whose elements are ordered

The return value of [compare] is:

  • zero, if the two arguments are equal
  • negative, if the first argument is smaller
  • positive, if the first argument is greater
Compare
, V :
trait Clone {
  clone(Self) -> Self
}
Clone
]
trait Clone {
  clone(Self) -> Self
}
Clone
for
type @sorted_map.T[K, V]
@sorted_map.T
[

type parameter K

K
,

type parameter V

V
] with
(self : @sorted_map.T[K, V]) -> @sorted_map.T[K, V]
clone
(
138
@sorted_map.T[K, V]
self
139) { 140 let
@sorted_map.T[K, V]
res
=
() -> @sorted_map.T[K, V]

Returns a new sorted map.

@sorted_map.new
()
141 for
K
k
,
V
v
in
@sorted_map.T[K, V]
self
{
142
@sorted_map.T[K, V]
res
(@sorted_map.T[K, V], K, V) -> Unit
[
k.
(K) -> K
clone
()] =
V
v
.
(V) -> V
clone
()
143 } 144
@sorted_map.T[K, V]
res
145} 146 147///| 148pub impl[V :
trait Clone {
  clone(Self) -> Self
}
Clone
+
trait Eq {
  op_equal(Self, Self) -> Bool
}

Trait for types whose elements can test for equality

Eq
+
trait Compare {
  compare(Self, Self) -> Int
}

Trait for types whose elements are ordered

The return value of [compare] is:

  • zero, if the two arguments are equal
  • negative, if the first argument is smaller
  • positive, if the first argument is greater
Compare
]
trait Clone {
  clone(Self) -> Self
}
Clone
for
type @sorted_set.T[V]
@sorted_set.T
[

type parameter V

V
] with
(self : @sorted_set.T[V]) -> @sorted_set.T[V]
clone
(
@sorted_set.T[V]
self
) {
149 let
@sorted_set.T[V]
res
=
() -> @sorted_set.T[V]

Construct a empty set.

@sorted_set.new
()
150 for
V
v
in
@sorted_set.T[V]
self
{
151
@sorted_set.T[V]
res
.
(self : @sorted_set.T[V], value : V) -> Unit
add
(
V
v
.
(V) -> V
clone
())
152 } 153
@sorted_set.T[V]
res
154} 155 156///| 157pub impl[A :
trait Clone {
  clone(Self) -> Self
}
Clone
+
trait Compare {
  compare(Self, Self) -> Int
}

Trait for types whose elements are ordered

The return value of [compare] is:

  • zero, if the two arguments are equal
  • negative, if the first argument is smaller
  • positive, if the first argument is greater
Compare
]
trait Clone {
  clone(Self) -> Self
}
Clone
for
type @priority_queue.T[A]
@priority_queue.T
[

type parameter A

A
] with
(self : @priority_queue.T[A]) -> @priority_queue.T[A]
clone
(
@priority_queue.T[A]
self
) {
158 let
@priority_queue.T[A]
res
=
() -> @priority_queue.T[A]

Creates a new empty priority queue.

Example

let queue : @priority_queue.T[Int] = @priority_queue.new()
assert_eq(queue.length(), 0)
@priority_queue.new
()
159 for
A
x
in
@priority_queue.T[A]
self
{
160
@priority_queue.T[A]
res
.
(self : @priority_queue.T[A], value : A) -> Unit

Adds a value to the priority queue.

Example

let queue = @priority_queue.new()
queue.push(1)
assert_eq(queue.length(), 1)
push
(
A
x
.
(A) -> A
clone
())
161 } 162
@priority_queue.T[A]
res
163} 164