Created
January 14, 2019 12:28
-
-
Save line-o/d60f286383dd74db48b40478f4cea5cd to your computer and use it in GitHub Desktop.
modified version of @adamretter's code in https://github.com/eXist-db/exist/issues/2385
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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