From ccb50d835ec5ae2e5233c92838755564c7a19e59 Mon Sep 17 00:00:00 2001 From: David Koontz Date: Tue, 24 Jan 2017 17:06:28 -0700 Subject: [PATCH] Implement `Iso` mapping for Nullable to Maybe --- bower.json | 3 ++- src/Data/Nullable.purs | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bower.json b/bower.json index e81ee7f..e802f09 100644 --- a/bower.json +++ b/bower.json @@ -15,7 +15,8 @@ ], "dependencies": { "purescript-maybe": "^2.0.0", - "purescript-functions": "^2.0.0" + "purescript-functions": "^2.0.0", + "purescript-isomorphisms": "^3.0.0" }, "repository": { "type": "git", diff --git a/src/Data/Nullable.purs b/src/Data/Nullable.purs index a082a13..d9578df 100644 --- a/src/Data/Nullable.purs +++ b/src/Data/Nullable.purs @@ -3,6 +3,7 @@ module Data.Nullable ( Nullable + , isoNullableMaybe , toMaybe , toNullable ) where @@ -11,6 +12,7 @@ import Prelude import Data.Function (on) import Data.Function.Uncurried (Fn3, runFn3) +import Data.Iso (Iso(Iso)) import Data.Maybe (Maybe(..), maybe) -- | A nullable type. @@ -35,6 +37,9 @@ toNullable = maybe null notNull toMaybe :: forall a. Nullable a -> Maybe a toMaybe n = runFn3 nullable n Nothing Just +isoNullableMaybe :: forall a. Iso (Nullable a) (Maybe a) +isoNullableMaybe = Iso toMaybe toNullable + instance showNullable :: Show a => Show (Nullable a) where show = maybe "null" show <<< toMaybe