Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rd4com/mojo-magiclist

🪄 multi-type list using mojo builtin object, with type checking
https://github.com/rd4com/mojo-magiclist

dynamic list mojo typed

Last synced: 27 days ago
JSON representation

🪄 multi-type list using mojo builtin object, with type checking

Awesome Lists containing this project

README

        

> :heart: part of the effort for the community
> https://github.com/Lynet101/Mojo_community-lib

> this is not a library , it has not been tested.
#### Thanks to @Stole from the discord who helped to convert the object to a string
```python
var COL=magiclist() #var peoples=magiclist(["foo",1])
print("-------------")
COL.push("something")
var s:String = "ann"
COL[0] = OW.from_string(s) #runtime string to builtin.object
let fl:Float64 = 1.0
COL.push(fl)
COL.push(3)
COL.push(True)
for i in range(COL.len()):
if OW.is_int(COL[i]): # type check of untyped value
let r:Int=OW.to_int(COL[i]) # conversion to typed value
print(r)
if OW.is_string(COL[i]):
let r:String=OW.to_string(COL[i])
print(r)
if OW.is_float(COL[i]):
let r:Float64=OW.to_float64(COL[i])
print(r)
if OW.is_bool(COL[i]):
let r:Bool=OW.to_bool(COL[i])
print(r)
COL.delete_elements("ann",OW.is_string) #typed value based deletion
COL.delete(0)
print("-----")
print(COL.data()) #pave the way for json-like serialisation
```
- [x] typed value searched deletion in multi type array
- [x] change type
- [x] check type
- [x] convert object to native type
- [x] convert native type to object
- [x] index based deletion
- [x] initialize/export from/to builtin.object multitype array
# output
```
-------------
ann
1.0
3
True
-----
[3, True]
```