@@ -76,7 +76,7 @@ keys, values := it.Collect2(maps.All(map[string]int{"one": 1, "two": 2}))
7676keys , values  :=  itx.FromMap (map [string ]int {" one"  : 1 , " two"  : 2 }).Collect ()
7777``` 
7878
79- ###  TryCollect 
79+ < h3   id = " trycollect " > TryCollect & MustCollect</ h3 > 
8080
8181Dealing with iterators that return ` T, error `  can involve the boilerplate of checking that the
8282returned slice of errors only contains ` nil ` . ` TryCollect `  solves this by collecting all values into
@@ -90,14 +90,28 @@ if lines, err := it.TryCollect(it.LinesString(text)); err != nil {
9090}
9191``` 
9292
93+ MustCollect is similar except that if an error is encountered then a panic will occur.
94+ 
95+ ``` go 
96+ text  :=  strings.NewReader (" one\n two\n three\n "  )
97+ 
98+ lines  :=  it.MustCollect (it.LinesString (text))
99+ ``` 
100+ 
101+ <!--  prettier-ignore --> 
102+ >  [ !TIP] 
103+ >  Use ` MustCollect `  when you can guarantee that no error will occur (such as with
104+ >  [ strings.Reader] ( https://pkg.go.dev/strings#Reader ) ).
105+ 
93106<!--  prettier-ignore --> 
94107>  [ !NOTE] 
95108>  If an error is encountered, collection stops. This means the iterator being collected may not be
96109>  fully drained.
97110
98111<!--  prettier-ignore --> 
99112>  [ !NOTE] 
100- >  The ` itx `  package does not contain ` TryCollect `  due to limitations with Go's type system.
113+ >  The ` itx `  package does not contain ` TryCollect `  or ` MustCollect `  due to limitations with Go's type
114+ >  system.
101115
102116### ForEach  
103117
@@ -316,7 +330,7 @@ itx.From2(it.Map2(slices.All([]int{1, 2, 3}), printValue2)).Drain()
316330
317331<!--  prettier-ignore --> 
318332>  [ !TIP] 
319- >  Use Drain to consume an iterator to invoke any side effects when you don't need to collect the
333+ >  Use ` Drain `  to consume an iterator to invoke any side effects when you don't need to collect the
320334>  values.
321335
322336## Iterators  
0 commit comments