Skip to content

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

License

Notifications You must be signed in to change notification settings

rd4com/mojo-magiclist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

❤️ 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

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
  • typed value searched deletion in multi type array
  • change type
  • check type
  • convert object to native type
  • convert native type to object
  • index based deletion
  • initialize/export from/to builtin.object multitype array

output

-------------
ann
1.0
3
True
-----
[3, True]

About

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

Topics

Resources

License

Stars

Watchers

Forks