samber / lo

💥 A Lodash-style Go library based on Go 1.18+ Generics (map, filter, contains, find...)
https://pkg.go.dev/github.com/samber/lo
MIT License
17.37k stars 797 forks source link

proof is in the pudding - go playground for examples #226

Open headwinds opened 1 year ago

headwinds commented 1 year ago

first off, fantastic library! this is more praise and wanting to help myself and others learn than an issue.

Has anyone already started to build a collection of examples using the go playground? The docs are excellent - a working example would be icing.

I was struggling a bit to learn how to use filter against a collection so created this playground to sort it out.

samber commented 1 year ago

hi @headwinds

I made a small PR: #230

Can you review it, please?

As soon as we are ok with this first PR, we can distribute work ;)

headwinds commented 1 year ago

@samber I've reviewed & much approve - that's an excellent approach and should encourage more devs to contribute examples!

samber commented 1 year ago

Can I ask you to write some examples for find.go ? I will keep pushing for slice.go and map.go.

I liked the example you provided above, but don't spend too much time with such big samples! ;)

I gonna write some instructions to future contributors in a PR template.

samber commented 1 year ago

I just added:

headwinds commented 1 year ago

cool I'll take a look at your samples and could write one similar for find.go - keep it small simple - 😘

headwinds commented 1 year ago

find playground

or maybe not so simple but I always look for examples that have both a simple string and an object

headwinds commented 1 year ago

find playground that handles no results

samber commented 1 year ago

Can I suggest some changes ?

-> https://go.dev/play/p/c2lDl0vxr-V

In your last snippet, I'm not sure declaring ProductSearchResult is necessary. It makes the example longer to understand. You can just return (Product, error) instead.

headwinds commented 1 year ago

@samber Yes this is great - let's go with your version - I'm pretty new to go and can see the experience in your upgrades!

headwinds commented 1 year ago

Actually one small change - can we flip the function names and order - so that string example runs first then the struct example - simple before complex

Currently it prints:

We also found the product Dragon Fruit ($3.75) 
We found the coconut

So I'd like to read:

We found the coconut
We also found the product Dragon Fruit ($3.75) 

And ship it!

samber commented 1 year ago

Yes, no worries ;)

Examples need to be clear and simple to read. This is the only requirement ;)

samber commented 1 year ago

Still a few examples missing: