Oak & Replit: Typechecking and Interfaces

Hey all!
Recently created an Oak module for checking interfaces/types using Atoms!

It goes through all children, recursively if needed.
Useful for translating/creating TS-like Oak-ware while still maintaining typing and using interface-like objects.

std := import('std')

a := { ... }
b := with std.clone() a

typeCheck?( a, b )
// a == b = true

Here is the Source Code of expressive.oak

std := import('std')

fn transformInput(inputItem) {

  fn iterateAndTransform(item) {
    iterator := std._baseIterator(item) 
    if type(item) {
      :list -> {
        itemLength := item |> len()
        itemKeys := keys(item)

        iterator << with std.each(item) fn(arrayItem, index) if arrayItem {
          _ -> iterateAndTransform(arrayItem)
        }

        iterator.(itemKeys.(itemLength-1))
      }
  
      :object -> {
        itemLength := item |> len()
        itemKeys := keys(item)

        with std.each(item) fn(objectItem, index) {
          iterator.(itemKeys.(index)) <- item.(itemKeys.(itemLength-1)) |> iterateAndTransform()
        }
        
        iterator.(itemKeys.(itemLength-1))
      }
  
      :atom -> {
        iterator <- item
      }
  
      _ -> {
        iterator <- type(item)
      }
    }
    iterator
  }

  inputItem |> iterateAndTransform()
}

fn typeCheck?(pattern, instance) {
  instance |> transformInput() = pattern |> transformInput() 
}
1 Like

Made a template for this for using Types and learning Oak!

Happy Oaking! :deciduous_tree: