Skip to content

Add IsLog type class #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions src/Effect/Console.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
"use strict";

exports.log = function (s) {
exports._log = function (s) {
return function () {
console.log(s);
return {};
};
};

exports.warn = function (s) {
exports._warn = function (s) {
return function () {
console.warn(s);
return {};
};
};

exports.error = function (s) {
exports._error = function (s) {
return function () {
console.error(s);
return {};
};
};

exports.info = function (s) {
exports._info = function (s) {
return function () {
console.info(s);
return {};
Expand Down
45 changes: 33 additions & 12 deletions src/Effect/Console.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,67 @@ import Effect (Effect)
import Data.Show (class Show, show)
import Data.Unit (Unit)

class IsLog a

instance isLogString :: IsLog String
instance isLogArray :: IsLog a => IsLog (Array a)

-- | Write a message to the console.
foreign import log
:: String
-> Effect Unit
log :: forall a. IsLog a => a -> Effect Unit
log = _log

-- | Write a value to the console, using its `Show` instance to produce a
-- | `String`.
logShow :: forall a. Show a => a -> Effect Unit
logShow a = log (show a)

-- | Write an warning to the console.
foreign import warn
:: String
foreign import _log
:: forall a
. a
-> Effect Unit

-- | Write an warning to the console.
warn :: forall a. IsLog a => a -> Effect Unit
warn = _warn

-- | Write an warning value to the console, using its `Show` instance to produce
-- | a `String`.
warnShow :: forall a. Show a => a -> Effect Unit
warnShow a = warn (show a)

-- | Write an error to the console.
foreign import error
:: String
foreign import _warn
:: forall a
. a
-> Effect Unit

-- | Write an error to the console.
error :: forall a. IsLog a => a -> Effect Unit
error = _error

-- | Write an error value to the console, using its `Show` instance to produce a
-- | `String`.
errorShow :: forall a. Show a => a -> Effect Unit
errorShow a = error (show a)

-- | Write an info message to the console.
foreign import info
:: String
foreign import _error
:: forall a
. a
-> Effect Unit

-- | Write an info message to the console.
info :: forall a. IsLog a => a -> Effect Unit
info = _info

-- | Write an info value to the console, using its `Show` instance to produce a
-- | `String`.
infoShow :: forall a. Show a => a -> Effect Unit
infoShow a = info (show a)

foreign import _info
:: forall a
. a
-> Effect Unit

-- | Start a named timer.
foreign import time :: String -> Effect Unit

Expand Down