Skip to content

Commit e0b4be3

Browse files
committed
add iterators example
1 parent e80be5f commit e0b4be3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

content/examples.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,23 @@ data SpecialDates = {MonthDay ^ ..=365}
9191
data Birthdays = { MonthDay -> ^ ..=365 {String256 ^ ..=0xFF} }
9292
```
9393

94-
### Cycles and iterators
94+
### Iterators
95+
96+
```
97+
class iter => item any
98+
fx next: _ -> item?
99+
100+
infx findFirst: V eq, I iter(item eq) => iter I, value V -> U64?
101+
enumerate iter |> fst =?= value |? $ := lst _
102+
103+
infx hasUnique: V eq, I iter(item eq) => iter I, value V -> Bool
104+
let index := iter findFirst value !! false
105+
(iter[index..] |> =?= value |? $ := false) ?? true
106+
107+
[0, 1, 2, 3, 4] hasUnique 1 -- true
108+
```
109+
110+
### Collection comprehensions
95111

96112
```
97113
let congratulations :=

0 commit comments

Comments
 (0)