aboutsummaryrefslogtreecommitdiff
path: root/is/doc.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2025-11-26 17:40:56 +0100
committerStefan Majewsky <majewsky@gmx.net>2025-11-26 17:54:09 +0100
commit26023a903cc22130f96a50e6e09d205c412615da (patch)
tree1d4bf882a78978d6edb1f3b1f60d1f1f04b4e085 /is/doc.go
parent3f447c28466911e234d421eb7e3310e14c30dfa9 (diff)
downloadgo-gg-26023a903cc22130f96a50e6e09d205c412615da.tar.gz
add package is
Diffstat (limited to 'is/doc.go')
-rw-r--r--is/doc.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/is/doc.go b/is/doc.go
new file mode 100644
index 0000000..42af01e
--- /dev/null
+++ b/is/doc.go
@@ -0,0 +1,28 @@
+// SPDX-FileCopyrightText: 2025 Stefan Majewsky <majewsky@gmx.net>
+// SPDX-License-Identifier: Apache-2.0
+
+// Package is contains functions to express binary operations in a curried style.
+// For example, "foo < bar" can be rewritten as "is.LessThan(bar)(foo)".
+//
+// This is not useful on its own, but may significantly improve readability
+// when replacing function literals. Consider the following example:
+//
+// import . "github.com/majewsky/gg/option"
+//
+// func checkNewVolumeSize(size, usage uint64, maxSize Option[uint64]) error {
+// switch {
+// case size < usage:
+// return errors.New("size cannot be smaller than usage")
+// case maxSize.IsSomeAnd(func(value uint64) bool { return maxSize < size }):
+// return errors.New("size cannot be larger than maximum")
+// }
+// }
+//
+// The IsSomeAnd() check is difficult to read because function literals in Go are clunky.
+// This can be rewritten in a clearer way using is.LessThan():
+//
+// // original
+// case maxSize.IsSomeAnd(func(value uint64) bool { return maxSize < size }):
+// // rewritten
+// case maxSize.IsSomeAnd(is.LessThan(size)):
+package is