Comments (5)
Within go language, such helper can ONLY be
func F[T, U any](func(T)U, ...T) []U
or
func F[K comparable, T, U any] (func(T)U, map[K]T) map[K]U
For example, it will be written as
its.Slice(its.ApplyOver(its.EqEq[int], 1, 2, 3)).Match(...)
This may be the most concise expression in go.
But I have little confidence that it make us happy.
My intuition is not touched by that.
It only adds complexness and nerdish bonus, isn't it?
from its.
How'd about this?
its.SliceForEach(its.EqEq[int], 1, 2, 3).
Unordered().Match([]int{3, 1, 2}).
OrError(t)
from its.
How'd about this?
I'm afraid that Unordered
will be placed far from its.SliceForEach
.
Where should do user's eyes set focus on?
from its.
I have less idea about what to be done with this.
This issue is postponed as backlog.
from its.
func ForItems[T, U, X any, F func(U) Matcher[T], S func(...Matcher[T]) Matcher[X]](
s S, matcherFactory F, element []U,
) Matcher[X] {
cancel := itskit.SkipStack()
defer cancel()
ret := make([]Matcher[T], len(element))
for i := range element {
ret[i] = matcherFactory(element[i])
}
return s(ret...)
}
func ForEntries[
K comparable, T, U, X any, F func(U) Matcher[T], S func(map[K]Matcher[T]) Matcher[X],
](
s S,
matcherFactory F,
entries map[K]U,
) Matcher[X] {
cancel := itskit.SkipStack()
defer cancel()
m := map[K]Matcher[T]{}
for k := range entries {
m[k] = matcherFactory(entries[k])
}
return s(m)
}
Isn't it nice?
Especially ForItems
, it works with not only its.Slice
, its.SliceUnordered
but also All
or Some
.
It will be used as its.ForItems(its.Slice, its.EqEq, []int{1, 2, 3})
.
Names can be bikesheddable.
from its.
Related Issues (20)
- `Its.Nil` should be typed
- `Its.Slice()` runs into infinity loop when match with empty want/got HOT 1
- generic pointer matcher HOT 1
- mocker: `_FooBehaviour[T]` should be exported
- Text matcher?
- mocker: be `TaskBehaviour` returned by `FooCall(...).ThenReturn(...)` pointer
- mocker, structer: force import `golang.org/x/mod`
- `Text` mathcer does not work
- refactor: `internal/editorial_graph.New`: param name `from` and `to` are inverted
- split examples
- mocker: generates func/interfaces related private type
- `its.ClosedChan` can not be `its.Matcher[chan T]`
- Depreate `its.EqEqPtr`
- move `its.Property`
- mocker/scenario: remove token
- panic: `scenario.Next` with variadic parameter
- its/mocker: Should be `...Behaviour` the first-class citizen?
- its/mocker: support embedded interface HOT 2
- mock matcher?
- incompatible with go1.20- HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from its.