Skip to content

Commit

Permalink
Merge pull request #105 from sanctuary-js/davidchambers/es6
Browse files Browse the repository at this point in the history
use ES6 syntax
  • Loading branch information
davidchambers authored Dec 9, 2023
2 parents 79ab8f2 + 6cd05be commit 64db3eb
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"root": true,
"extends": ["./node_modules/sanctuary-style/eslint-es3.json"],
"extends": ["./node_modules/sanctuary-style/eslint-es6.json"],
"overrides": [
{
"files": ["adt/*.js", "env.js"],
Expand Down
55 changes: 22 additions & 33 deletions adt/Html.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(f) {
(f => {

'use strict';

Expand All @@ -12,88 +12,77 @@
self.sanctuaryTypeIdentifiers);
}

} (function($, show, type) {
}) (($, show, type) => {

'use strict';

var def = $.create ({checkTypes: true, env: []});
const def = $.create ({checkTypes: true, env: []});

// htmlTypeIdent :: String
var htmlTypeIdent = 'sanctuary-site/Html';
const htmlTypeIdent = 'sanctuary-site/Html';

var HtmlType = $.NullaryType
const HtmlType = $.NullaryType
('Html')
('https://github.com/sanctuary-js/sanctuary-site/blob/gh-pages/adt/Html.js')
([])
(function(x) { return type (x) === htmlTypeIdent; });
(x => type (x) === htmlTypeIdent);

// Html :: String -> Html
var Html =
const Html =
def ('Html')
({})
([$.String, HtmlType])
(function(s) {
var html = Object.create (Html$prototype);
html.value = s;
return html;
});
(value => Object.assign (Object.create (Html$prototype), {value}));

var Html$prototype = {
const Html$prototype = {
'@@type': htmlTypeIdent,
'fantasy-land/concat': function(other) {
return Html (this.value + other.value);
},
'@@show': function() {
return 'Html (' + show (this.value) + ')';
}
},
};

Html['fantasy-land/empty'] = function() { return Html (''); };
Html['fantasy-land/empty'] = () => Html ('');

// Html.unwrap :: Html -> String
Html.unwrap =
def ('Html.unwrap')
({})
([HtmlType, $.String])
(function(html) { return html.value; });
(html => html.value);

// Html.encode :: String -> Html
Html.encode =
def ('Html.encode')
({})
([$.String, HtmlType])
(function(text) {
return Html (text.replace (/&/g, '&')
.replace (/</g, '&lt;')
.replace (/"/g, '&quot;'));
});
(text => Html (text.replace (/&/g, '&amp;')
.replace (/</g, '&lt;')
.replace (/"/g, '&quot;')));

// Html.decode :: Html -> String
Html.decode =
def ('Html.decode')
({})
([HtmlType, $.String])
(function(html) {
return html.value
.replace (/&quot;/g, '"')
.replace (/&lt;/g, '<')
.replace (/&amp;/g, '&');
});
(html => html.value
.replace (/&quot;/g, '"')
.replace (/&lt;/g, '<')
.replace (/&amp;/g, '&'));

// Html.indent :: NonNegativeInteger -> Html -> Html
Html.indent =
def ('Html.indent')
({})
([$.NonNegativeInteger, HtmlType, HtmlType])
(function(indent) {
return function(html) {
return Html (html.value.replace (/^(?!$)/gm, ' '.repeat (indent)));
};
});
(indent => html =>
Html (html.value.replace (/^(?!$)/gm, ' '.repeat (indent))));

// Html.Type :: Type
Html.Type = HtmlType;

return Html;

}));
});
22 changes: 9 additions & 13 deletions adt/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
self.sanctuaryTypeIdentifiers);
}

} (function($, show, Z, type) {
} (($, show, Z, type) => {

'use strict';

var List = {prototype: _List.prototype};
const List = {prototype: _List.prototype};

List.prototype.constructor = List;

Expand All @@ -32,21 +32,17 @@
}

// Nil :: List a
var Nil = List.Nil = new _List ('Nil');
const Nil = List.Nil = new _List ('Nil');

// Cons :: (a, List a) -> List a
var Cons = List.Cons = function(head) {
return function(tail) {
return new _List ('Cons', head, tail);
};
};
const Cons = List.Cons = head => tail => new _List ('Cons', head, tail);

// listTypeIdent :: String
var listTypeIdent = List.prototype['@@type'] = 'sanctuary-site/List';
const listTypeIdent = List.prototype['@@type'] = 'sanctuary-site/List';

List['fantasy-land/empty'] = function() { return Nil; };
List['fantasy-land/empty'] = () => Nil;

List['fantasy-land/of'] = function(x) { return Cons (x) (Nil); };
List['fantasy-land/of'] = x => Cons (x) (Nil);

List['fantasy-land/zero'] = List['fantasy-land/empty'];

Expand Down Expand Up @@ -108,8 +104,8 @@
('List')
('https://github.com/sanctuary-js/sanctuary-site/blob/gh-pages/adt/List.js')
([])
(function(x) { return type (x) === listTypeIdent; })
(function(list) { return list; });
(x => type (x) === listTypeIdent)
(list => list);

return List;

Expand Down
12 changes: 6 additions & 6 deletions adt/Sum.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(f) {
(f => {

'use strict';

Expand All @@ -14,7 +14,7 @@
self.sanctuaryTypeIdentifiers);
}

} (function($, show, Z, type) {
}) (($, show, Z, type) => {

'use strict';

Expand All @@ -25,9 +25,9 @@
}

// sumTypeIdent :: String
var sumTypeIdent = Sum.prototype['@@type'] = 'sanctuary-site/Sum';
const sumTypeIdent = Sum.prototype['@@type'] = 'sanctuary-site/Sum';

Sum['fantasy-land/empty'] = function() { return Sum (0); };
Sum['fantasy-land/empty'] = () => Sum (0);

Sum.prototype['fantasy-land/equals'] = function(other) {
return Z.equals (this.value, other.value);
Expand All @@ -50,8 +50,8 @@
('Sum')
('https://github.com/sanctuary-js/sanctuary-site/blob/gh-pages/adt/Sum.js')
([])
(function(x) { return type (x) === sumTypeIdent; });
(x => type (x) === sumTypeIdent);

return Sum;

}));
});
Loading

0 comments on commit 64db3eb

Please sign in to comment.