I've working on this code that does some lazy initialization of data reachable from my object. (I'm using a parking_lot::Once for this, fwiw.) It returns a reference that won't move...or it returns error. So I have this now:
I'd love for ARefs::map (or something like it with a different name to maintain backward compatibility) to accept a function that can return error.
I could call my lazy initialization once before putting it into ARefs using ?, and then call it a second time through map with the unwrap. It'd be functionally similar but seems verbose and lame.
I spent some time thinking about whether this could be generalized (to return other things than Results) but I think that kind of generalization requires HKT, so I implemented is as you wished. Enjoy!
I've working on this code that does some lazy initialization of data reachable from my object. (I'm using a
parking_lot::Once
for this, fwiw.) It returns a reference that won't move...or it returns error. So I have this now:I'd love for
ARefs::map
(or something like it with a different name to maintain backward compatibility) to accept a function that can return error.I could call my lazy initialization once before putting it into
ARefs
using?
, and then call it a second time throughmap
with the unwrap. It'd be functionally similar but seems verbose and lame.The function is currently:
I'd like something like this: