% map_fields - Apply function to all member fields of structure
%
% map_fields :: 
%    (A->B)              ~'function from As to Bs',
%    struct(fields(N,A)) 
% -> struct(fields(N,B)).
%
% fields(N,A) denotes a list of struct field type declarates with
% names from list N and types all equal to A, eg
%    fields({'a','b','c'},real) == {a::real, b::real, c::real}.

function y=map_fields(fn,x)
	y=foldl(@(s,f)setfield(s,f,fn(s.(f))),x,fields(x));
