Skip to content

Commit 0e74c61

Browse files
committed
IterRecover() became available outside the package
1 parent 3c07d8b commit 0e74c61

20 files changed

+61
-20
lines changed

accumulate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func Accumulate[T any](iterable Iter[T], operator func(T, T) T) Iter[T] {
66
iter := Instance[T](iterable.Count(), iterable.IsInfinite())
77

88
go func() {
9-
defer iterRecover()
9+
defer IterRecover()
1010
defer iter.Close()
1111

1212
var last T

combinations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func Combinations[T any](symbols []T, limit int) Iter[[]T] {
3636
}
3737

3838
go func() {
39-
defer iterRecover()
39+
defer IterRecover()
4040
defer iter.Close()
4141

4242
// Loop over the stack until it is empty.

combinations_with_replacement.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func CombinationsWithReplacement[T any](symbols []T, k int) Iter[[]T] {
2121
iter := Instance[[]T](total, false)
2222

2323
go func() {
24-
defer iterRecover()
24+
defer IterRecover()
2525
defer iter.Close()
2626

2727
comb := make([]int, k)

count.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func Count[N Number](args ...N) Iter[N] {
99
iter := Instance[N](0, true)
1010

1111
go func() {
12-
defer iterRecover()
12+
defer IterRecover()
1313
defer iter.Close()
1414

1515
for {

cycle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func Cycle[T any](iterable Iter[T]) Iter[T] {
2121
// Run infinite loop into the goroutine and
2222
// send values from the slice to the channel.
2323
go func() {
24-
defer iterRecover()
24+
defer IterRecover()
2525
defer iter.Close()
2626

2727
for {

decrypt_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package iterium
2+
3+
import (
4+
"crypto/md5"
5+
"encoding/hex"
6+
"fmt"
7+
"strings"
8+
"testing"
9+
)
10+
11+
func BenchmarkDecryptMD5Hash(b *testing.B) {
12+
// result of md5("qwerty") = d8578edf8458ce06fbc5bb76a58c5ca4
13+
passHash := "d8578edf8458ce06fbc5bb76a58c5ca4"
14+
15+
for passLength := range Range(1, 7).Chan() {
16+
product := Product(AsciiLowercase, passLength)
17+
fmt.Println("Password Length:", passLength, "total combinations:", product.Count())
18+
19+
// Merge a slide into a string.
20+
// []string{"a", "b", "c"} => "abc"
21+
join := func(product []string) string {
22+
return strings.Join(product, "")
23+
}
24+
25+
// Check the hash of a raw password with an unknown hash.
26+
sameHash := func(rawPassword string) bool {
27+
hash := md5.Sum([]byte(rawPassword))
28+
return hex.EncodeToString(hash[:]) == passHash
29+
}
30+
31+
// Combine iterators to achieve the goal...
32+
decrypt := FirstTrue(
33+
Map(product, join), sameHash,
34+
)
35+
36+
if result, err := decrypt.Next(); err == nil {
37+
fmt.Println("Raw password:", result)
38+
break
39+
}
40+
}
41+
}

dropwhile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func DropWhile[T any](iterable Iter[T], pred func(T) bool) Iter[T] {
88
iter := Instance[T](0, false)
99

1010
go func() {
11-
defer iterRecover()
11+
defer IterRecover()
1212
defer iter.Close()
1313

1414
// Wait until the value from the channel returns false.

filter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func Filter[T any](iterable Iter[T], predicate func(T) bool) Iter[T] {
66
iter := Instance[T](iterable.Count(), iterable.IsInfinite())
77

88
go func() {
9-
defer iterRecover()
9+
defer IterRecover()
1010
defer iter.Close()
1111

1212
for {

filterfalse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func FilterFalse[T any](iterable Iter[T], predicate func(T) bool) Iter[T] {
66
iter := Instance[T](iterable.Count(), iterable.IsInfinite())
77

88
go func() {
9-
defer iterRecover()
9+
defer IterRecover()
1010
defer iter.Close()
1111

1212
for {

firstfalse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func FirstFalse[T any](iterable Iter[T], apply func(T) bool) Iter[T] {
66
iter := Instance[T](0, false)
77

88
go func() {
9-
defer iterRecover()
9+
defer IterRecover()
1010
defer iter.Close()
1111

1212
for true {

0 commit comments

Comments
 (0)