-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c07db1b
commit 67e56ce
Showing
16 changed files
with
216 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package threading | ||
package fun | ||
|
||
import ( | ||
"fmt" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package threading | ||
package fun | ||
|
||
import ( | ||
"strconv" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package threading | ||
package fun | ||
|
||
import ( | ||
"fmt" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package threading | ||
package fun | ||
|
||
import "testing" | ||
|
||
|
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,23 @@ | ||
package fun | ||
|
||
import "github.com/rushsteve1/fp" | ||
|
||
func Identity[T any](t T) T { | ||
return t | ||
} | ||
|
||
|
||
// Errorless takes a function that can error and returns a new function that | ||
// wraps the provided one in [fp.Must] | ||
func Errorless[T, U any](f func(T) (U, error)) func(T) U { | ||
return func(t T) U { | ||
return fp.Must(f(t)) | ||
} | ||
} | ||
|
||
// Discard takes a function and returns a new wrapping function without the return value | ||
func Discard[T, U any](f func(T) U) func(T) { | ||
return func(t T) { | ||
_ = f(t) | ||
} | ||
} |
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,49 @@ | ||
// This package wraps the standard library's [iter] package, providing some | ||
// additional features. | ||
// | ||
// It is intended to potentially inform future development and act as the | ||
// backbone of this library. | ||
|
||
package fp | ||
|
||
import ( | ||
"iter" | ||
) | ||
|
||
// SeqFunc is exactly the same as [iter.Seq] and can be trivially cast between | ||
type SeqFunc[V any] iter.Seq[V] | ||
|
||
// Seq borrows a trick used by [http.Handler] to define an interface and a func | ||
// that implements that interface by calling itself [SeqFunc] | ||
type Seq[V any] interface { | ||
// Seq implements push-style iteration using the yield callback. | ||
// See the documenation of [iter] for more information. | ||
// It has exactly the same signature as [SeqFunc]. | ||
Seq(yield func(V) bool) | ||
} | ||
|
||
func (sf SeqFunc[V]) Seq(yield func(V) bool) { | ||
sf(yield) | ||
} | ||
|
||
// Seq2Func is exactly the same as [iter.Seq2] and can be trivially cast between | ||
type Seq2Func[K, V any] iter.Seq2[K, V] | ||
|
||
// Seq2 is to [Seq] what [iter.Seq] is to [iter.Seq2] | ||
type Seq2[K, V any] interface { | ||
Seq2(yield func(K, V) bool) | ||
} | ||
|
||
func (sf Seq2Func[K, V]) Seq2(yield func(K, V) bool) { | ||
sf(yield) | ||
} | ||
|
||
// Pull is a wrappr around [iter.Pull] | ||
func Pull[V any](seq Seq[V]) (next func() (V, bool), stop func()) { | ||
return iter.Pull(seq.Seq) | ||
} | ||
|
||
// Pull2 is a wrapper around [iter.Pull2] | ||
func Pull2[K, V any](seq Seq2[K, V]) (next func() (K, V, bool), stop func()) { | ||
return iter.Pull2(seq.Seq2) | ||
} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package monads | ||
|
||
import ( | ||
) | ||
import "github.com/rushsteve1/fp" | ||
|
||
// Monad is a context that an operation took place in. | ||
// You can apply additional operations to | ||
type Monad[T any] interface { | ||
fp.Seq[T] | ||
Ok() bool | ||
Get() (T, error) | ||
Seq(yield func(T) bool) | ||
} |
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
Oops, something went wrong.