grain streams inspired by javascript callbags
🌾 A standard for callbacks that enables lightweight observables and iterables
Photo by Clem Onojeghuo on Unsplash
WIP still being built!
import * from "./hessian"
import * from "./types"
import { (|>) } from "./pipe"
let producer = fromList([1, 2, 3]) |> map(v => v + 10)
let operators = producer |> map(v => v + 10) |> map(v => v + 10)
operators |> forEach(print)
31
32
33
// serialise.gr
...
record Human {
mut message: String,
}
let value = { message: "Hi from Bob", }
print(Bytes.toString(marshal(value)))
// deserialise.gr
...
let stdinOptions = {
file: Fd(File.stdin),
rwFlags: [],
size: 1024,
}: Sources.ReadFileOptions
let deserialise = message => {
let parsed = Result.map((bob: Human) => bob.message, unmarshal(message))
Result.toOption(parsed)
}
readFile(stdinOptions) |>
map(Bytes.fromString) |>
map(deserialise) |>
forEach(print)
grain serialise | grain deserialise
Some("Hi from Bob")