{"id":40088153,"url":"https://github.com/zx80live/gofp","last_synced_at":"2026-01-19T10:01:05.303Z","repository":{"id":57556872,"uuid":"311431278","full_name":"zx80live/gofp","owner":"zx80live","description":"Go for Scala developers","archived":false,"fork":false,"pushed_at":"2021-01-14T13:47:03.000Z","size":3786,"stargazers_count":1,"open_issues_count":21,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-11-22T15:02:30.678Z","etag":null,"topics":["collection-api","concurrence-api","functional-programming","golang","io-api","lazy-evaluation"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zx80live.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-09T18:36:19.000Z","updated_at":"2025-06-03T07:02:50.000Z","dependencies_parsed_at":"2022-08-25T20:01:45.231Z","dependency_job_id":null,"html_url":"https://github.com/zx80live/gofp","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/zx80live/gofp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zx80live%2Fgofp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zx80live%2Fgofp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zx80live%2Fgofp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zx80live%2Fgofp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zx80live","download_url":"https://codeload.github.com/zx80live/gofp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zx80live%2Fgofp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28565051,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T08:53:44.001Z","status":"ssl_error","status_checked_at":"2026-01-19T08:52:40.245Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["collection-api","concurrence-api","functional-programming","golang","io-api","lazy-evaluation"],"created_at":"2026-01-19T10:01:04.269Z","updated_at":"2026-01-19T10:01:05.286Z","avatar_url":"https://github.com/zx80live.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Functional programming in GO\n\n\n## Introduction\n\nThis library was inspired by Scala (collection API, functional paradigm and, concurrence API etc).\nIt allows to program in Go using functional style similar to Scala. \nIt enables us to combine the efficiency of FP and performance of Golang. \nThere is an opportunity to work with mutable/immutable collections, futures which are monads.\n\n## Table of contents\n\n- [Getting started](#getting-started)\u003ca name=\"toc0\"\u003e\u003c/a\u003e\n- [Collection API](#collection-api)\n  * [List](#list)\u003ca name=\"list0\"\u003e\u003c/a\u003e\n    + [List structure](#list-structure)\n    + [Create list](#create-list)\n    + [List.Copy](#listcopy)\n    + [List.Count](#listcount)\n    + [List.Drops](#listdrops)\n    + [List.Equals](#listequals)\n    + [List.Filter](#listfilter)\n    + [List.Find](#listfind)\n    + [List.FlatMap](#listflatmap)\n    + [List.Flatten](#listflatten)\n    + [List.FoldLeft](#listfoldleft)\n    + [List.Foreach](#listforeach)\n    + [List.GroupBy](#listgroupby)\n    + [List.Heads and tails](#listheads-and-tails)\n    + [List.Empty NonEmpty](#listempty-nonempty)\n    + [List.Map](#listmap)\n    + [List.MkString](#listmkstring)\n    + [List.Nil](#listnil)\n    + [List.Cons](#listcons)\n    + [List.Reduce](#listreduce)\n    + [List.Reverse](#listreverse)\n    + [List.Size](#listsize)\n    + [List.Takes](#listtakes)\n    + [List.ToArray](#listtoarray)\n    + [List.ToString](#listtostring)\n    + [List.Zip](#listzip)\n    + [List.ZipAll](#listzipall)\n    + [List.ZipWithIndex](#listzipwithindex)\n    + [Supported list types](#supported-list-types)\n  * [Option](#option)\u003ca name=\"option0\"\u003e\u003c/a\u003e\n    + [Create option](#create-option)\n    + [Option.Equals](#optionequals)\n    + [Option.Filter](#optionfilter)\n    + [Option.FlatMap](#optionflatmap)\n    + [Option.Flatten](#optionflatten)\n    + [Option.FoldLeft](#optionfoldleft)\n    + [Option.Foreach](#optionforeach)\n    + [Option.IsDefined](#optionisdefined)\n    + [Option.IsEmpty](#optionisempty)\n    + [Option.Map](#optionmap)\n    + [Option.None](#optionnone)\n    + [Option.ToString](#optiontostring)\n    + [Supported option types](#supported-option-types)\n  * [Tuple2](#tuple2)\u003ca name=\"tuple20\"\u003e\u003c/a\u003e\n    + [Create tuple2](#create-tuple2)\n    + [Tuple2.Equals](#tuple2equals)\n    + [Tuple2.ToString](#tuple2tostring)\n  * [Array](#array)\u003ca name=\"array0\"\u003e\u003c/a\u003e\n    + [Create array](#create-array)\n    + [Array.Count](#arraycount)\n    + [Array.Drops](#arraydrops)\n    + [Array.Equals](#arrayequals)\n    + [Array.Filter](#arrayfilter)\n    + [Array.Find](#arrayfind)\n    + [Array.Foreach](#arrayforeach)\n    + [Array.Heads and tails](#arrayheads-and-tails)\n    + [Array.Map](#arraymap)\n    + [Array.MkString](#arraymkstring)\n    + [Array.Takes](#arraytakes)\n    + [Array.ToList](#arraytolist)\n    + [Array.ToString](#arraytostring)\n    + [Array.Zip](#arrayzip)\n    + [Array.ZipAll](#arrayzipall)\n    + [Array.ZipWithIndex](#arrayzipwithindex)\n    + [Supported array types](#supported-array-types)\n- [Boxed types](#boxed-types)\u003ca name=\"boxed0\"\u003e\u003c/a\u003e\n    + [Underlined](#underlined)\n    + [Converters](#converters)\n    + [List constructors](#list-constructors)\n    + [Math and logic operations](#math-and-logic-operations)\n    + [Supported boxed types](#supported-boxed-types)\n- [Predicates](#predicates)\u003ca name=\"predicates0\"\u003e\u003c/a\u003e\n    + [Empty predicates](#empty-predicates)\n    + [Numeric predicates](#numeric-predicates)\n    + [String predicates](#string-predicates)\n    + [Predicates composition](#predicates-composition)\n    + [Supported predicate types](#supported-predicate-types)\n- [Transformers](#transformers)\u003ca name=\"transformers0\"\u003e\u003c/a\u003e\n    + [Identity](#identity)\n    + [String transformers](#string-transformers)\n- [Predef](#predef)\u003ca name=\"predef0\"\u003e\u003c/a\u003e\n    + [Require](#require)\n- [Concurrency API](#concurrency-api)\u003ca name=\"concurrency0\"\u003e\u003c/a\u003e\n  * [Future](#future)\u003ca name=\"future0\"\u003e\u003c/a\u003e\n    + [Create future](#create-future)  \n    + [Future.FlatMap](#futureflatmap)\n    + [Future.FlatMap Blocking composition](#futureflatmapblocking-composition)\n    + [Future.FlatMap NON-blocking composition](#futureflatmapnon-blocking-composition)\n    + [Future.Map](#futuremap)\n    + [Future.Result](#futureresult)\n    + [Future.Success](#futuresuccess)\n    + [Supported future types](#supported-future-types)\n- [Bootstrap](#bootstrap)\u003ca name=\"bootstrap0\"\u003e\u003c/a\u003e\n- [License](#license)\u003ca name=\"license0\"\u003e\u003c/a\u003e\n\n\n## Getting started\n\nBefore using functional library add dependency in your `go.mod` file:\n```go\nrequire github.com/zx80live/gofp v1.0.1\n```\nand then import the following package in your project:\n```go\nimport . \"github.com/zx80live/gofp/fp\"\n```\n\nOr do the following steps if you want to create an empty project:\n\n1. Create new go-module project in your `$WORK_DIR` directory\n```bash\n# create your project dir\ncd $WORK_DIR\nmkdir test-gofp\ncd test-gofp\n\n# create your go-module\ngo mod init example.com/username/test-gofp\n```\n\n2. Add dependency in your `go.mod` file:\n```bash\necho 'require github.com/zx80live/gofp v1.0.1' \u003e\u003e go.mod\ncat go.mod\n```\nThe result of previous command should be:\n```go\nmodule example.com/pav/test-gofp\n\ngo 1.15\nrequire github.com/zx80live/gofp v1.0.1\n```\n\n3. Create your first go-file in your preffered editor, for example:\n```bash\nvim test.go\n```\n4. Write the following code in the `$WORK_DIR/test-gofp/test.go` file:\n```go\npackage main\n\nimport (\n\t\"fmt\"\n    . \"github.com/zx80live/gofp/fp\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello functional programming in GO!\")\n\n  l := MkIntList(1,2,3,4,5,-6,-7,-8,9)\n  res1 := l.Filter(EvenInt.And(PosInt)).\n            MapInt(func(e int) int { return e * 10})\n\n  fmt.Println(res1.ToString())\n}\n```\n\n5. Execute file:\n```bash\ngo run test.go\n```\nThe result of above command should be:\n```\nHello functional programming in GO!\nList(20,40)\n```\n\n4. Explore this library by the examples which are presented in that [documentation](#toc0). Good luck!\n\n## Collection API\n\nCurrent library supports the following collection types: `Arrays`, `Lists` and `Options`. Each type is monad and supports functions such as `Map`, `FlatMap`, `Filter` and etc.\n\n[[🠕]](#list0)\n\n### List\n\nAll examples of  this section use a `IntList` type. But this API is supported in the other array types also. (See [Supported list types](#supported-list-types) section)\n[[🠕]](#list0)\n\n#### List structure\n\nList is recursive functional data structure which has `head` and `tail` as sublist. For example, an `IntList(1,2,3)` will be presented in the following structure: \n\n```go\n   1 ──▶ ( 2 ──▶ ( 3 ──▶ Nil ) )\n  └─┘    └─────────────────────┘          \n   ↑               ↑\n  head            tail\n```\n\nList is implemented in the following structure:\n\n```go\ntype IntList struct {\n  head *int\n  tail *IntList\n}\n```\n\n[[🠕]](#list0)\n\n#### Create list\n\n```go\n// Create list\n// O(n)\nfunc MkIntList(elements ...int) IntList\n\n// Construct list by prepend head\n// O(1)\nfunc (l IntList) Cons(e int) IntList\n```\n\nExample:\n\n```go\n// create list by factory\nvar l IntList = MkIntList(1,2,3,4,5)\n\n// create list from Nil\nl2 := NilInt.Cons(5).Cons(4).Cons(3).Cons(2).Cons(1)  // equals IntList(1,2,3,4,5)\n\n// create list from boxed (rich) types\nl3 := Int(10).Cons(20).Cons(30)               // List(30,20,10)\nl4 := String(\"one\").Cons(\"two\").Cons(\"three\") // List(\"three\", \"two\", \"one\")\n\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Copy\n\n```go\n// Copy references of elements to new list\n// O(n)\nfunc (l IntList) Copy() IntList\n```\n\nExample:\n\n```go\nl1 := MkIntList(1,2,3,4,5)\nl2 := l1.Copy()\n```\n\n[[🠕]](#list0)\n\n#### List.Count\n\n```go\n// Count elements which satisfy a predicate\n// O(1..n)\nfunc (l IntList) Count(predicate func(int) bool)\n```\n\nExample:\n\n```go\nl := MkIntList(1,2,3,4,5)\nl.Count(func(e int) bool { return e % 2 == 0})    // 2\nl.Count(EvenInt)                                  // 2\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Drops\n\n```go\n// Returns new list without n-first elements\n// O(1..n)\nfunc (l IntList) Drop(n int) IntList\n\n// Returns new list without n-last elements\n// O(1..n)\nfunc (l IntList) DropRight(n int) IntList\n\n// Returns new list without first elements which statisfy a predicate\n// O(1..n)\nfunc (l IntList) DropWhile(predicate func(int) bool) IntList\n```\n\nExample:\n\n```go\nl := MkIntList(10,20,30,40,50)\nres1 := l.Drop(2)                                 // IntList(30,40,50)\nres2 := l.DropRight(2)                            // IntList(10,20,30)\nres3 := l.DropWhile(func (e int) bool { e \u003c 40 }) // IntList(40,50)                      \n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Empty NonEmpty\n\n```go\n// Returns true if list is empty\n// O(n)\nfunc (l IntList) IsEmpty() bool\n\n// Returns true if list is not empty\n// O(n)\nfunc (l IntList) NonEmpty() bool\n```\n\nExample:\n\n```go\nl1 := MkIntList(1,2,3)\nres1 := l1.IsEmpty()      // false\nres2 := l1.NoEmpty()      // true\n\nl2 := MkIntList()    \nres3 := l2.IsEmpty()      // true\nres4 := l2.NonEmpty()     // fase\n\nres5 := NilInt.IsEmpty()  // true\nres6 := NilInt.NonEmpty() // false\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Equals\n\n```go\n// Returns true if both lists are equal\n// O(n)\nfunc (a IntLIst) Equals(b IntList) bool\n```\n\nExample:\n\n```go\n// compare the simple lists\nl1 := MkIntList(10,20,30,40,50)\nl2 := MkIntList(10,20,30,40,50)\nl3 := MkIntList({10,20,30)\n\nl1.Equals(l2)   // true\nl1.Equals(l3)   // false\n                   \n// compare the nested lists\nl4 := MkIntListList(MkIntList(1,2), MkIntList(3,4,5))           \nl5 := MkIntListList(MkIntList(1,2), MkIntList(3,4,5)) \nl6 := MkIntListList(MkIntList(1,2,3), MkIntList(4,5))           \n                 \nl4.Equals(l5)  // true\nl4.Equals(l6)  // false\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Filter\n\n```go\n// Returns new list with elements which statisfy a predicate\n// O(n)\nfunc (l IntList) Filter(predicate func(int) bool) IntList\n```\n\nExample:\n\n```go\nl := MkIntList(1,-2,-3,4,5,-6,7,8,-9,10)\nres := l.\n         Filter(func (e int) bool { return e % 2 == 0}).   // filter even numbers\n         Filter(func (e int) bool { return e \u003e= 0 })       // filter positive numbers\n\nfmt.Println(res.ToString())    // IntList(4, 8, 10)\n\nres2 := l.Filter(EvenInt).Filter(PosInt)                   // use library predicates O(n)\nres3 := l.Filter(EvenInt.And(PosInt))                      // compose predicates     O(n)\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Find\n\n```go\n// Returns first element which statisfy a predicate\n// O(1..n)\nfunc (l IntList) Find(predicate func(int) bool)\n```\n\nExample:\n\n```go\nl := IntList(1,2,3,4,5,6)\n\nvar res1 IntOption = l.Find(func(e int) bool { return e == 3 }) // Some(3)\nvar res2 IntOption = l.Find(EvenInt)                            // Some(2)\nvar res3 IntOption = l.Find(NegInt)                             // None\n\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.FlatMap\n\n```go\n// FlatMap gives the ability to chain operations together\nfunc (l IntList) FlatMap\u003cType\u003e(f func(int) \u003cType\u003eList) \u003cType\u003eList\n\n// examples\nfunc (l IntList) FlatMapInt(f func(int) IntList) IntList\nfunc (l IntList) FlatMapString(f func(int) StringList) StringList\n...\n```\n\nExample:\n\n```go\n// Example: flatten nested list\n// List(List(1,2), Nil, List(3,4,5), List(6,7))\nl := MkIntListList(MkIntList(1,2), NilInt, MkIntList(3,4,5), MkIntList(6,7)) \nl.FlatMapInt(func(e IntList) IntList { return e })        // List(1,2,3,4,5,6,7)\nl.FlatMapInt(func(e IntList) IntList { \n    return e.MapInt(func(e int) int) { return e * 10 }})  // List(10,20,30,40,50,60,70)\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Flatten\n\n```go\n// Collapse the nested elements of a collection to flat collection\nfunc (l \u003cType\u003eListList) Flatten() \u003cType\u003eList\nfunc (l \u003cType\u003eOptionList) Flatten() \u003cType\u003eList\n\n// examples\nfunc (l IntIntList) Flatten() IntList\nfunc (l IntOptionList) Flatten() IntList\n```\n\nExample:\n\n```go\n// List(List(1,2,3), Nil, List(4,5), List(6,7))\nl := MkIntListList(MkIntList(1,2,3), Nil, MkIntList(4,5), MkIntList(6, 7))\nvar res IntList = l.Flatten()   // List(1,2,3,4,5,6,7)\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.FoldLeft\n\n```go\n// Applies binary function to each element of list going left to right\n// O(n)\n// z - initial value\nfunc (l IntList) FoldLeft\u003cType\u003e(z \u003cType\u003e, func(\u003cType\u003e, int) \u003cType\u003e) \u003cType\u003e\n\n// examples\nfunc (l IntList) FoldLeftInt(z Int, func(int, int) int) int\nfunc (l IntList) FoldLeftString(z string, func(string, int) string) string\n\n```\n\nExample:\n\n```go\nl := MkIntList(1,2,3,4,5)\n\n\nsum := l.FoldLeftInt(\n          0, \n          func(acc, el) int { return acc + el})   // sum = (((((0 + 1) + 2) + 3) + 4) + 5)\n\nstr := l.FoldLeftString(\n          \"\u003e\", \n          func(acc, el) string { return fmt.Sprintf(\"%v|%v\", acc, el)}) // \u003e1|2|3|4|5\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Foreach\n\n```go\n// Iterate over elements\n// O(n)\nfunc (l IntList) Foreach(func(int))\n```\n\nExample:\n\n```go\nl := MkIntList(1,2,3)\nf.Foreach(func(e int) {\n    fmt.Println(\"\u003e \", e)\n})\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.GroupBy\n\n```go\n// Partitions this list into a map of according to some discriminator function\nfunc (l \u003cA\u003eList) GroupBy\u003cK\u003e(func(\u003cA\u003e)\u003cK\u003e) map[\u003cK\u003e]\u003cA\u003eList\n\n// examples\nfunc (l IntList) GroupByInt(func(int) int) map[int]IntList\nfunc (l AnyList) GroupByAny(func(Any)Any) map[Any]AnyList\n```\n\nExample: group by identity\n\n```go\nl1 := MkIntList(1,2,1,1,3,2)\nres1 := l1.GroupByInt(func(e int) int { return e }) /* Map(1 -\u003e List(1,1,1)\n                                                           2 -\u003e List(2,2)\n                                                           3 -\u003e List(3))  */\nres2 := l1.GroutByInt(IntIdentity)                  // the same as res1\n```\n\nExample: group by different attributes\n\n```go\ntype Shape struct {\n  name  string\n  color string\n  area  int\n}\n\nshapes := NilAny.\n  Cons(Shape{\"circle\", \"green\", 10}).\n  Cons(Shape{\"triangle\", \"yellow\", 30}).\n  Cons(Shape{\"polygon\", \"green\", 10}).\n  Cons(Shape{\"triangle\", \"green\", 10}).\n  Cons(Shape{\"circle\", \"red\", 20}).  \n  Cons(Shape{\"polygon\", \"red\", 20}).\n  Cons(Shape{\"circle\", \"yellow\", 30}).\n  Cons(Shape{\"triangle\", \"red\", 20}).\n  Cons(Shape{\"polygon\", \"yellow\", 30})\n\n// Group shapes by name\nbyShape := func(e Any) Any { return e.(Shape).name }\nres1 := shapes.GroupByAny(byShape)\n/*\n Map(\n   \"polygon\"  -\u003e List({\"polygon\" \"green\" 10}, {\"polygon\" \"red\" 20}, {\"polygon\" \"yellow\" 30})\n   \"triangle\" -\u003e List({\"triangle\" \"green\" 10}, {\"triangle\" \"red\" 20}, {\"triangle\" \"yellow\" 30})\n   \"circle\"   -\u003e List({\"circle\" \"green\" 10}, {\"circle\" \"red\" 20}, {\"circle\" \"yellow\" 30})\n )\n */\n\n// Group shapes by color\nbyColor := func(e Any) Any { return e.(Shape).color }\nres2 := shapes.GroupByAny(byColor)\n/*\n Map(\n   \"yellow\" -\u003e List({\"circle\" \"yellow\" 30}, {\"triangle\" \"yellow\" 30}, {\"polygon\" \"yellow\" 30})\n   \"red\"    -\u003e List({\"circle\" \"red\" 20}, {\"triangle\" \"red\" 20}, {\"polygon\" \"red\" 20})\n   \"green\"  -\u003e List({\"circle\" \"green\" 10}, {\"triangle\" \"green\" 10}, {\"polygon\" \"green\" 10})\n )\n*/\n\nbyArea := func(e Any) Any { return e.(Shape).area }\nres3 := shapes.GroupByAny(byArea)\n/*\n Map (\n   30 -\u003e List({\"circle\" \"yellow\" 30}, {\"triangle\" \"yellow\" 30}, {\"polygon\" \"yellow\" 30})\n   20 -\u003e List({\"circle\" \"red\" 20}, {\"triangle\" \"red\" 20}, {\"polygon\" \"red\" 20})\n   10 -\u003e List({\"circle\" \"green\" 10}, {\"triangle\" \"green\" 10}, {\"polygon\" \"green\" 10})\n )\n*/\n```\n[[🠕]](#list0)\n\n\n\n#### List.Heads and tails\n\n```go\n// Returns head of list or throws exeption if list is empty\n// O(1)\nfunc (l IntList) Head() int\n\n// Returns optional head from list\n// O(1)\nfunc (l IntList) HeadOption() IntOption\n\n// Returns tail as list without first element\n// O(1)\nfunc (l IntList) Tail() IntList\n```\n\nExample:\n\n```go\nl := MkIntList(1,2,3)\nh1 := l.Head()                      // 1\nt1 := l.Tail()                      // List(2,3)\nh1Opt := l.HeadOption()             // Some(1)\nh2Opt := l.Tail().Tail().Tail()     // NoneInt\nl.Tail().Tail().Tail().Head()       // panic(\"there is no heads\")\n```\n\n[[🠕]](#list0)\n\n\n\n\n#### List.Map\n\n```go\n// Transform each element of list to other type\n// O(n)\nfunc (l IntList) Map\u003cType\u003e(func (int) \u003cType\u003e) \u003cType\u003eList\n\n// examples\nfunc(l IntList) MapInt(func (int) int) IntList\nfunc(l IntList) MapString(func (int) string) StringList\n\n```\n\nExample:\n\n```go\nl := MkIntList(1,2,3)\nr1 := l.MapInt(func(e int) int { return e * 10})                        // List(10,20,30)\nr2 := l.MapString(func (e int) string { return fmt.Sprintf(\"\u003c%v\u003e\", e)}) // List(\"\u003c1\u003e\",\"\u003c2\u003e\",\"\u003c3\u003e\")\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.MkString\n\n```go\n// Make string representation of that list with decorated elements and separator\n// O(n)\nfunc (l IntList) MkString(start, sep, end string) string\n```\n\nExample:\n\n```go\nl := MkIntList(1,2,3)\nstr := l.MkString(\"\u003c\", \"|\", \"\u003e\")      // \"\u003c1|2|3\u003e\"\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Nil\n\n```go\n// Empty list, can be used as initial tail before creating\nvar Nil\u003cType\u003e \u003cType\u003eList\n\n// examples\nvar NilInt IntList = ...\nvar NilString StringList = ...\n...\n```\n\nExample:\n\n```go\n// create list from empty tail\nl := NilInt.Cons(3).Cons(2).Cons(1)   // List(1,2,3)\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Cons\n\n```go\n// Create new list with new head and tail as current list\n// O(1)\nfunc (l IntList) Cons(e int) IntList\n```\n\nExample:\n\n```go\n// create list from empty tail\nl1 := NilInt.Cons(3).Cons(2).Cons(1)   // List(1,2,3)\n\nl2 := MkIntList(1,2,3)\nl3 := l2.Cons(4)                       // List(4,1,2,3)\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Reduce\n\n```go\n// Reduces elements of list using associative binary operator\n// O(n)\nfunc (l IntList) Reduce(func (int, int) int) int\n```\n\nExample:\n\n```go\nl := MkIntList(1,2,3)\nsum := l.Reduce(func(acc, el int) int { return acc + el })  // sum = 1 + 2 + 3\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Reverse\n\n```go\n// Reverse order of list elements\n// O(n)\nfunc (l IntList) Reverse() IntList\n```\n\nExample:\n\n```go\nl1 := MkIntList(1,2,3)\nl2 := l1.Reverse()                       // List(3,2,1)\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Size\n\n```go\n// Count elements of list\n// O(n)\nfunc (l IntList) Size() int\n```\n\nExample:\n\n```go\nl1 := MkIntList(1,2,3)\nl2 := MkIntList()\n\nres1 := l1.Size()         // 3\nres2 := l2.Size()         // 0\nres3 := NilInt            // 0\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.Takes\n\n```go\n// Returns first n-elements\n// O(1..n)\nfunc (l IntList) Take(n int) IntList\n\n// Returns last n-elements\n// O(1..n)\nfunc (l IntList) TakeRight(n int) IntList\n\n// Returns first elements which statisfy a predicate\n// O(1..n)\nfunc (l IntList) TakeWhile(func(int) bool) IntList\n```\n\nExample:\n\n```go\nl := IntList(10,20,30,40,50)\nres1 := l.Take(2)                                 // List(10,20)\nres2 := l.TakeRight(2)                            // List(40,50)\nres3 := l.TakeWhile(func (e int) bool { e \u003c 40})  // List(10,20,30)\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.ToArray\n\n```go\n// Returns elements of list as array\n// O(n)\nfunc (l IntList) ToArray() []int\n```\n\nExample:\n\n```go\nl := MkIntList(1,2,3)\na := l.ToArray()          // []int{1,2,3}\n```\n\n[[🠕]](#list0)\n\n\n\n#### List.ToString\n\n```go\n// Transform list to string\nfunc (l IntList) ToString() string\n```\n\nExample:\n\n```go\nl1 := MkIntList(1,2,3)\nres1 := l1.ToString()                                              // \"List(1,2,3)\"\nl2 := MkIntListList(\n        MkIntList(1,2), \n        NilInt, \n        MkIntList(3,4))  // \"List(List(1,2), List(), List(3,4))\"\n```\n\n[[🠕]](#list0)\n\n\n#### List.Zip\n```go\n// Returns a collection of combined corresponding elements in pairs\n// Resulting list will have min-length of input collections\nfunc (l IntList) ZipIntList(l2 IntList) Tuple2List\nfunc (l IntList) ZipStringList(l2 StirngList) Tuple2List\n...\n```\nExample:\n```go\nl1 := MkIntList(1,2,3)\nl2 := MkStringList(\"a\", \"b\", \"c\")\n\nres1 := l1.ZipStringList(l2)  \n/* List(Tuple(1, \"a\"), \n        Tuple(2, \"b\"), \n        Tuple(3, \"b\")) */\n                                   \nres2 := l1.ZipStringList(MkStringList(\"a\", \"b\"))\n/* List(Tuple(1, \"a\"), \n        Tuple(2, \"b\")) */\n\nres3 := l1.ZipStringList(MkStringList(\"a\", \"b\", \"c\", \"d\", \"e\"))\n/* List(Tuple(1, \"a\"), \n        Tuple(2, \"b\"), \n        Tuple(3, \"b\")) */\n```\n[[🠕]](#list0)\n\n#### List.ZipAll\n```go\n// Returns a collection of combined corresponding elements in pairs\n// Resulting list will have max-length of input collections\n// If one of corresponding element isn't found then default value will be used\nfunc (l IntList) ZipAllIntList(l2 IntList, \n                               thisDefault Int, \n                               thatDefault Int) Tuple2List\nfunc (l IntList) ZipAllStringList(l2 StringList, \n                                  thisDefault Int, \n                                  thatDefault string) Tuple2List\n...\n```\nExample:\n```go\nl1 := MkIntList(1,2,3)\nl2 := MkStringList(\"a\", \"b\", \"c\")\nl1Default := -100\nl2Default := \"NONE\"\n\nres1 := l1.ZipAllStringList(l2, l1Default, l2Default)  \n/* List(Tuple(1, \"a\"), \n        Tuple(2, \"b\"), \n        Tuple(3, \"b\")) */\n                                   \nres2 := l1.ZipAllStringList(MkStringList(\"a\", \"b\"), \n                            l1Default, \n                            l2Default)\n/* List(Tuple(1, \"a\"), \n        Tuple(2, \"b\"),\n        Tuple(3, \"NONE\")) */\n\nres3 := l1.ZipStringLitst(MkStringList(\"a\", \"b\", \"c\", \"d\", \"e\"),\n                          l1Default,\n                          l2Default)\n/* List(Tuple(1, \"a\"), \n        Tuple(2, \"b\"), \n        Tuple(3, \"b\"),\n        Tuple(-100, \"d\"),\n        Tuple(-100, \"e\")) */\n```\n[[🠕]](#list0)\n\n#### List.ZipWithIndex\n```go\n// Returns list of tuples which contains corresponding elements and its index\nfunc (l IntList) ZipWithIndex() Tuple2List\n...\n```\nExample:\n```go\nl1 := MkIntList(1024, 2048, 4096)\nres1 := l1.ZipWithIndex()\n/* List(Tuple(1024, 0),\n        Tuple(2048, 1),\n        Tuple(4096, 2))*/\n        \nl2 := MkStringList(\"a\", \"b\", \"c\")\nres2 := l2.ZipWithIndex()\n/* List(Tuple(\"a\", 0),\n        Tuple(\"b\", 1),\n        Tuple(\"c\", 2))*/\n```\n[[🠕]](#list0)\n\n\n#### Supported list types\n\n\u003cdetails\u003e\u003csummary\u003eSupported list types (click to expand)\u003c/summary\u003e\n\n| Array type        | Scala analogue        | Go analogue |\n| ----------------- | --------------------- | ----------- |\n| BoolList          | List[Boolean]         |             |\n| StringList        | List[String]          |             |\n| IntList           | List[Int]             |             |\n| Int64List         | List[Long]            |             |\n| ByteList          | List[Byte]            |             |\n| RuneList          | List[Char]            |             |\n| Float32List       | List[Float]           |             |\n| Float64List       | List[Double]          |             |\n| AnyList           | List[Any]             |             |\n| BoolArrayList     | List[Array[Bool]]     |             |\n| StringArrayList   | List[Array[String]]   |             |\n| IntArrayList      | List[Array[Int]]      |             |\n| Int64ArrayList    | List[Array[Long]]     |             |\n| ByteArrayList     | List[Array[Byte]]     |             |\n| RuneArrayList     | List[Array[Char]]     |             |\n| Float32ArrayList  | List[Array[Float]]    |             |\n| Float64ArrayList  | List[Array[Double]]   |             |\n| AnyArrayList      | List[Array[Any]]      |             |\n| BoolOptionList    | List[Option[Boolean]] |             |\n| StringOptionList  | List[Option[String]]  |             |\n| IntOptionList     | List[Option[Int]]     |             |\n| Int64OptionList   | List[Option[Long]]    |             |\n| ByteOptionList    | List[Option[Byte]]    |             |\n| RuneOptionList    | List[Option[Char]]    |             |\n| Float32OptionList | List[Option[Float]]   |             |\n| Float64OptionList | List[Option[Double]]  |             |\n| AnyOptionList     | List[Option[Any]]     |             |\n| BoolListList      | List[List[Boolean]]   |             |\n| StringListList    | List[List[String]]    |             |\n| IntListList       | List[List[Int]]       |             |\n| Int64ListList     | List[List[Long]]      |             |\n| ByteListList      | List[List[Byte]]      |             |\n| RuneListList      | List[List[Char]]      |             |\n| Float32ListList   | List[List[Float]]     |             |\n| Float64ListList   | List[List[Double]]    |             |\n| AnyListList       | List[List[Any]]       |             |\n\u003c/details\u003e\n\n[[🠕]](#list0)\n\n\n\n### Option\n\nAll examples of  this section use a `IntOption` type. But this API is supported in the other array types also. (See [Supported option types](#supported-option-types) section)\n\n#### Create option\n```go\nfunc MkIntOption(e int) IntOption\nfunc IntOpt(e int) IntOption\n```\nExample:\n```go\no1 := MkIntOption(10)     // Some(10)\no2 := IntOpt(20)            // Some(20)\n```\n[[🠕]](#option0)\n\n#### Option.Equals\n```go\n// Returns true if both options are equal\nfunc (a IntOption) Equals(b IntOption) bool\n```\nExample:\n```go\no1 := IntOpt(10)\no2 := IntOpt(20)\no3 := IntOpt(10)\n\no1.Equals(o2)            // false\no1.Equals(o3)            // true\no1.Equals(NoneInt)       // false\nNoneInt.Equals(NoneInt)  // true\n```\n[[🠕]](#option0)\n\n\n#### Option.Filter\n```go\n// Filter content of option by predicate\nfunc (o IntOption) Filter(predicate func(int)bool) IntOption\n```\nExample:\n```go\no := IntOption(10)\nres1 := o.Filter(func(e int) bool { return e % 2 == 0})  // Some(10)\nres2 := o.Filter(EvenInt)                                // Some(10)\nres3 := o.Filter(func(e int) bool { return e == 20 })    // None\nres4 := o.Filter(NegInt)                                 // None\n```\n[[🠕]](#option0)\n\n\n#### Option.FlatMap\n```go\n// FlatMap gives the ability to chain operations together\nfunc (o IntOption) FlatMap\u003cType\u003e(f func(int) \u003cType\u003eOption) \u003cType\u003eOption\n\n// examples\nfunc (o IntOption) FlatMapInt(f func(int) IntOption) IntOption\nfunc (o IntOption) FlatMapString(f func(int) StringOption) StringOption\n...\n```\nExample:\n```go\n// Task: calculate the sum of elements\n//       if all elements are defined then the sum will be defined too\n//       if one or more elements are not defined then the sum will not be defined too\n\n// implementation of the task\nsumFunc := func(a, b, c IntOption) IntOption {\n    sum := a.FlatMapInt(func (av int) IntOption {\n        return b.FlatMapInt(func bv int) IntOption {\n            return c.MapInt(func cv int) IntOption {\n                return av + bv + cv\n            } \n        }\n    })\n    return sum\n}\n\n// Case when a, b, c are defined\na := IntOpt(10)\nb := IntOpt(20)\nc := IntOpt(30)\n\nsumFunc(a, b, c)                                          // Some(60)\n\n\n// Cases when one or more of a, b, c are not defined\nsumFunc(IntOpt(10), NoneInt, IntOpt(30))                  // None\nsumFunc(IntOpt(10), IntOpt(20), NoneInt)                  // None\nsumFunc(NoneInt, IntOpt(20), IntOpt(30))                  // None\nsumFunc(NoneInt, NoneInt, IntOpt(30))                     // None\n...\n```\n[[🠕]](#option0)\n\n\n#### Option.Flatten\n```go \n// Collapse the nested option to flat option\nfunc (o IntIntOption) IntOption\n```\nExample:\n```go\no := MkIntOptionOption(MkIntOption(10))    // Some(Some(10))\nflatten := o.Flatten()                         // Some(10)\n```\n[[🠕]](#option0)\n\n\n#### Option.FoldLeft\n```go\n// Applies binary function to element of option\n// z - initial value\nfunc (l IntOption) FoldLeft\u003cType\u003e(z \u003cType\u003e, func(\u003cType\u003e, int) \u003cType\u003e) \u003cType\u003e\n\n// examples\nfunc (l IntOption) FoldLeftInt(z Int, func(int, int) int) int\nfunc (l IntOption) FoldLeftString(z string, func(string, int) string) string\n...\n```\nExample:\n```go\no := IntOpt(10)\nres1 := l.FoldLeftInt(\n            0, \n            func(acc, el) int { return acc + el})   // sum = 0 + 10\n```\n[[🠕]](#option0)\n\n\n#### Option.Foreach\n```go\n// Iterate over content\nfunc (l IntOption) Foreach(func(int))\n```\nExample:\n```go\nl := IntOpt(10)\nf.Foreach(func(e int) {\n    fmt.Println(\"\u003e \", e)\n})\n```\n[[🠕]](#option0)\n\n\n#### Option.IsDefined\n```go\n// Returns true if option contains a value\nfunc (o IntOption) IsDefined() bool\n```\nExample:\n```go\nIntOption(10).IsDefined()     // true\nNoneInt.IsDefined()           // false\n```\n[[🠕]](#option0)\n\n\n#### Option.IsEmpty\n```go\n// Returns true if option is not defined\nfunc (o IntOption) IsEmpty() bool\n```\nExample:\n```go\nNoneInt.IsEmpty()             // true\nIntOpt(10).IsEmpty()          // false\n```\n[[🠕]](#option0)\n\n\n#### Option.Map\n```go\n// Transform element of option to other type\nfunc (l IntOption) Map\u003cType\u003e(func (int) \u003cType\u003e) \u003cType\u003eOption\n\n// examples\nfunc(l IntOption) MapInt(func (int) int) IntOption\nfunc(l IntOption) MapString(func (int) string) StringOption\n```\nExample:\n```go\no := IntOpt(10)\nres1 := o.MapInt(func (e int) int { return e * 10 })                       // Some(100)\nres2 := o.MapString(func (e int) string { return fmt.Sprintf(\"\u003c%v\u003e\", e) }) // Some(\"\u003c10\u003e\") \n```\n[[🠕]](#option0)\n\n#### Option.None\n\nThere are empty option constants for each supported optional type\n\n```go\nvar NoneInt IntOption = ...\nvar NoneString IntOption = ...\n...\n```\nExample:\n```go\no1 := NoneInt            // None\no2 := NoneString         // None\n\nfunc parseIp(str string) StringOption {\n    if str != \"\" { \n        return StringOpt(str) \n    } else {\n        return NoneString\n    } \n}\n\nip1 := parseIp(\"\")           // None\nip2 := parseIp(\"127.0.0.1\")  // Some(\"127.0.0.1\")\n```\n[[🠕]](#option0)\n\n\n#### Option.ToString\n```go\n// Transform option to string\nfunc (o IntOption) string\n```\nExample:\n```go\nvar o1 IntOption = IntOption(10)\nvar o2 IntOption = NoneInt\n\nvar str1 string = o1.ToString()      // \"Some(10)\"\nvar str2 string = o2.TOString()      // \"None\"\n```\n[[🠕]](#option0)\n\n#### Supported option types\n\u003cdetails\u003e\u003csummary\u003eSupported option types (click to expand)\u003c/summary\u003e\n\n| Option type         | Scala analogue          |\n| ------------------- | ----------------------- |\n| BoolOption          | Option[Boolean]         |\n| StringOption        | Option[String]          |\n| IntOption           | Option[Int]             |\n| Int64Option         | Option[Long]            |\n| ByteOption          | Option[Byte]            |\n| RuneOption          | Option[Char]            |\n| Float32Option       | Option[Float]           |\n| Float64Option       | Option[Double]          |\n| AnyOption           | Option[Any]             |\n| BoolOptionOption    | Option[Option[Boolean]] |\n| StringOptionOption  | Option[Option[String]]  |\n| IntOptionOption     | Option[Option[Int]]     |\n| Int64OptionOption   | Option[Option[Long]]    |\n| ByteOptionOption    | Option[Option[Byte]]    |\n| RuneOptionOption    | Option[Option[Char]]    |\n| Float32OptionOption | Option[Option[Float]]   |\n| AnyOptionOption     | Option[Option[Double]]  |\n| BoolArrayOption     | Option[Array[Boolean]]  |\n| StringArrayOption   | Option[Array[String]]   |\n| IntArrayOption      | Option[Array[Int]]      |\n| Int64ArrayOption    | Option[Array[Long]]     |\n| ByteArrayOption     | Option[Array[Byte]]     |\n| RuneArrayOption     | Option[Array[Char]]     |\n| Float32ArrayOption  | Option[Array[Float]]    |\n| Float64ArrayOption  | Option[Array[Double]]   |\n| AnyArrayOption      | Option[Array[Any]]      |\n| BoolListOption      | Option[List[Boolean]]   |\n| StringListOption    | Option[List[String]]    |\n| IntListOption       | Option[List[Int]]       |\n| Int64ListOption     | Option[List[Long]]      |\n| ByteListOption      | Option[List[Byte]]      |\n| RuneListOption      | Option[List[Char]]      |\n| Float32ListOption   | Option[List[Float]]     |\n| Float64ListOption   | Option[List[Double]]    |\n| AnyListOption       | Option[List[Any]]       |\n\u003c/details\u003e\n\n[[🠕]](#option0)\n\n### Tuple2\n`Tuple2` is just a pair of two elements any types. Tuples are used in the `Zip` operations under collections, for example (see [List.Zip](#listzip), [Array.Zip](#arrayzip) sections).\n[[🠕]](#tuple20)\n\n#### Create tuple2\nExample:\n```go\nt1 := Tuple2 {10, \"hello\" }  // Tuple(10, \"Hello\")\n\n// accessing to tuple's fields\nvar t1_e1 Any = t1.E1           // Any(10)\nvar t2_e2 Any = t2.E2           // Any(\"Hello\")\n\nt2 := Tuple2 {t1, MkIntList(1,2,3)} \n/* Tuple(Tuple(10, \"hello\"), List(1,2,3)) */\n\nvar t2_e1 Any = t2.E1   // Any(Tuple(10, \"hello\"))\nvar t2_e2 Any = t2.E2   // Any(List(1,2,3))\n\n```\n[[🠕]](#tuple20)\n\n#### Tuple2.Equals\n```go\n// Deep equality of two tuples\nfunc (a Tuple2) Equals(b Tuple2) bool\n```\nExample:\n```go\nt1 := Tuple2 {10, \"hello\" }\nt2 := Tuple2 {10, \"hello\" }\nt3 := Tuple2 {t1, MkIntList(1,2,3) }\nt4 := Tuple2 {t1, MkIntList(1,2,3) }\n\nt1.Equals(t2)                // true\nt1.Equals(t3)                // false\nt3.Equals(t4)                // true\n```\n[[🠕]](#tuple20)\n\n#### Tuple2.ToString\n```go\n// Transform tuple to string representation\nfunc (t Tuple2) ToString String\n```\nExample:\n```go\nt1 := Tuple2 {10, \"hello\"}\nt1.ToString()       // \"Tuple(10, hello)\"\n\nt2 := Tuple2 { t1, MkIntList(1,2,3) }\nt2.ToString()       // \"Tuple(Tuple(10, hello), List(1,2,3))\" \n\n```\n[[🠕]](#tuple20)\n\n\n### Array\n\nArray is just wrapper for go-arrays which contains convenient functions. All examples of  this section use a `IntArray` type. But this API is supported in the other array types also. (See [Supported array types](#supported-array-types) section)\nWarning, current implementation of the array wrapper is mutable data structure.\n\n\n\n#### Create array\n```go\ntype IntArray []int\n```\nExample:\n```go\narr := IntArray([]int{10, 20, 30})\n```\n[[🠕]](#array0)\n\n\n#### Array.Count\n\n```go\n// Returns count of elements which satisfy a predicate\n// O(n)\nfunc (a IntArray) Count(predicate func(int) bool) int\n```\nExample:\n```go\narr := IntArray([]int{1,2,3,4,5})\narr.Count(func (e int) bool { return e % 2 == 0})         // 2\narr.Count(EvenInt)                                        // 2\narr.Count(PosInt)                                         // 5\narr.Count(NegInt)                                         // 0\n```\n[[🠕]](#array0)\n\n\n#### Array.Drops\n\n```go\n// Returns new array without n-first elements\n// O(1..n)\nfunc (a IntArray) Drop(n int) IntArray\n\n// Returns new array without n-last elements\n// O(1..n)\nfunc (a IntArray) DropRight(n int) IntArray\n\n// Returns new array without first elements which statisfy a predicate\n// O(1..n)\nfunc (a IntArray) DropWhile(predicate func(int) bool) IntArray\n```\n\nExample:\n\n```go\narr := IntArray([]int{10,20,30,40,50})\nres1 := arr.Drop(2)                                 // Array(30,40,50)\nres2 := arr.DropRight(2)                            // Array(10,20,30)\nres3 := arr.DropWhile(func (e int) bool { e \u003c 40 }) // Array(40,50)\n```\n[[🠕]](#array0)\n\n\n#### Array.Equals\n\n```go\n// Returns true if both arrays are equal\n// O(n)\nfunc (a IntArray) Equals(b IntArray) bool\n```\n\nExample:\n\n```go\narr1 := IntArray([]int{10,20,30,40,50})\narr2 := IntArray([]int{10,20,30,40,50})\narr3 := IntArray([]int{10,20,30})\n\narr1.Equals(arr2)   // true\narr1.Equals(arr3)   // false\n```\n[[🠕]](#array0)\n\n\n\n#### Array.Filter\n\n```go\n// Returns new array with elements which statisfy a predicate\n// O(n)\nfunc (a IntArray) Filter(predicate func(int) bool) IntArray\n```\n\nExample:\n\n```go\narr := IntArray([]int {1,-2,-3,4,5,-6,7,8,-9,10})\nres := arr.\n         Filter(func (e int) bool { return e % 2 == 0}).   // filter even numbers\n         Filter(func (e int) bool { return e \u003e= 0 })       // filter positive numbers\n\nfmt.Println(res.ToString())    // [4, 8, 10]\n\nres2 := arr.Filter(EvenInt).Filter(PosInt)                 // use library predicates\nres3 := arr.Filter(EvenInt.And(PosInt))                    // compose predicates\n\n```\n[[🠕]](#array0)\n\n\n\n#### Array.Find\n\n```go\n// Returns first element which statisfy a predicate\n// O(1..n)\nfunc (a IntArray) Find(predicate func(int) bool) IntOption\n```\n\nExample:\n\n```go\narr := IntArray([]int {1,2,3,4,5,6})\n\nvar res1 IntOption = arr.Find(func(e int) bool { return e == 3 }) // Some(3)\nvar res2 IntOption = arr.Find(EvenInt)                            // Some(2)\nvar res3 IntOption = arr.Find(NegInt)                             // None\n```\n[[🠕]](#array0)\n\n\n\n#### Array.Foreach\n\n```go\n// Applies function `f` to each element of array. \n// O(n)\nfunc (a IntArray) Foreach(f func(int))\n```\nExample:\n\n```go\narr := IntArray([]int{10, 20, 30})\n\n// functional stype\narr.Foreach(func (e int) {              \n    fmt.Println(e)           // print each element\n})\n\n// functional style (shortest)\narr.Foreach(PrintlnInt)\n\n// imperative style\nfor _, e := range arr {\n    fmt.Println(e)\n}\n```\n[[🠕]](#array0)\n\n\n#### Array.Heads and tails\n\n```go\n// Returns head of array or throws exeption if array is empty\n// O(1)\nfunc (a IntArray) Head() int\n\n// Returns optional head from array\n// O(1)\nfunc (a IntArray) HeadOption() IntOption\n\n// Returns array without first element\n// O(c)\nfunc (a IntArray) Tail() IntArray\n```\nExample:\n```go\narr := IntArray([]int{10, 20, 30})\n\nvar h = arr.Head()                      // 10\nvar hopt IntOption = arr.HeadOption()   // Some(10)\nvar tail IntArray = arr.Tail()          // IntArray(20, 30)\nvar tail2 = tail.Tail()                 // IntArray(30)\nvar tail3 = tail2.Tail()                // empty array\n\nvar hopt3 = tail3.HeadOption()          // NoneInt\ntail3.Head()                            // panic(\"there is no heads\")\n```\n[[🠕]](#array0)\n\n\n#### Array.Map\n\n```go\n// Transform each element of array to new element\n// O(n)\nfunc (a IntArray) Map\u003cType\u003e(transformer func(int) \u003cType\u003e) \u003cType\u003eArray\n\nfunc (a IntArray) MapInt(transformer func(int) int) IntArray\nfunc (a IntArray) MapString(transformer func(int) string) StringArray\n...\n```\n\nExample:\n\n```go\narr := IntArray([]int{10, 20, 30})\n\nvar res StringArray = arr.\n                        MapInt(func(e int) int { return e * 10 }).\n                        MapString(func (e int) string) { return fmt.Sprintf(\"~%v~\", e) }\n\nres.Foreach(PrintString)\n```\n\n```\nOutput:\n~100~\n~200~\n~300~\n```\n[[🠕]](#array0)\n\n\n\n#### Array.MkString\n\n```go\n// Make string representation of that array with decorated elements and separator\n// O(n)\nfunc (a IntArray) MkString(start, sep, end string) string\n```\n\nExample:\n\n```go\narr := IntArray([]int{1,2,3})\nfmt.Println(arr.MkString(\"(\", \"|\", \")\"))  // (1|2|3)\n```\n[[🠕]](#array0)\n\n\n\n#### Array.takes\n\n```go\n// Returns first n-elements\n// O(1..n)\nfunc (a IntArray) Take(n int) IntArray\n\n// Returns last n-elements\n// O(1..n)\nfunc (a IntArray) TakeRight(n int) IntArray\n\n// Returns first elements which statisfy a predicate\n// O(1..n)\nfunc (a IntArray) TakeWhile(predicate func(int) bool) IntArray\n```\n\nExample:\n\n```go\narr := IntArray([]int{10,20,30,40,50})\nres1 := arr.Take(2)                                 // Array(10,20)\nres2 := arr.TakeRight(2)                            // Array(40,50)\nres3 := arr.TakeWhile(func (e int) bool { e \u003c 40})  // Array(10,20,30)\n```\n[[🠕]](#array0)\n\n\n\n#### Array.ToList\n\n```go\n// Transform array to recursive functional data structure\n// O(n)\nfunc (a IntArray) ToList() IntList\n```\n\nExample:\n\n```go\narr := IntArray([]int{1,2,3})\nvar l IntList = arr.ToList()\n```\n[[🠕]](#array0)\n\n\n#### Array.ToString\n\n```go\n// Make string representation of that array\n// O(n)\nfunc (a IntArray) ToString() string\n```\n\nExample:\n\n```go\narr := IntArray([]int{1,2,3})\nfmt.Println(arr.ToString())                        // [1,2,3]\n\narr2 := IntIntArray([]int{1,2}, []int[]{3,4,5})\nfmt.Println(arr2.ToString())                       // [[1,2], [3,4,5]]          \n```\n[[🠕]](#array0)\n\n#### Array.Zip\n```go\n// Returns an array of combined corresponding elements in pairs\n// Resulting array will have min-length of input collections\nfunc (a IntArray) ZipIntArray(a2 IntArray) Tuple2Array\nfunc (a IntArray) ZipStrinArray(a2 StirngArray) Tuple2Array\n...\n```\nExample:\n```go\na1 := IntArray([]int{1,2,3})\na2 := StringArray([]string{\"a\", \"b\", \"c\"})\n\nres1 := a1.ZipStringArray(a2)  \n/* Array(Tuple(1, \"a\"), \n         Tuple(2, \"b\"), \n         Tuple(3, \"b\")) */\n                                   \nres2 := a1.ZipStringArray(StringArray([]string{\"a\", \"b\"}))\n/* Array(Tuple(1, \"a\"), \n         Tuple(2, \"b\")) */\n\nres3 := a1.ZipStringArray(StringArray([]string{\"a\", \"b\", \"c\", \"d\", \"e\"}))\n/* Array(Tuple(1, \"a\"), \n         Tuple(2, \"b\"), \n         Tuple(3, \"b\")) */\n```\n[[🠕]](#array0)\n\n#### Array.ZipAll\n```go\n// Returns an array of combined corresponding elements in pairs\n// Resulting array will have max-length of input collections\n// If one of corresponding element isn't found then default value will be used\nfunc (a IntArray) ZipAllIntArray(a2 IntArray, \n                                 thisDefault Int, \n                                 thatDefault Int) Tuple2Array\nfunc (a IntArray) ZipAllStringList(a2 StringArray, \n                                   thisDefault Int, \n                                   thatDefault string) Tuple2Array\n...\n```\nExample:\n```go\na1 := IntArray([]int{1,2,3})\na2 := StringArray([]string{\"a\", \"b\", \"c\"})\nl1Default := -100\nl2Default := \"NONE\"\n\nres1 := a1.ZipAllStringArray(a2, l1Default, l2Default)  \n/* Array(Tuple(1, \"a\"), \n         Tuple(2, \"b\"), \n         Tuple(3, \"b\")) */\n                                   \nres2 := a1.ZipAllStringArray(StringArray([]string{\"a\", \"b\"}), \n                             l1Default, \n                             l2Default)\n/* Array(Tuple(1, \"a\"), \n         Tuple(2, \"b\"),\n         Tuple(3, \"NONE\")) */\n\nres3 := a1.ZipStringArray(StringArray([]string{\"a\", \"b\", \"c\", \"d\", \"e\"}),\n                          l1Default,\n                          l2Default)\n/* Array(Tuple(1, \"a\"), \n         Tuple(2, \"b\"), \n         Tuple(3, \"b\"),\n         Tuple(-100, \"d\"),\n         Tuple(-100, \"e\")) */\n```\n[[🠕]](#array0)\n\n#### Array.ZipWithIndex\n```go\n// Returns array of tuples which contains corresponding elements and its index\nfunc (a IntArray) ZipWithIndex() Tuple2Array\n...\n```\nExample:\n```go\na1 := IntArray([]int{1024, 2048, 4096})\nres1 := a1.ZipWithIndex()\n/* Array(Tuple(1024, 0),\n         Tuple(2048, 1),\n         Tuple(4096, 2))*/\n        \na2 := StringArray([]string{\"a\", \"b\", \"c\"})\nres2 := a2.ZipWithIndex()\n/* Array(Tuple(\"a\", 0),\n         Tuple(\"b\", 1),\n         Tuple(\"c\", 2))*/\n```\n[[🠕]](#array0)\n\n#### Supported array types\n\u003cdetails\u003e\u003csummary\u003eSupported array types (click to expand)\u003c/summary\u003e\n\n| Array type          | Scala analogue        | Go analogue   |\n| ------------------- | --------------------- | ------------- |\n| `BoolArray`         | Array[Bool]           | `[]bool`      |\n| `StringArray`       | Array[String]         | `[]string`    |\n| `IntArray`          | Array[Int]            | `[]int`       |\n| `Int64Array`        | Array[Long]           | `[]int64`     |\n| `ByteArray`         | Array[Byte]           | `[]byte`      |\n| `RuneArray`         | Array[Rune]           | `[]rune`      |\n| `Float32Array`      | Array[Float]          | `[]float32`   |\n| `Float64Array`      | Array[Long]           | `[]float64`   |\n| `AnyArray`          | Array[Any]            | `[]Any`       |\n| `BoolArrayArray`    | Array[Array[Boolean]] | `[][]bool`    |\n| `StringArrayArray`  | Array[Array[String]]  | `[][]string`  |\n| `IntArrayArray`     | Array[Array[Int]]     | `[][]int`     |\n| `Int64ArrayArray`   | Array[Array[Long]]    | `[][]int64`   |\n| `ByteArrayArray`    | Array[Array[Byte]]    | `[][]byte`    |\n| `RuneArrayArray`    | Array[Array[Char]]    | `[][]rune`    |\n| `Float32ArrayArray` | Array[Array[Float]]   | `[][]float32` |\n| `Float64ArrayArray` | Array[Array[Double]]  | `[][]float64` |\n| `AnyArrayArray`     | Array[Array[Any]]     | `[][]Any`     |\n\u003c/details\u003e\n\n[[🠕]](#array0)\n\n\n\n## Boxed types\nBoxed types are just wrappers under primitive go-types. These wrappers support additional operations which are desrcibed in this section.\n\n[[🠕]](#boxed0)\n\n### Underlined\n```go\n// Returns underlined value from boxed\nfunc (e Int) Underlined() int\nfunc (e String) Underlined() string\n...\n```\nExample:\n```go\nvar a Int = Int(10)   // explicit boxing\nvar b Int = 20        // implicit boxing\n\nvar v1 int = a.Underlined()   // returns underlined value 10\nvar v2 int = b.Underlined()   // returns underlined value 20\n\n```\n\n[[🠕]](#boxed0)\n\n\n### Converters\n\n#### String.ToArray\n```go\n// Converts string to array of runes (character codes)\nfunc (s String) ToArray() RuneArray\n```\nExample:\n```go\ns := String(\"Hello\")\narr := s.ToArray()      // RuneArray(72,101,108,108,111)\n```\n[[🠕]](#boxed0)\n\n#### String.ToLetterArray\n```go\n// Coverts string to letter array\nfunc (s String) ToLetterArray() StringArray\n```\nExample:\n```go\ns := String(\"Hello\")\narr := s.ToLetterArray()  // StringArray(\"H\", \"e\", \"l\", \"l\", \"o\")\n```\n[[🠕]](#boxed0)\n\n#### String.ToInt\n```go\n// Converts string to integer or throws exception for wrong format \nfunc (s String) ToInt Int\n```\nExample:\n```go\nvar n1 Int = String(\"10\").ToInt()     // Int(10)\nvar n2 Int = String(\"zz\").ToInt()     // panic(\"wrong format\")\n```\n[[🠕]](#boxed0)\n\n#### String.ToIntOption\n```go\n// Converts string to Some(int) for correct format and None for wrong format\nfunc (s String) ToIntOption() IntOption\n```\nExample:\n```go\nvar n1 IntOption = String(\"10\").ToIntOption()  // Some(10)\nvar n2 IntOption = String(\"zz\").ToIntOption()  // None\n```\n[[🠕]](#boxed0)\n\n### List constructors\n```go\n// Create list from two elements `a` and `b`\nfunc (a Int) Cons(b Int) IntList\nfunc (a String) Cons(b String) StringList\n...\n```\nExample:\n```go\nl1 := Int(10).Cons(20)                         // List(20, 10)\nl2 := String(\"one\").Cons(\"two\").Cons(\"three\")  // List(\"three\", \"two\", \"one\")\n```\n[[🠕]](#boxed0)\n\n### Range constructor\n\n#### To\n```go\n// Creates list with values from range from=n, to=t inclusive\nfunc (n Int) To(t Int) IntList\n```\nExample:\n```go\nl := Int(0).To(5)     // List(0,1,2,3,4,5)\n```\n[[🠕]](#boxed0)\n\n#### Until\n```go\n// Creates list with values from range from=n, to=(t-1)\nfunc (n Int) Until(t Int) IntList\n```\nExample:\n```go\nl := Int(0).To(5)     // List(0,1,2,3,4)\n```\n[[🠕]](#boxed0)\n\n### Math and logic operations\n\n#### IsBetween\n```go\n// check if a number is \u003e left and \u003c right (exclusive)\nfunc (a Int) IsBetween(left, right int) bool\n```\nExample:\n```go\nInt(10).IsBetween(9, 15)      // true\nInt(10).IsBetween(0, 5)       // false\nInt(10).IsBetween(10, 11)     // false\n```\n[[🠕]](#boxed0)\n\n#### IsBetweenInclusive\n```go\n// check if a number is \u003e= left and \u003c= right (inclusive)\nfunc (a Int) IsBetweenInclusive(left, right int) bool\n```\nExample:\n```go\nInt(10).IsBetween(10, 15)      // true\nInt(10).IsBetween(0, 5)        // false\n```\n[[🠕]](#boxed0)\n\n#### Min/Max numeric\n```go\n// Returns min value of `a` and `b`\nfunc (a Int) Min(b Int) Int\nfunc (a Byte) Min(b Byte) Byte\n...\n\n// Returns max value of `a` and `b`\nfunc (a Int) Max(b Int) Int\nfunc (a Byte) Max(b Byte) Byte\n...\n```\nExample:\n```go\nres1 := Int(10).Min(20)     // 10\nres2 := Int(10).Max(20)     // 20\n```\n[[🠕]](#boxed0)\n\n### Supported boxed types\n\u003cdetails\u003e\u003csummary\u003eSupported boxed types (click to expand)\u003c/summary\u003e\n\n| Boxed type | Go type      |\n| ---------- | ------------ |\n| Bool       | bool         |\n| String     | string       |\n| Int        | int          |\n| Int8       | int8         |\n| Int16      | int16        |\n| Int32      | int32        |\n| Int64      | int64        |\n| Uint       | uint         |\n| Uint16     | uint16       |\n| Uint32     | uint32       |\n| Uint64     | uint64       |\n| Uintptr    | uintptr      |\n| Byte       | byte         |\n| Rune       | rune         |\n| Float32    | float32      |\n| Float64    | float64      |\n| Complex64  | complex64    |\n| Complex128 | complex128   |\n| Any        | interface {} |\n\u003c/details\u003e\n\n[[🠕]](#boxed0)\n\n## Predicates\nPredicates are used as function's arguments in the following operations on monads: `Filter`, `Find`, `Count`, `Exist` ...\n[[🠕]](#predicates0)\n\n### Empty predicates\n```go\n// Always returns true for all input values\nvar EmptyIntPredicate IntPredicate = func(t int) bool { return true }\n...\n```\nExample:\n```go\n\nfunc getFilter() IntPredicate {\n  var filterType string = config.getProperty(\"filter\")\n  \n  if filterType == \"even\" {\n     return EvenInt  // func (e int) bool { return e % 2 == 0 }\n  } else if filterType == \"odd\" {\n     return OddInt   // func (e int) bool { return e % 2 != 0 }\n  } else {\n    return EmptyIntPredicate   // default filter is no-filter\n  }\n}\n\nl := MkIntList(1,2,3)\n\nres1 := l.Filter(getFilter())  // if config propery does not contain\n                               // filter type then filtering will not use\n\n```\n\n[[🠕]](#predicates0)\n\n### Numeric predicates\n```go\n// Check if number is even\nvar EvenInt IntPredicate = ...\nvar EvenInt64 Int64Predicate = ...\nvar EvenByte BytePredicate = ...\nvar EvenRune RunePredicate = ...\n\n// Check if number is odd\nvar OddInt IntPredicate = ...\n...\n\n// Check if number is negative\nvar NegInt IntPredicate = ...\n...\n\n// Check if number is positive\nvar PosInt IntPredicate = ...\n...\n\n// Check if number is zero\nvar ZeroInt IntPredicate = ...\n...\n\n// Check if number is equal to 1\nvar OneInt IntPredicate = ...\n...\n```\nExamples:\n```go\nl := MkIntList(1,2,-3,-4,5,6,-7,8,9,0)\n\nres1 := l.Filter(EvenInt)                // List(2,-4,6,8,0)\nres2 := l.Filter(NegInt)                 // List(-3,-4,-7)\nres3 := l.Filter(EvenInt).Filter(NegInt) // List(-4)\n```\n[[🠕]](#predicates0)\n\n### String predicates\n```go\n// Build string predicate which check if string is matched to regexp\nfunc MatchRegexp(r *regexp.Regexp) StringPredicate\n\n// Build string predicate which check if string is matched to pattern\nfunc MatchRegexpString(pattern string) StringPredicate\n```\nExamples:\n```go\nl := MkStringList(\"Hello\", \"abc\", \"127.0.0.1\", \"255.255.255.0\", \"world\", \"127\", \"255\")\n\nvar matchIp StringPredicate = \n        MatchRegexpString(\"[\\\\d]{1,3}\\\\.[\\\\d]{1,3}\\\\.[\\\\d]{1,3}\\\\.[\\\\d]{1,3}\")\n   \nipList := l.Filter(matchIp)           // List(\"127.0.0.1\", \"255.255.255.0\")\n\nvar onlyWords = MatchRegexpString(\"[a-zA-Z]+\")\nwords := l.Filter(onlyWords)          // List(\"Hello\", \"abc\", \"world\")\n```\n\n[[🠕]](#predicates0)\n\n### Predicates composition\n```go\n// Apply boolean operator to two predicates\nfunc (p1 IntPredicate) And(p2 IntPredicate) IntPredicate\nfunc (p1 IntPredicate) Or(p2 IntPredicate) IntPredicate\nfunc (p1 IntPredicate) Neg(p2 IntPredicate) IntPredicate\nfunc (p1 IntPredicate) Xor(p2 IntPredicate) IntPredicate\n...\n```\nExamples:\n```go\nl := MkIntList(1,-2,3,4,5,-6,7,8,9,0)\n\nvar p1 IntPredicate = func(e int) bool { return e % 2 == 0 }  // even numbers\nvar p2 IntPredicate = func(e int) bool { return e \u003c 0 }       // neg numbers\n\np3 := p1.And(p2)\n\nl.Filter(p3)     // List(-2,-6)\n\n```\n[[🠕]](#predicates0)\n\n### Supported predicate types\n\u003cdetails\u003e\u003csummary\u003eSupported predicate types (click to expand)\u003c/summary\u003e\n\n| Predicate type               |      |\n| ---------------------------- | ---- |\n| BoolPredicate                |      |\n| StringPredicate              |      |\n| IntPredicate                 |      |\n| Int64Predicate               |      |\n| BytePredicate                |      |\n| RunePredicate                |      |\n| Float32Predicate             |      |\n| Float64Predicate             |      |\n| AnyPredicate                 |      |\n| BoolArrayPredicate           |      |\n| StringArrayPredicate         |      |\n| IntArrayPredicate            |      |\n| Int64ArrayPredicate          |      |\n| ByteArrayPredicate           |      |\n| RuneArrayPredicate           |      |\n| Float32ArrayPredicate        |      |\n| Float64ArrayPredicate        |      |\n| AnyArrayPredicate            |      |\n| BoolArrayArrayPredicate      |      |\n| StringArrayArrayPredicate    |      |\n| IntArrayArrayPredicate       |      |\n| Int64ArrayArrayPredicate     |      |\n| ByteArrayArrayPredicate      |      |\n| RuneArrayArrayPredicate      |      |\n| Float32ArrayArrayPredicate   |      |\n| Float64ArrayArrayPredicate   |      |\n| AnyArrayArrayPredicate       |      |\n| BoolOptionPredicate          |      |\n| StringOptionPredicate        |      |\n| IntOptionPredicate           |      |\n| Int64OptionPredicate         |      |\n| ByteOptionPredicate          |      |\n| RuneOptionPredicate          |      |\n| Float64OptionPredicate       |      |\n| AnyOptionPredicate           |      |\n| BoolOptionOptionPredicate    |      |\n| StringOptionOptionPredicate  |      |\n| IntOptionOptionPredicate     |      |\n| Int64OptionOptionPredicate   |      |\n| RuneOptionOptionPredicate    |      |\n| Float32OptionOptionPredicate |      |\n| Float64OptionOptionPredicate |      |\n| AnyOptionOptionPredicate     |      |\n| BoolArrayOptionPredicate     |      |\n| StringArrayOptionPredicate   |      |\n| IntArrayOptionPredicate      |      |\n| Int64ArrayOptionPredicate    |      |\n| ByteArrayOptionPredicate     |      |\n| RuneArrayOptionPredicate     |      |\n| Float32ArrayOptionPredicate  |      |\n| Float64ArrayOptionPredicate  |      |\n| AnyArrayOptionPredicate      |      |\n| BoolListOptionPredicate      |      |\n| StringListOptionPredicate    |      |\n| IntListOptionPredicate       |      |\n| Int64ListOptionPredicate     |      |\n| ByteListOptionPredicate      |      |\n| RuneListOptionPredicate      |      |\n| Float32ListOptionPredicate   |      |\n| Float64ListOptionPredicate   |      |\n| AnyListOptionPredicate       |      |\n| BoolListPredicate            |      |\n| StringListPredicate          |      |\n| IntListPredicate             |      |\n| Int64ListPredicate           |      |\n| ByteListPredicate            |      |\n| RuneListPredicate            |      |\n| Float32ListPredicate         |      |\n| Float64ListPredicate         |      |\n| AnyListPredicate             |      |\n| BoolArrayListPredicate       |      |\n| StringArrayListPredicate     |      |\n| IntArrayListPredicate        |      |\n| Int64ArrayListPredicate      |      |\n| ByteArrayListPredicate       |      |\n| RuneArrayListPredicate       |      |\n| Float32ArrayListPredicate    |      |\n| Float64ArrayListPredicate    |      |\n| AnyArrayListPredicate        |      |\n| BoolOptionListPredicate      |      |\n| StringOptionListPredicate    |      |\n| IntOptionListPredicate       |      |\n| Int64OptionListPredicate     |      |\n| ByteOptionListPredicate      |      |\n| RuneOptionListPredicate      |      |\n| Float32OptionListPredicate   |      |\n| Float64OptionListPredicate   |      |\n| AnyOptionListPredicate       |      |\n| BoolListListPredicate        |      |\n| StringListListPredicate      |      |\n| IntListListPredicate         |      |\n| Int64ListListPredicate       |      |\n| ByteListListPredicate        |      |\n| RuneListListPredicate        |      |\n| Float32ListListPredicate     |      |\n| Float64ListListPredicate     |      |\n| AnyListListPredicate         |      |\n\n\u003c/details\u003e\n\n[[🠕]](#predicates0)\n\n## Transformers\nTransformers are functions which transform one type to other type `A =\u003e B`. Transformers are used as function's arguments in the following operations on monads: `Map`, `FlatMap`, `GroupBy`\n[[🠕]](#transformers0)\n\n### Identity\n```go\n// Just return value without transformation\nvar IntIdentity func(int) int = func(i int) int { return i }\n...\n```\nExamples:\n```go\nl := MkIntList(1,2,3,1,3,3,4)\n\ngroups := l.GroupBy(IntIdentity)\n/*\n   Map(1 -\u003e List(1,1),\n       2 -\u003e List(2),\n       3 -\u003e List(3,3,3),\n       4 -\u003e List(4))\n*/\n```\n\n[[🠕]](#transformers0)\n\n### String transformers\n```go\n// Build transformer which transform string to matched regex groups\nfunc RegexGroups(r *regexp.Regexp) func(string) []string\nfunc StringRegexGroups(pattern string) func(string) []string\n```\nExample:\n```go\nl := MkStringList(\"10014-dav\", \"10015-pav\", \"10016-ant\", \"10017-din\")\n\n\nidNameRegex := StringRegexGroups(\"([0-9]+)\\\\-([a-z]+)\") // string =\u003e []string transformer\n\nres1 := l.MapStringArray(idNameRegex) \n/* StringArrayList (Array(\"10014-dav\", \"10014\", \"dav\"),\n                    Array(\"10015-pav\", \"10015\", \"pav\"),\n                    Array(\"10016-ant\", \"10016\", \"ant\"),\n                    Array(\"10017-din\", \"10017\", \"din\")) */\n```\n[[🠕]](#transformers0)\n\n## Predef\nContains some convenient utils.\n[[🠕]](#predef0)\n### Require\n```go\n// Throws exception with message if e-condition is false\n// Can be used as validation of public functions argument\nfunc Require(e bool, msg string)\n```\nExamples:\n```go\nfunc Div(a, b Int) Float32 {\n  Require(a != 0, \"Divide by zero!\")\n  ...\n}\n```\n[[🠕]](#predef0)\n\n## Concurrency API\n\nConcurrence API implements a `Future` as abstraction over go routines and channels. It allows to combine async calculations in blocking and non blocking manner.\nAll examples of this section use a `IntFuture` type. But this API is supported in the other future types also. (See [Supported future types section](#supported-future-types))\n\nBefore using concurrence API library import the following packages:\n```go\nimport (\n  . \"github.com/zx80live/gofp/fp\"\n  . \"github.com/zx80live/gofp/fp/concurrent\"\n)\n```\n[[🠕]](#concurrency0)\n\n### Create future\n```go\n// Execute go-routine for calculate function\nfunc MkIntFuture(f func() Int) IntFuture\n```\nExample:\n```go\nt1 := time.Now().Unix()\n// create future\nf1 := MkIntFuture(func() Int {\n        time.Sleep(2 * time.Second)\n        return Int(10)\n      })\nt2 := time.Now().Unix()\nfmt.Println(\"at \", t2 - t1)      // at 0 milliseconds\n                                 // microbenchmark demonstrates async running of IntFuture\n\n// If you want to wait and get result of future use Result method\n// Warning! But this method blocks current thread (routine)\nt3 := time.Now().Unix()\nres1 := f1.Result()\nt4 := time.Now().Unix()\n\nfmt.Println(\"result \", res1, \"at \", t4 - t3)  // result 10 at 2 seconds \n\n```\n[[🠕]](#future0)\n\n### Future.FlatMap\n```go\n// Gives the ability to compose async operations together\nfunc (f IntFuture) FlatMap\u003cType\u003e(t func(Int) \u003cType\u003eFuture) \u003cType\u003eFuture\n\n// examples\nfunc (f IntFuture) FlatMapInt(t func(Int) IntFuture) IntFuture\nfunc (f IntFuture) FlatMapString(t func(Int) StringFuture) StringFuture\n...\n```\n[[🠕]](#future0)\n\n#### Future.FlatMap.Blocking composition\n`FlatMap` allows to compose two async calculations (which are presented as two futures) in the blocking manner. In other words, the resulting future will be result of sequential calculations of two futures. So the inner future which is mapped to outer future will be started when outer future will be completed.\nThis example uses `Future.Result` invocation which is described in [Future.Result](#futureresult) section.\n\n```go\n// Task: implement two async functions.\n// Each function takes some time (2 seconds) and return some number.\n// And then we should multiple results of these functions in blocking manner.\n// Full time of execution both futures will be ~4000 milliseconds.\n// Therefore these futures will be executed SEQUENTIALLY\n\nt1 := time.Now().Unix()\nf := MkIntFuture(func () Int {\n       time.Sleep(2 * time.Second)                          // some payload emulation\n       return Int(10)\n     }).FlatMapInt(func (a Int) IntFuture  {\n          return MkIntFuture(func () Int {\n            time.Sleep(2 * time.Second)                     // some payload emulation\n            return Int(a * 20)\n           })\n     })\nt2 := time.Now().Unix()\nfmt.Println(\"create and compose futures at\", t2 - t1)       // at 0 milliseconds\n\nt3 := time.Now().Unix()\n// block current main-thread and wait and get result of future\nvar res1 Int = f.Result()                                   // 10 * 20\nt4 := time.Now().Unix()\nfmt.Println(\"get result of composing futures at\", res1, t4 - t3)  // at 4 seconds\n                                                                  // SEQUENTIAL execution\n\n\n```\n[[🠕]](#future0)\n\n#### Future.FlatMap.NON-blocking composition\n`FlatMap` allows to compose two async calculations (which are presented as two futures) in the non-blocking manner. In other words, the resulting future will be result of parallel calculations of two futures. So the both futures should be defined before than they will be composed via `FlatMap`. In this case they will be executed parallely.\nThis example uses `Future.Result` invocation which is described in [Future.Result](#futureresult) section.\n\n```go\n\n// Task: implement two async functions.\n// Each function takes some time (2 seconds) and return some number.\n// And then we should multiple results of these functions in NON-blocking manner.\n// Full time of executions both futures will be ~2000 milliseconds.\n// Therefore these futures will be executed PARALLEL\n\nt1 := time.Now().Unix()\nf1 := MkIntFuture(func () Int {\n        time.Sleep(2 * time.Second)                         // some payload emulation\n        return Int(10)\n      })\n\nf2 := MkIntFuture(func () Int {\n        time.Sleep(2 * time.Second)                         // some payload emulation\n        return Int(20)\n      })\n\n// compose futures in NON-blocking manner\nvar futureResult IntFuture = f1.FlatMapInt(func (a Int) IntFuture {\n                                 return f2.MapInt(func (b Int) Int {\n                                   return Int(a * b)\n                                 })\n                             })\n\nt2 := time.Now().Unix()\nfmt.Println(\"create and compose futures at\", t2 - t1)       // at 0 milliseconds\n\n\nt3 := time.Now().Unix()\n// block current main-thread and wait and get result of future\nvar res1 Int = futureResult.Result()                        // 10 * 20\nt4 := time.Now().Unix()\nfmt.Println(\"get result of composing futures at\", t4 - t3)  // at 2000 milliseconds\n                                                            // PARALLEL execution\n                                                            \n```\n[[🠕]](#future0)\n\n### Future.Map\n```go\n// Transform content of the future\nfunc (f IntFuture) Map\u003cType\u003e(t func(Int) \u003cType\u003e) \u003cType\u003eFuture\n\n// examples\nfunc (f IntFuture) MapInt(t func(Int) Int) IntFuture\nfunc (f IntFuture) MapString(t func(Int) String) StringFuture\n...\n```\nExample:\n```go\nf1 := MkIntFuture(func() Int { return Int(10) })             // Future(10)\n\nres1 := f1.MapInt(func(e Int) Int { return Int(e * 10) })      // Future(100)\nres2 := f1.MapString(func(e Int) String { \n    return String(fmt.Sprintf(\"\u003c%v\u003e\", e)) })                   // Future(\"\u003c10\u003e\")\n```\n[[🠕]](#future0)\n\n### Future.Result\n```go\n// Await and return the result of future\n// This method blocks the current thread (routine) from which it was invoked\nfunc (f IntFuture) Result() Int\n```\nExample:\n```go\nt1 := time.Now().Unix()\nf1 := MkIntFuture(func() Int { return Int(10) })  \nf2 := MkIntFuture(func() Int { \n\ttime.Sleep(2 * time.Second)\n\treturn Int(20) \n})                                \nt2 := time.Now().Unix()\n\nfmt.Println(\"create futures at \", t2 - t1)          // at ~0 milliseconds\n\n\nt3 := time.Now().Unix()\nres1 := f1.Result()                \nt4 := time.Now().Unix()\nfmt.Println(\"blocks current thread and return result of f1\", res1,\" at \", res1, t4 - t3)   // at ~0 millis\n\nt5 := time.Now().Unix()\nres2 := f2.Result()                \nt6 := time.Now().Unix()\nfmt.Println(\"blocks current thread and return result of f2\", res2, \" at \", t6 - t5)   // at ~2000 millis\n\n```\n[[🠕]](#future0)\n\n### Future.Success\n```go\n// Create already completed future with specified result\n// Thus, it can be used when known result should be returned as future\nfunc SuccessIntFuture(v Int) IntFuture\n```\nExample:\n```go\nvar f1 IntFuture = SuccessIntFuture(10)      // Future(10)\n```\n[[🠕]](#future0)\n\n### Supported future types\n\u003cdetails\u003e\u003csummary\u003eSupported future types (click to expand)\u003c/summary\u003e\n\n| Future type              | Scala analogue                |\n| ------------------------ | ----------------------------- |\n| BoolFuture               | Future[Boolean]               |\n| StringFuture             | Future[String]                |\n| IntFuture                | Future[Int]                   |\n| Int64Future              | Future[Long]                  |\n| ByteFuture               | Future[Byte]                  |\n| RuneFuture               | Future[Char]                  |\n| Float32Future            | Future[Float]                 |\n| Float64Future            | Future[Double]                |\n| AnyFuture                | Future[Any]                   |\n| BoolOptionFuture         | Future[Option[Boolean]]       |\n| StringOptionFuture       | Future[Option[String]]        |\n| IntOptionFuture          | Future[Option[Int]]           |\n| Int64OptionFuture        | Future[Option[Long]]          |\n| ByteOptionFuture         | Future[Option[Byte]]          |\n| RuneOptionFuture         | Future[Option[Char]]          |\n| Float32OptionFuture      | Future[Option[Float]]         |\n| Float64OptionFuture      | Future[Option[Double]]        |\n| AnyOptionFuture          | Future[Option[Any]]           |\n| BoolListOptionFuture     | Future[Option[Boolean]]       |\n| StringListOptionFuture   | Future[Option[List[String]]]  |\n| IntListOptionFuture      | Future[Option[List[Int]]]     |\n| Int64ListOptionFuture    | Future[Option[List[Long]]]    |\n| ByteListOptionFuture     | Future[Option[List[Byte]]]    |\n| RuneListOptionFuture     | Future[Option[List[Char]]]    |\n| Float32ListOptionFuture  | Future[Option[List[Float]]]   |\n| Float64ListOptionFuture  | Future[Option[List[Double]]]  |\n| AnyListOptionFuture      | Future[Option[List[Any]]]     |\n| BoolArrayOptionFuture    | Future[Option[Array[Bool]]]   |\n| StringArrayOptionFuture  | Future[Option[Array[String]]] |\n| IntArrayOptionFuture     | Future[Option[Array[Int]]]    |\n| Int64ArrayOptionFuture   | Future[Option[Array[Long]]]   |\n| ByteArrayOptionFuture    | Future[Option[Array[Byte]]]   |\n| RuneArrayOptionFuture    | Future[Option[Array[Char]]]   |\n| Float32ArrayOptionFuture | Future[Option[Array[Float]]]  |\n| Float64ArrayOptionFuture | Future[Option[Array[Double]]] |\n| AnyArrayOptionFuture     | Future[Option[Array[Any]]]    |\n| BoolListFuture           | Future[List[Boolean]]         |\n| StringListFuture         | Future[List[String]]          |\n| IntListFuture            | Future[List[Int]]             |\n| Int64ListFuture          | Future[List[Long]]            |\n| ByteListFuture           | Future[List[Byte]]            |\n| RuneListFuture           | Future[List[Char]]            |\n| Float32ListFuture        | Future[List[Float]]           |\n| Float64ListFuture        | Future[List[Long]]            |\n| AnyListFuture            | Future[List[Any]]             |\n| BoolArrayFuture          | Future[Array[Boolean]]        |\n| StringArrayFuture        | Future[Array[String]]         |\n| IntArrayFuture           | Future[Array[Int]]            |\n| Int64ArrayFuture         | Future[Array[Long]]           |\n| ByteArrayFuture          | Future[Array[Byte]]           |\n| RuneArrayFuture          | Future[Array[Char]]           |\n| Float32ArrayFuture       | Future[Array[Float]]          |\n| Float64ArrayFuture       | Future[Array[Double]]         |\n| AnyArrayFuture           | Future[Array[Any]]            |\n\u003c/details\u003e\n\n[[🠕]](#future0)\n\n## Bootstrap\nAlmost all code base of this library was generated by code-generator from the project [gofp-bootstrap](https://github.com/zx80live/gofp-bootstrap). That code generator is implemented in Scala language for the following reasons:\n - string interpolations\n - functional programming, etc\n\nBut the next generation of code generator can be implemented by the current [gofp](https://github.com/zx80live/gofp) library.\n[[🠕]](#bootstrap0)\n\n## License\n\nThis library is distributed under MIT license found in the LICENSE file.\n\n[[🠕]](#table-of-contents)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzx80live%2Fgofp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzx80live%2Fgofp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzx80live%2Fgofp/lists"}