-
Notifications
You must be signed in to change notification settings - Fork 99
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
make bots happy #651
base: master
Are you sure you want to change the base?
make bots happy #651
Changes from all commits
b036e20
1b5f939
7ba7c31
8b11b63
f3286fa
6679f52
8ce964d
d7e64d5
28a673d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,6 +160,12 @@ module { | |
}; | ||
return null | ||
}; | ||
public func exists<X>(array : [X], predicate : X -> Bool) : Bool { | ||
Option.isSome(find(array, predicate)) | ||
}; | ||
public func forall<X>(array : [X], predicate : X -> Bool) : Bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is called |
||
not exists<X>(array, func x = not (predicate x)) | ||
}; | ||
|
||
/// Create a new array by appending the values of `array1` and `array2`. | ||
/// Note that `Array.append` copies its arguments and has linear complexity; | ||
|
@@ -207,6 +213,10 @@ module { | |
sortInPlace(temp, compare); | ||
freeze(temp) | ||
}; | ||
public func sortByLessThanOrEqual<X>(array : [X], isLessThanOrEqual : (X, X) -> Bool) : [X] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still an isse with the revised prompt? The bot was having trouble with defining functions returning Order.order because the prompt was actually misleadingly broken. Maybe we could call |
||
let compare = Order.lteToOrder(isLessThanOrEqual); | ||
sort(array, compare); | ||
}; | ||
|
||
/// Sorts the elements in the array, __in place__, according to `compare`. | ||
/// Sort is deterministic, stable, and in-place. | ||
|
@@ -575,6 +585,7 @@ module { | |
|
||
accumulation | ||
}; | ||
public let fold = foldLeft; | ||
|
||
// FIXME the type arguments are reverse order from Buffer | ||
/// Collapses the elements in `array` into a single value by starting with `base` | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1050,6 +1050,18 @@ module { | |||||
|
||||||
null | ||||||
}; | ||||||
public func find<X>(buffer : Buffer<X>, equal : X -> Bool) : ?X { | ||||||
let size = buffer.size(); | ||||||
var i = 0; | ||||||
while (i < size) { | ||||||
let x = buffer.get(i); | ||||||
if (equal(x)) { | ||||||
return ?x | ||||||
}; | ||||||
i += 1 | ||||||
}; | ||||||
null | ||||||
}; | ||||||
|
||||||
/// Finds the last index of `element` in `buffer` using equality of elements defined | ||||||
/// by `equal`. Returns `null` if `element` is not found. | ||||||
|
@@ -2368,6 +2380,20 @@ module { | |||||
|
||||||
(buffer1, buffer2) | ||||||
}; | ||||||
/// Slice buffer from [start, end). | ||||||
public func slice<X>(buffer : Buffer<X>, start : Nat, end : Nat) : Buffer<X> { | ||||||
let size = buffer.size(); | ||||||
if (start < 0 or start > size or end < 0 or end > size or start > end) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Nat's are never < 0, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs better doc and test. |
||||||
Prim.trap "Index out of bounds in slice" | ||||||
}; | ||||||
let newBuffer = Buffer<X>(newCapacity(end - start)); | ||||||
var i = start; | ||||||
while (i < end) { | ||||||
newBuffer.add(buffer.get(i)); | ||||||
i += 1 | ||||||
}; | ||||||
newBuffer | ||||||
}; | ||||||
|
||||||
/// Breaks up `buffer` into buffers of size `size`. The last chunk may | ||||||
/// have less than `size` elements if the number of elements is not divisible | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ module { | |
public func abs(x : Int) : Nat { | ||
Prim.abs(x) | ||
}; | ||
public func fromNat(n : Nat) : Int = n; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs doc . |
||
|
||
/// Converts an integer number to its textual representation. Textual | ||
/// representation _do not_ contain underscores to represent commas. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ import Int "Int"; | |
import Order "Order"; | ||
import Prim "mo:⛔"; | ||
import Char "Char"; | ||
import Hash "Hash"; | ||
import Iter "Iter"; | ||
|
||
module { | ||
|
||
|
@@ -26,6 +28,10 @@ module { | |
/// Nat.toText 1234 // => "1234" | ||
/// ``` | ||
public func toText(n : Nat) : Text = Int.toText n; | ||
public func hash(n : Nat) : Hash.Hash = Hash.hash(n); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hash.hash is suboptimal. Do we really want to spread it's use? |
||
public func abs(n : Int) : Nat = Int.abs n; | ||
public func fromInt(n : Int) : Nat = Int.abs n; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
public let range = Iter.range; | ||
|
||
/// Creates a natural number from its textual representation. Returns `null` | ||
/// if the input is not a valid natural number. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
/// ``` | ||
import Nat "Nat"; | ||
import Prim "mo:⛔"; | ||
import Hash "Hash"; | ||
|
||
module { | ||
|
||
|
@@ -29,6 +30,7 @@ module { | |
/// Nat32.toNat(123); // => 123 : Nat | ||
/// ``` | ||
public let toNat : Nat32 -> Nat = Prim.nat32ToNat; | ||
public func hash(n : Nat32) : Hash.Hash = Hash.hash(toNat n); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same argument about Hash.hash |
||
|
||
/// Converts an unsigned integer with infinite precision to a 32-bit unsigned integer. | ||
/// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,5 +42,17 @@ module { | |
case _ { false } | ||
} | ||
}; | ||
|
||
public func lteToOrder<X>(isLessThanOrEqual : (X, X) -> Bool) : (X, X) -> Order { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if there is a better name for this... totalOrderToComparer or lessThanOrEqualToCompare or |
||
func (a : X, b : X) : Order { | ||
if (isLessThanOrEqual(a, b)) { | ||
if (isLessThanOrEqual(b, a)) { | ||
#equal; | ||
} else { | ||
#less; | ||
} | ||
} else { | ||
#greater; | ||
}; | ||
}; | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is called
some
in Trie.mo and List.mo. I'd hate to introduce inconsistency. Does the bot insist one this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also would need doc and some tests, ideally.