From 94130c3ff512b457f349a29633d0fafc3a6e93b6 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 23 Oct 2019 21:35:18 +0200 Subject: Add singletonShared convenience function --- src/Gtk/Shares.icl | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/Gtk/Shares.icl') diff --git a/src/Gtk/Shares.icl b/src/Gtk/Shares.icl index 13a8727..4ff107f 100644 --- a/src/Gtk/Shares.icl +++ b/src/Gtk/Shares.icl @@ -34,3 +34,14 @@ setShared (id,_) v = updateShared :: !(a -> a) !(Shared a) -> GtkM a | shared a updateShared f shared = getShared shared >>= setShared shared o f + +singletonShared :: !String !(GtkM a) -> GtkM a | shared a +singletonShared name setup = + let shr = share name Nothing in + getShared shr >>= \val -> case val of + Just val -> + pure val + Nothing -> + setup >>= \val -> + setShared shr (Just val) >>| + pure val -- cgit v1.2.3