Skip to content

Instantly share code, notes, and snippets.

@line-o
Created January 14, 2019 12:28
Show Gist options
  • Save line-o/d60f286383dd74db48b40478f4cea5cd to your computer and use it in GitHub Desktop.
Save line-o/d60f286383dd74db48b40478f4cea5cd to your computer and use it in GitHub Desktop.
xquery version "3.1";
declare namespace io = "http://io";
(: IO version of get-char :)
declare function local:get-char() as map(*) {
local:create-io(function($realworld as element(io:realworld)) {
($realworld, 123)
})
};
(: IO version of put-char :)
declare function local:put-char($codepoint as xs:integer) as map(*) {
local:create-io(function($realworld as element(io:realworld)) {
($realworld, ())
})
};
declare function local:bind($apply-fn as function(*), $binder as function(item()*) as map(*)) {
local:create-io(function($realworld) {
let $io-res := $apply-fn($realworld)
return $binder(tail($io-res))?apply(head($io-res))
})
};
declare function local:create-io($apply-fn as function(element(io:realworld)) as item()+) as map(*) {
map {
'apply': $apply-fn,
'bind': local:bind($apply-fn, ?)
}
};
let $x := local:get-char()?bind(local:put-char#1)
return $x?apply(<io:realworld />)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment