Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
40 changes: 0 additions & 40 deletions docs/Data/Nullable.md

This file was deleted.

4 changes: 1 addition & 3 deletions src/Data/Nullable.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* global exports */
"use strict";

// module Data.Nullable

exports["null"] = null;

exports.nullable = function(a, r, f) {
Expand All @@ -11,4 +9,4 @@ exports.nullable = function(a, r, f) {

exports.notNull = function(x) {
return x;
};
};
13 changes: 7 additions & 6 deletions src/Data/Nullable.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
-- |
Expand All @@ -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

Expand Down
18 changes: 9 additions & 9 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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)