diff --git a/README.md b/README.md index 0eed1cd..10a3acb 100644 --- a/README.md +++ b/README.md @@ -103,48 +103,73 @@ For the actual generated code, see the [example](https://github.com/miyamo2/filt ## Features +### Types to be generated + +`filtgen` generates the following defined-types. +Type name is determined by the struct name; e.g. `User` -> `UserSlice`. +To use the generated methods, cast must be performed. +```go +s := []User{ + {Name: "Alice"}, + {Name: "Bob"}, +} +for i, v := range UserSlice(s).NameEq("Alice") { + fmt.Printf("%d: %s\n", i, v.Name) +} +``` + +`XxxSlice`(`[]T`) + +`XxxMap[K]`(`map[K compareble]T`) + +`XxxSeq[T]`(`iter.Seq[T]`) + +`XxxSeq2[T]`(`iter.Seq2[T, U]`) + +### Methods to be generated + Following methods are generated by `filtgen`. Method name is determined by the field name; e.g. `Name` -> `NameEq`. -### `XxxEq` +#### `XxxEq` Selects iterator items whose field values are equal to the specified value. -### `XxxNe` +#### `XxxNe` Selects iterator items whose field values are not equal to the specified value. -### `XxxGt` +#### `XxxGt` Selects iterator items whose field values are greater than the specified value. -### `XxxLt` +#### `XxxLt` Selects iterator items whose field values are less than the specified value. -### `XxxGe` +#### `XxxGe` Selects iterator items whose field values are greater than or equal to the specified value. -### `XxxLe` +#### `XxxLe` Selects iterator items whose field values are less than or equal to the specified value. -### `XxxMatches` +#### `XxxMatches` Selects iterator items whose field values match the specified function. -### `XxxIs` +#### `XxxIs` Selects iterator items whose field values are equal to the specified `error`. Equivalence is determined by `errors.Is`. -### `XxxIsnt` +#### `XxxIsnt` Selects iterator items whose field values are not equal to the specified `error`. Equivalence is determined by `errors.Is`. -## List of compatible filters by type +#### List of compatible filters by type | Type\Filter | `XxxEq` | `XxxNe` | `XxxGt` | `XxxLt` | `XxxGe` | `XxxLe` | `XxxMatches` | `XxxIs` | `XxxIsnt` | |--------------|---------|---------|---------|---------|---------|---------|--------------|---------|-----------| @@ -169,7 +194,7 @@ Equivalence is determined by `errors.Is`. | `bool` | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | | other-types | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | -## `filtgen` tags +### `filtgen` tags The following values can be set in the `filtgen` tag. If you want to set multiple values, separate them with `,`.