{"id":17119034,"url":"https://github.com/chyroc/go-lambda","last_synced_at":"2025-07-08T10:38:57.747Z","repository":{"id":38310494,"uuid":"409457442","full_name":"chyroc/go-lambda","owner":"chyroc","description":"Process data like functional programming","archived":false,"fork":false,"pushed_at":"2023-05-19T03:58:14.000Z","size":130,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-29T08:23:18.684Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chyroc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-23T05:16:33.000Z","updated_at":"2021-11-17T03:37:18.000Z","dependencies_parsed_at":"2024-12-01T05:21:34.904Z","dependency_job_id":"a0659a7d-c51e-4fa4-9d0b-c458eedb5047","html_url":"https://github.com/chyroc/go-lambda","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chyroc%2Fgo-lambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chyroc%2Fgo-lambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chyroc%2Fgo-lambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chyroc%2Fgo-lambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chyroc","download_url":"https://codeload.github.com/chyroc/go-lambda/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245195962,"owners_count":20575938,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T17:56:08.610Z","updated_at":"2025-03-24T02:19:05.789Z","avatar_url":"https://github.com/chyroc.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-lambda\n\n[![codecov](https://codecov.io/gh/chyroc/go-lambda/branch/master/graph/badge.svg?token=Z73T6YFF80)](https://codecov.io/gh/chyroc/go-lambda)\n[![go report card](https://goreportcard.com/badge/github.com/chyroc/go-lambda \"go report card\")](https://goreportcard.com/report/github.com/chyroc/go-lambda)\n[![test status](https://github.com/chyroc/go-lambda/actions/workflows/test.yml/badge.svg)](https://github.com/chyroc/go-lambda/actions)\n[![Apache-2.0 license](https://img.shields.io/badge/License-Apache%202.0-brightgreen.svg)](https://opensource.org/licenses/Apache-2.0)\n[![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-blue?logo=go\u0026logoColor=white)](https://pkg.go.dev/github.com/chyroc/go-lambda)\n[![Go project version](https://badge.fury.io/go/github.com%2Fchyroc%2Fgo-lambda.svg)](https://badge.fury.io/go/github.com%2Fchyroc%2Fgo-lambda)\n\n![](./header.jpg)\n\nProcess data like functional programming\n\n## Install\n\n```shell\ngo get github.com/chyroc/go-lambda\n```\n\n## Usage\n\n### A simple example\n\n```go\nfunc ExampleNew() {\n\tobj := lambda.New([]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})\n\n\tobj = obj.FilterList(func(idx int, obj interface{}) bool {\n\t\treturn obj.(int)%2 == 0\n\t})\n\tfmt.Println(obj.ToIntSlice())\n\n\tobj = obj.Chunk(3)\n\tfmt.Println(obj.ToExpectType([][]int{}))\n\n\tobj = obj.Flatten()\n\tfmt.Println(obj.ToIntSlice())\n\n\tobj = obj.Compact()\n\tfmt.Println(obj.ToIntSlice())\n\n\tobj = obj.MapList(func(idx int, obj interface{}) interface{} {\n\t\treturn exampleItem{Name: fmt.Sprintf(\"name-%d\", obj.(int))}\n\t})\n\tfmt.Println(obj.ToExpectType([]exampleItem{}))\n\n\t// output:\n\t// [0 2 4 6 8] \u003cnil\u003e\n\t// [[0 2 4] [6 8]] \u003cnil\u003e\n\t// [0 2 4 6 8] \u003cnil\u003e\n\t// [2 4 6 8] \u003cnil\u003e\n\t// [{name-2} {name-4} {name-6} {name-8}] \u003cnil\u003e\n}\n```\n\n### Chunk\n\n```go\nfunc ExampleObject_Chunk() {\n\t// Split the list into shorter length lists\n\tres, err := lambda.New([]int{1, 2, 3, 4, 5}).Chunk(2).ToIntListList()\n\tfmt.Println(\"err:\", err)\n\tfmt.Println(\"res:\", res)\n\t// output:\n\t// err: \u003cnil\u003e\n\t// res: [[1 2] [3 4] [5]]\n}\n```\n\n### Compact\n\n```go\nfunc ExampleObject_Compact() {\n\t// Remove 0-valued elements from the list\n\tres, err := lambda.New([]int{0, 1, 2, 1, 0, 2}).Compact().ToIntSlice()\n\tfmt.Println(\"err:\", err)\n\tfmt.Println(\"res:\", res)\n\t// output:\n\t// err: \u003cnil\u003e\n\t// res: [1 2 1 2]\n}\n```\n\n### Flatten\n\n```go\nfunc ExampleObject_Flatten() {\n\t// Flatten the list\n\tres, err := lambda.New([][]int{{1, 2}, {2, 3}, {4}}).Flatten().ToIntSlice()\n\tfmt.Println(\"err:\", err)\n\tfmt.Println(\"res:\", res)\n\t// output:\n\t// err: \u003cnil\u003e\n\t// res: [1 2 2 3 4]\n}\n```\n\n### Reverse\n\n```go\nfunc ExampleObject_Reverse() {\n\t// Reverse list\n\tres, err := lambda.New([]int{1, 2, 3, 4}).Reverse().ToIntSlice()\n\tfmt.Println(\"err:\", err)\n\tfmt.Println(\"res:\", res)\n\t// output:\n\t// err: \u003cnil\u003e\n\t// res: [4 3 2 1]\n}\n```\n\n### Uniq\n\n```go\nfunc ExampleObject_Uniq() {\n\t// Remove duplicate elements in the list\n\tres, err := lambda.New([]int{1, 2, 1, 3, 2, 3, 4}).Uniq().ToIntSlice()\n\tfmt.Println(\"err:\", err)\n\tfmt.Println(\"res:\", res)\n\t// output:\n\t// err: \u003cnil\u003e\n\t// res: [1 2 3 4]\n}\n```\n\n### MapArray\n\n```go\nfunc ExampleObject_MapList() {\n\t// Traverse the elements of the list, and after each element is processed, the returned elements form a new list\n\tres, err := lambda.New([]int{1, 2, 3}).MapArray(func(idx int, obj interface{}) interface{} {\n\t\treturn obj.(int) + 1\n\t}).ToIntSlice()\n\tfmt.Println(\"err:\", err)\n\tfmt.Println(\"res:\", res)\n\t// output:\n\t// err: \u003cnil\u003e\n\t// res: [2 3 4]\n}\n```\n\n### FilterArray\n\n```go\nfunc ExampleObject_FilterList() {\n\t// Traverse the elements of the list, each element is added to a new list or not, and a new list is returned\n\tres, err := lambda.New([]int{1, 2, 3, 4}).FilterArray(func(idx int, obj interface{}) bool {\n\t\treturn obj.(int)%2 == 0\n\t}).ToIntSlice()\n\tfmt.Println(\"err:\", err)\n\tfmt.Println(\"res:\", res)\n\t// output:\n\t// err: \u003cnil\u003e\n\t// res: [2 4]\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchyroc%2Fgo-lambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchyroc%2Fgo-lambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchyroc%2Fgo-lambda/lists"}