Skip to content

Commit

Permalink
Make parentheses optional for case, for and if expressions. (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdotdesign authored May 1, 2023
1 parent 9f19e36 commit a5e46ec
Show file tree
Hide file tree
Showing 65 changed files with 224 additions and 274 deletions.
22 changes: 11 additions & 11 deletions core/source/Array.mint
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Array {
Array.any([1, 3], (number : Number) : Bool { number % 2 == 0 }) == false
*/
fun any (array : Array(item), function : Function(item, Bool)) : Bool {
case (Array.find(array, function)) {
case Array.find(array, function) {
Maybe::Nothing => false
Maybe::Just => true
}
Expand Down Expand Up @@ -44,7 +44,7 @@ module Array {
array,
[],
(memo : Array(item), item : Maybe(item)) : Array(item) {
case (item) {
case item {
Maybe::Just(value) => Array.push(memo, value)
Maybe::Nothing => memo
}
Expand Down Expand Up @@ -135,7 +135,7 @@ module Array {
*/
fun find (array : Array(item), function : Function(item, Bool)) : Maybe(item) {
Array.first(
for (item of array) {
for item of array {
item
} when {
function(item)
Expand Down Expand Up @@ -289,7 +289,7 @@ module Array {
Array.indexOf(["a","b","c"], "a") == 0
*/
fun indexOf (array : Array(item), search : item) : Maybe(Number) {
for (item, index of array) {
for item, index of array {
index
} when {
item == search
Expand Down Expand Up @@ -374,7 +374,7 @@ module Array {
Array.map([1, 2, 3], (number : Number) : Number { number + 1 }) == [2, 3, 4]
*/
fun map (array : Array(item), method : Function(item, result)) : Array(result) {
for (item of array) {
for item of array {
method(item)
}
}
Expand All @@ -392,7 +392,7 @@ module Array {
array : Array(item),
method : Function(item, Number, result)
) : Array(result) {
for (item, index of array) {
for item, index of array {
method(item, index)
}
}
Expand All @@ -405,7 +405,7 @@ module Array {
Array.max([]) == Maybe::Nothing
*/
fun max (array : Array(Number)) : Maybe(Number) {
if (Array.size(array) > 0) {
if Array.size(array) > 0 {
Maybe::Just(`Math.max(...#{array})`)
} else {
Maybe::Nothing
Expand All @@ -420,7 +420,7 @@ module Array {
Array.min([]) == Maybe::Nothing
*/
fun min (array : Array(Number)) : Maybe(Number) {
if (Array.size(array) > 0) {
if Array.size(array) > 0 {
Maybe::Just(`Math.min(...#{array})`)
} else {
Maybe::Nothing
Expand Down Expand Up @@ -552,7 +552,7 @@ module Array {
Array.reverseIf([1, 2, 3], true) == [3, 2, 1]
*/
fun reverseIf (array : Array(item), condition : Bool) : Array(item) {
if (condition) {
if condition {
Array.reverse(array)
} else {
array
Expand Down Expand Up @@ -745,7 +745,7 @@ module Array {
Array.uniq(["a", "a", "b", "b", "c"] == ["a", "b", "c"]
*/
fun uniq (array : Array(item)) : Array(item) {
for (item, index of array) {
for item, index of array {
item
} when {
indexOf(array, item) == Maybe::Just(index)
Expand Down Expand Up @@ -781,7 +781,7 @@ module Array {
index : Number,
method : Function(item, item)
) : Array(item) {
case (array[index]) {
case array[index] {
Maybe::Just(item) => setAt(array, index, method(item))
Maybe::Nothing => array
}
Expand Down
2 changes: 1 addition & 1 deletion core/source/Dom.mint
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module Dom {
|> Dom.getElementById()
*/
fun focus (maybeElement : Maybe(Dom.Element)) : Promise(Void) {
case (maybeElement) {
case maybeElement {
Maybe::Just(element) =>
{
focusWhenVisible(element)
Expand Down
2 changes: 1 addition & 1 deletion core/source/Http.mint
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ module Http {
|> Http.send()
*/
fun jsonBody (request : Http.Request, body : Object) : Http.Request {
if (hasHeader(request, "Content-Type")) {
if hasHeader(request, "Content-Type") {
{ request | body: `JSON.stringify(#{body})` }
} else {
{ request | body: `JSON.stringify(#{body})` }
Expand Down
2 changes: 1 addition & 1 deletion core/source/If.mint
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ component If {
property condition : Bool = true

fun render : Array(Html) {
if (condition) {
if condition {
children
} else {
[]
Expand Down
16 changes: 8 additions & 8 deletions core/source/Map.mint
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Map {
*/
fun delete (map : Map(key, value), keyToDelete : key) : Map(key, value) {
Map.fromArray(
for (key, value of map) {
for key, value of map {
{key, value}
} when {
key != keyToDelete
Expand All @@ -31,7 +31,7 @@ module Map {
*/
fun deleteValues (map : Map(key, value), valueToDelete : value) : Map(key, value) {
Map.fromArray(
for (key, value of map) {
for key, value of map {
{key, value}
} when {
value != valueToDelete
Expand Down Expand Up @@ -70,7 +70,7 @@ module Map {
function : Function(value, Bool)
) : Maybe(key) {
Array.first(
for (key, value of map) {
for key, value of map {
key
} when {
function(value)
Expand Down Expand Up @@ -98,7 +98,7 @@ module Map {
*/
fun get (map : Map(key, value), search : key) : Maybe(value) {
Array.first(
for (key, value of map) {
for key, value of map {
value
} when {
key == search
Expand Down Expand Up @@ -128,7 +128,7 @@ module Map {
*/
fun has (map : Map(key, value), search : key) : Bool {
Array.first(
for (key, value of map) {
for key, value of map {
true
} when {
key == search
Expand Down Expand Up @@ -158,7 +158,7 @@ module Map {
|> Map.values()) == ["a", "b"]
*/
fun keys (map : Map(key, value)) : Array(key) {
for (key, value of map) {
for key, value of map {
key
}
}
Expand All @@ -177,7 +177,7 @@ module Map {
function : Function(key, value, result)
) : Map(key, result) {
Map.fromArray(
for (key, value of map) {
for key, value of map {
({key, function(key, value)})
})
}
Expand Down Expand Up @@ -318,7 +318,7 @@ module Map {
|> Map.values()) == [1, 2]
*/
fun values (map : Map(key, value)) : Array(value) {
for (key, value of map) {
for key, value of map {
value
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/source/Math.mint
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ module Math {
*/
fun truncate (value : Number, to : Number) : Number {
let multiplier =
if (to == 0) {
if to == 0 {
1
} else {
to * 100
Expand Down
10 changes: 5 additions & 5 deletions core/source/Maybe.mint
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Maybe {
maybe : Maybe(value),
transform : Function(value, Maybe(result))
) : Maybe(result) {
case (maybe) {
case maybe {
Maybe::Just(value) => transform(value)
Maybe::Nothing => Maybe::Nothing
}
Expand All @@ -35,7 +35,7 @@ module Maybe {
|> Maybe.flatten()) == Maybe.just("A")
*/
fun flatten (maybe : Maybe(Maybe(value))) : Maybe(value) {
case (maybe) {
case maybe {
Maybe::Nothing => Maybe::Nothing
Maybe::Just(value) => value
}
Expand Down Expand Up @@ -73,7 +73,7 @@ module Maybe {
|> Maybe.map((number : Number) : Number { number + 2 })) == 3
*/
fun map (maybe : Maybe(value), func : Function(value, result)) : Maybe(result) {
case (maybe) {
case maybe {
Maybe::Just(value) => Maybe::Just(func(value))
Maybe::Nothing => Maybe::Nothing
}
Expand Down Expand Up @@ -102,7 +102,7 @@ module Maybe {
Maybe.toResult(Maybe.just("A"), "Error") == Result.ok("A")
*/
fun toResult (maybe : Maybe(value), error : error) : Result(error, value) {
case (maybe) {
case maybe {
Maybe::Just(value) => Result::Ok(value)
Maybe::Nothing => Result::Err(error)
}
Expand All @@ -125,7 +125,7 @@ module Maybe {
Maybe.withLazyDefault(Maybe.just("B"), () { "A" }) == "B"
*/
fun withLazyDefault (maybe : Maybe(value), func : Function(value)) : value {
case (maybe) {
case maybe {
Maybe::Nothing => func()
Maybe::Just(value) => value
}
Expand Down
2 changes: 1 addition & 1 deletion core/source/Number.mint
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Number {
|> Maybe.withDefault("")
|> String.chopEnd("0")

if (String.isEmpty(decimals)) {
if String.isEmpty(decimals) {
prefix + digits
} else {
prefix + digits + "." + decimals
Expand Down
6 changes: 3 additions & 3 deletions core/source/Provider/AnimationFrame.mint
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider Provider.AnimationFrame : Provider.AnimationFrame.Subscription {

/* Call the subscribers. */
fun process (timestamp : Number) : Promise(Void) {
for (subscription of subscriptions) {
for subscription of subscriptions {
subscription.frames(timestamp)
}

Expand All @@ -19,9 +19,9 @@ provider Provider.AnimationFrame : Provider.AnimationFrame.Subscription {

/* Updates the provider. */
fun update : Promise(Void) {
if (Array.isEmpty(subscriptions)) {
if Array.isEmpty(subscriptions) {
next { id: AnimationFrame.cancel(id) }
} else if (id == -1) {
} else if id == -1 {
next { id: AnimationFrame.request(process) }
} else {
next { }
Expand Down
14 changes: 7 additions & 7 deletions core/source/Provider/ElementSize.mint
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ provider Provider.ElementSize : Provider.ElementSize.Subscription {

/* Notifies all subscribers when there are changes. */
fun notify (entries : Array(ResizeObserver.Entry)) : Array(Array(Promise(Void))) {
for (entry of entries) {
for (subscription of subscriptions) {
if (subscription.element == Maybe::Just(entry.target)) {
for entry of entries {
for subscription of subscriptions {
if subscription.element == Maybe::Just(entry.target) {
subscription.changes(entry.dimensions)
} else {
next { }
Expand All @@ -27,12 +27,12 @@ provider Provider.ElementSize : Provider.ElementSize.Subscription {

/* Updates the provider. */
fun update : Promise(Void) {
for (element of Array.compact(observedElements)) {
for element of Array.compact(observedElements) {
ResizeObserver.unobserve(observer, element)
}

for (subscription of subscriptions) {
case (subscription.element) {
for subscription of subscriptions {
case subscription.element {
Maybe::Just(element) =>
{
ResizeObserver.observe(observer, element)
Expand All @@ -46,7 +46,7 @@ provider Provider.ElementSize : Provider.ElementSize.Subscription {
next
{
observedElements:
for (subscription of subscriptions) {
for subscription of subscriptions {
subscription.element
}
}
Expand Down
10 changes: 5 additions & 5 deletions core/source/Provider/Intersection.mint
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ provider Provider.Intersection : Provider.Intersection.Subscription {
longer present.
*/
let currentObservers =
for (item of observers) {
for item of observers {
let {subscription, observer} =
item

if (Array.contains(subscriptions, subscription)) {
if Array.contains(subscriptions, subscription) {
Maybe::Just({subscription, observer})
} else {
case (subscription.element) {
case subscription.element {
Maybe::Just(observed) =>
{
IntersectionObserver.unobserve(observer, observed)
Expand All @@ -40,8 +40,8 @@ provider Provider.Intersection : Provider.Intersection.Subscription {

/* Create new observers. */
let newObservers =
for (subscription of subscriptions) {
case (subscription.element) {
for subscription of subscriptions {
case subscription.element {
Maybe::Just(observed) =>
Maybe::Just(
{
Expand Down
6 changes: 3 additions & 3 deletions core/source/Provider/Keydown.mint
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ provider Provider.Keydown : Provider.Keydown.Subscription {

/* The event handler. */
fun handle (event : Html.Event) : Array(Promise(Void)) {
for (subscription of subscriptions) {
for subscription of subscriptions {
subscription.keydowns(event)
}
}

/* Updates the provider. */
fun update : Promise(Void) {
if (Array.isEmpty(subscriptions)) {
if Array.isEmpty(subscriptions) {
Maybe.map(listener, (unsubscribe : Function(Void)) { unsubscribe() })
next { listener: Maybe::Nothing }
} else {
case (listener) {
case listener {
Maybe::Nothing =>
next { listener: Maybe::Just(Window.addEventListener("keydown", true, handle)) }

Expand Down
6 changes: 3 additions & 3 deletions core/source/Provider/Keyup.mint
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ provider Provider.Keyup : Provider.Keyup.Subscription {

/* The event handler. */
fun handle (event : Html.Event) : Array(Promise(Void)) {
for (subscription of subscriptions) {
for subscription of subscriptions {
subscription.keyups(event)
}
}

/* Updates the provider. */
fun update : Promise(Void) {
if (Array.isEmpty(subscriptions)) {
if Array.isEmpty(subscriptions) {
Maybe.map(listener, (unsubscribe : Function(Void)) { unsubscribe() })
next { listener: Maybe::Nothing }
} else {
case (listener) {
case listener {
Maybe::Nothing =>
next { listener: Maybe::Just(Window.addEventListener("keyup", true, handle)) }

Expand Down
Loading

0 comments on commit a5e46ec

Please sign in to comment.