-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage.mojo
More file actions
36 lines (25 loc) · 819 Bytes
/
example_usage.mojo
File metadata and controls
36 lines (25 loc) · 819 Bytes
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
from simpletools.simplelist import SimpleList as slist
@value
@register_passable
struct MyStruct:
var name: StringRef
var x: Int
var y: Int
fn slist_example() raises:
# Create a list and add some elements
var storage = slist[MyStruct]()
storage.append(MyStruct("First Name", 0, 1))
storage.append(MyStruct("Second Name", 0, 1))
# Build a names SimpleList
fn get_name(value: MyStruct) -> StringRef:
return value.name
var names = storage.map[StringRef](get_name)
# Print the length of each name
fn print_len(value: StringRef):
print(value.__len__())
names.foreach(print_len)
# Get the second element and pring x and y
let second_element = storage[1]
print(second_element.x, second_element.y)
fn main() raises:
slist_example()