From 2736d8d97d883603eac701a614ee02b63611f782 Mon Sep 17 00:00:00 2001 From: Phil Freeman Date: Thu, 26 May 2016 21:31:42 -0700 Subject: [PATCH 1/2] Updates for 1.0 core libraries --- bower.json | 12 ++++++------ docs/Data/Nullable.md | 40 ---------------------------------------- src/Data/Nullable.js | 4 +--- src/Data/Nullable.purs | 13 +++++++------ 4 files changed, 14 insertions(+), 55 deletions(-) delete mode 100644 docs/Data/Nullable.md diff --git a/bower.json b/bower.json index 6d8bd7e..80372b6 100644 --- a/bower.json +++ b/bower.json @@ -14,11 +14,11 @@ "tests" ], "dependencies": { - "purescript-maybe": "^0.3.0", - "purescript-functions": "^0.1.0" + "purescript-maybe": "^1.0.0-rc.1", + "purescript-functions": "^1.0.0-rc.1" }, - "repository": { - "type": "git", - "url": "git://github.com/paf31/purescript-nullable.git" - } + "repository": { + "type": "git", + "url": "git://github.com/paf31/purescript-nullable.git" + } } diff --git a/docs/Data/Nullable.md b/docs/Data/Nullable.md deleted file mode 100644 index 4372b40..0000000 --- a/docs/Data/Nullable.md +++ /dev/null @@ -1,40 +0,0 @@ -## Module Data.Nullable - -This module defines types and functions for working with nullable types -using the FFI. - -#### `Nullable` - -``` purescript -data Nullable :: * -> * -``` - -A nullable type. - -This type constructor may be useful when interoperating with JavaScript functions -which accept or return null values. - -##### Instances -``` purescript -instance showNullable :: (Show a) => Show (Nullable a) -instance eqNullable :: (Eq a) => Eq (Nullable a) -instance ordNullable :: (Ord a) => Ord (Nullable a) -``` - -#### `toNullable` - -``` purescript -toNullable :: forall a. Maybe a -> Nullable a -``` - -Takes `Nothing` to `null`, and `Just a` to `a`. - -#### `toMaybe` - -``` purescript -toMaybe :: forall a. Nullable a -> Maybe a -``` - -Represent `null` using `Maybe a` as `Nothing`. - - diff --git a/src/Data/Nullable.js b/src/Data/Nullable.js index 1be08b9..ab5dadd 100644 --- a/src/Data/Nullable.js +++ b/src/Data/Nullable.js @@ -1,8 +1,6 @@ /* global exports */ "use strict"; -// module Data.Nullable - exports["null"] = null; exports.nullable = function(a, r, f) { @@ -11,4 +9,4 @@ exports.nullable = function(a, r, f) { exports.notNull = function(x) { return x; -}; +}; diff --git a/src/Data/Nullable.purs b/src/Data/Nullable.purs index a9e660c..55ffd64 100644 --- a/src/Data/Nullable.purs +++ b/src/Data/Nullable.purs @@ -7,10 +7,11 @@ module Data.Nullable , toNullable ) where -import Prelude +import Prelude (class Ord, class Eq, class Show, compare, eq, show) -import Data.Maybe -import Data.Function +import Data.Function (on) +import Data.Function.Uncurried (Fn3, runFn3) +import Data.Maybe (Maybe(..), maybe) -- | A nullable type. -- | @@ -20,17 +21,17 @@ foreign import data Nullable :: * -> * -- | The null value. foreign import null :: forall a. Nullable a - + foreign import nullable :: forall a r. Fn3 (Nullable a) r (a -> r) r -- | Wrap a non-null value. foreign import notNull :: forall a. a -> Nullable a - + -- | Takes `Nothing` to `null`, and `Just a` to `a`. toNullable :: forall a. Maybe a -> Nullable a toNullable = maybe null notNull --- | Represent `null` using `Maybe a` as `Nothing`. +-- | Represent `null` using `Maybe a` as `Nothing`. toMaybe :: forall a. Nullable a -> Maybe a toMaybe n = runFn3 nullable n Nothing Just From acd62714de10ed9dd97aef62f2eef457e1c2bb06 Mon Sep 17 00:00:00 2001 From: Phil Freeman Date: Thu, 26 May 2016 21:34:33 -0700 Subject: [PATCH 2/2] Fix tests --- test/Main.purs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/Main.purs b/test/Main.purs index 32c9765..f6579db 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -2,17 +2,17 @@ module Test.Main where import Prelude -import Data.Maybe -import Data.Nullable +import Data.Maybe (Maybe(..)) +import Data.Nullable (toNullable, toMaybe) -import Control.Monad.Eff.Console +import Control.Monad.Eff.Console (logShow) main = do - print $ toNullable (Nothing :: Maybe Number) - print $ toNullable (Just 42) + logShow $ toNullable (Nothing :: Maybe Number) + logShow $ toNullable (Just 42) - print $ toMaybe $ toNullable (Nothing :: Maybe Number) - print $ toMaybe $ toNullable (Just 42) + logShow $ toMaybe $ toNullable (Nothing :: Maybe Number) + logShow $ toMaybe $ toNullable (Just 42) - print $ toNullable Nothing == toNullable (Just 42) - print $ toNullable Nothing `compare` toNullable (Just 42) + logShow $ toNullable Nothing == toNullable (Just 42) + logShow $ toNullable Nothing `compare` toNullable (Just 42)