-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework
Sequence.locate
and Sequence.rlocate
Nothing actually used these before, primarily since their fuctionalty was not only unnecessary, but rather complicated. As such, remove those functions and replace them with new ones that (can) do pretty much the same, but much more than that, hopefully making them actually useful. (for reference, `Sequence.locate` now does what the javascript `Array.find` function does, taking a predicate and returning th first matching element, or `none`) Migration (in case someone actually used the old ones): ``` // Before local z = x.locate(y); // After local z = x.locate(item -> item == y); if (z is none) throw ValueError(); ```
- Loading branch information
1 parent
80225c7
commit cb8aa8e
Showing
29 changed files
with
295 additions
and
1,384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* Copyright (c) 2018-2024 Griefer@Work * | ||
* * | ||
* This software is provided 'as-is', without any express or implied * | ||
* warranty. In no event will the authors be held liable for any damages * | ||
* arising from the use of this software. * | ||
* * | ||
* Permission is granted to anyone to use this software for any purpose, * | ||
* including commercial applications, and to alter it and redistribute it * | ||
* freely, subject to the following restrictions: * | ||
* * | ||
* 1. The origin of this software must not be misrepresented; you must not * | ||
* claim that you wrote the original software. If you use this software * | ||
* in a product, an acknowledgement (see the following) in the product * | ||
* documentation is required: * | ||
* Portions Copyright (c) 2018-2024 Griefer@Work * | ||
* 2. Altered source versions must be plainly marked as such, and must not be * | ||
* misrepresented as being the original software. * | ||
* 3. This notice may not be removed or altered from any source distribution. * | ||
*/ | ||
import * from deemon; | ||
import * from errors; | ||
import identity from functools; | ||
|
||
function seq_locate(seq, item, key = none): Object { | ||
if (key is none) | ||
key = identity; | ||
item = key(item); | ||
for (local elem: seq as Sequence) { | ||
if (equals(item, key(elem))) | ||
return elem; | ||
} | ||
throw ValueError(f"Could not locate item `{item}' in sequence `{seq}'"); | ||
} | ||
|
||
function seq_rlocate(seq, item, key = none): Object { | ||
if (key is none) | ||
key = identity; | ||
item = key(item); | ||
local result; | ||
for (local elem: seq as Sequence) { | ||
if (equals(item, key(elem))) | ||
result = elem; | ||
} | ||
if (result is bound) | ||
return result; | ||
throw ValueError(f"Could not locate item `{item}' in sequence `{seq}'"); | ||
} | ||
|
||
function seq_locateall(seq, item, key = none): {Object...} { | ||
if (key is none) | ||
key = identity; | ||
item = key(item); | ||
for (local elem: seq as Sequence) { | ||
if (equals(item, key(elem))) | ||
yield elem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.