Skip to content

Instantly share code, notes, and snippets.

@AlaShibanAtKlo
Last active May 10, 2024 17:33
Show Gist options
  • Save AlaShibanAtKlo/67525d0888cbf3a7be8d63a1baab99bf to your computer and use it in GitHub Desktop.
Save AlaShibanAtKlo/67525d0888cbf3a7be8d63a1baab99bf to your computer and use it in GitHub Desktop.
discuss: interoperability of ecosystems within a single runtime environment
// this is how wasm can really transform programming for all of us.
// seamless interoperability of ecosystems within a single runtime environment
// for example using Python's networkx library directly within TypeScript code:
import { networkx } from "python/nx"
import { convertToNative } from "wasm"
/* use modules from other languages natively in the host language and runtime */
const G = new networkx.Graph()
/* Objects from other languages propogate types to the host language */
console.log(typeof G) // GraphPythonReference
/* Use the modules from other languages as if they were native */
/* Native object types are converted transparently when possible */
G.add_nodes_from([[1,2], [2, 3]])
G.add_edges_from([[1,2], [1, 3], [2, 3]])
console.log(G.nodes()) // PythonList([1, 2, 3])
console.log(G.edges()) // PythonList([[1, 2], [1, 3], [2, 3]])
/* Helpers to convert between native and foreign data types */
console.log(convertToNative(G.nodes())) // [1, 2, 3]
// calculate minimum spanning tree
const mst = networkx.minimum_spanning_tree(G)
console.log(mst.edges()) // PythonList([[1, 2], [2, 3]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment