Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/rd4com/mojo-magiclist
- Owner: rd4com
- License: mit
- Created: 2023-09-11T03:35:19.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-28T07:07:30.000Z (about 1 year ago)
- Last Synced: 2024-02-11T18:47:00.050Z (10 months ago)
- Topics: dynamic, list, mojo, typed
- Homepage:
- Size: 12.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-mojo - mojo-magiclist - Multi-type list using mojo builtin object, with type checking. (🗂️ Libraries / Data Structures)
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]
```