Skip to content
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

List methods #1086

Merged
merged 38 commits into from
Dec 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e2baa03
Fix listOf(…) for three items
JonasWanke Dec 5, 2024
5da5a9a
Fix references to outer parameters in lambdas
JonasWanke Dec 5, 2024
ef775c4
Fix nullptr to NULL
JonasWanke Dec 5, 2024
052db45
Remove invalid assert!(…)
JonasWanke Dec 5, 2024
bef32d7
Improve todo message
JonasWanke Dec 5, 2024
8c2f762
Add maybe., result..unwrapOr(…), .unwrapOrElse(…)
JonasWanke Dec 5, 2024
86ccbe1
Add list.fold(…), .reduce(…). map(…)
JonasWanke Dec 5, 2024
223caa4
impl[T: ToText] List[T]: ToText
JonasWanke Dec 5, 2024
8742569
Support escape sequences in text
JonasWanke Dec 5, 2024
69abd8e
Use Display formatting of type
JonasWanke Dec 5, 2024
2ea4f90
Add text.split(…), .splitIf(…)
JonasWanke Dec 5, 2024
3553c9a
Merge branch 'function-types-in-ast' into list-methods
JonasWanke Dec 8, 2024
5215be7
Lower lambdas inside switch cases
JonasWanke Dec 11, 2024
82c8f00
Use (signed) int64_t for Int
JonasWanke Dec 11, 2024
8bfbe1f
Validate length in builtinListFilled(…)
JonasWanke Dec 11, 2024
4ba7088
Add listGenerate(…)
JonasWanke Dec 11, 2024
e536448
Add list.getRange(…)
JonasWanke Dec 11, 2024
61c0afb
Add list.windows(…)
JonasWanke Dec 11, 2024
c28725c
Remove indentation in empty line
JonasWanke Dec 11, 2024
e9fa691
Merge branch 'list-methods' into advent-of-code
JonasWanke Dec 11, 2024
96f0710
Rename int.is(Less|Greater)ThanOrEqualTo(…) to .isAt(Least|Most)(…)
JonasWanke Dec 12, 2024
a3ac6f7
Add list.filter(…)
JonasWanke Dec 12, 2024
56a9b10
Add list.all(…), .any(…)
JonasWanke Dec 12, 2024
f8bfdd8
impl Mono: ToText
JonasWanke Dec 12, 2024
6d24849
Add struct Pair[T0, T1]
JonasWanke Dec 12, 2024
a41cfff
Add list.pairs()
JonasWanke Dec 12, 2024
35d58fb
Improve call type argument debug formatting
JonasWanke Dec 12, 2024
e885780
Use environment when lowering ExpressionKind::CreateStruct
JonasWanke Dec 12, 2024
d073533
Fix switch debug formatting in HIR, Mono
JonasWanke Dec 12, 2024
b8b90ee
Propagate error
JonasWanke Dec 12, 2024
0b7a1a4
Add error messages when unwrap fails
JonasWanke Dec 12, 2024
3334a92
impl Ordering: Compare
JonasWanke Dec 12, 2024
d62f705
impl Bool: Compare
JonasWanke Dec 12, 2024
ee7055c
Add list.isSortedBy(…), .isStrictly(Ascending|Descending)(…)
JonasWanke Dec 12, 2024
c9e83be
Add list.concat(…)
JonasWanke Dec 12, 2024
4b79ede
Add list.indexes(…)
JonasWanke Dec 12, 2024
fba96b8
Merge branch 'main' into list-methods
JonasWanke Dec 14, 2024
9772291
Simplify list.allHelper(…)
JonasWanke Dec 19, 2024
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
Prev Previous commit
Next Next commit
Add list.windows(…)
  • Loading branch information
JonasWanke committed Dec 11, 2024
commit 61c0afb9abb9ab27a9a881e58dae178a8ce50710
19 changes: 19 additions & 0 deletions packages_v5/example.candy
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,25 @@ fun map[T, R](list: List[T], transform: (T) R) List[R] {
result.append(transform(item))
})
}
fun windows[T](list: List[T], windowLength: Int) List[List[T]] {
# Returns a list over all contiguous windows of length `windowLength`.
#
# The windows overlap. If the `list` is shorter than `windowLength`, the
# resulting list is empty.
needs(windowLength.isPositive())

list.windowsHelper(windowLength, listOf[List[T]]())
}
fun windowsHelper[T](list: List[T], windowLength: Int, resultSoFar: List[List[T]]) List[List[T]] {
let index = resultSoFar.length()
switch index.isLessThanOrEqualTo(list.length().subtract(windowLength)) {
true => list.windowsHelper(
windowLength,
resultSoFar.append(list.getRange(index, index.add(windowLength))),
),
false => resultSoFar,
}
}
impl[T: ToText] List[T]: ToText {
fun toText(self: List[T]) Text {
let items = self.map((item: T) { item.toText() })
Expand Down