GithubHelp home page GithubHelp logo

Comments (5)

youta-t avatar youta-t commented on May 27, 2024

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.

youta-t avatar youta-t commented on May 27, 2024

How'd about this?

	its.SliceForEach(its.EqEq[int], 1, 2, 3).
		Unordered().Match([]int{3, 1, 2}).
		OrError(t)

from its.

youta-t avatar youta-t commented on May 27, 2024

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.

youta-t avatar youta-t commented on May 27, 2024

I have less idea about what to be done with this.
This issue is postponed as backlog.

from its.

youta-t avatar youta-t commented on May 27, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.