{"id":21275695,"url":"https://github.com/halimath/golang-generics-kata","last_synced_at":"2025-03-15T13:13:41.830Z","repository":{"id":227314083,"uuid":"763447923","full_name":"halimath/golang-generics-kata","owner":"halimath","description":"A programming kata to practice golang generics with functional programming","archived":false,"fork":false,"pushed_at":"2024-02-26T10:10:26.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T03:27:31.352Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/halimath.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-02-26T10:09:39.000Z","updated_at":"2024-03-12T15:41:57.000Z","dependencies_parsed_at":"2024-03-12T18:09:23.580Z","dependency_job_id":null,"html_url":"https://github.com/halimath/golang-generics-kata","commit_stats":null,"previous_names":["halimath/golang-generics-kata"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halimath%2Fgolang-generics-kata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halimath%2Fgolang-generics-kata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halimath%2Fgolang-generics-kata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halimath%2Fgolang-generics-kata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/halimath","download_url":"https://codeload.github.com/halimath/golang-generics-kata/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243732303,"owners_count":20338839,"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-11-21T09:36:12.714Z","updated_at":"2025-03-15T13:13:41.810Z","avatar_url":"https://github.com/halimath.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# golang generics kata\n\nA coding kata to learn generics with golang and practice building a library to\nenable functional programming style with common collections.\n\n# Exercise\n\nBuild a library with example tests that provides datastructures and functions to\nrepresent ordered sequences of elements with common operations in a functional \nway.\n\nThe datastructures should be able to support different sources of input, i.e.\n* pre-allocated sources - ordered lists of elements, i.e. \n    slices or arrays with varying element types\n* generator sources - i.e. finite and infinit ranges of integral types \n    (those that have a \"natural\" successor)\n* streaming sources - i.e. elements that are read from i/o sources (files,\n    network, databases) or from `chan`nels - either one at a time or in bulks\n\nThe lib should provide implementations for common operations on those \ndatastructures, that somehow transform, filter or discard elements, i.e.\n\n* `map` - apply a mapping function converting elements from on datastructure\n    returning a new datastructure holding the converted elements\n* `filter` - return a new datatype that contains only those elements matching\n    a given _predicate_ function\n* `find` - find all elements matching a given _predicate_ function\n* `first` - find the first element to match a _predicate_ function\n* `take` - only take the first `n` elements from a datastructure returning a\n    new one\n* `skip` - skip the first `n` elements from a datastructure\n\nThese operations should be _combineable_ (i.e. via chaining, composition, ...).\n\nThe lib should provide implementations that serve as a _sink_ for the datasources,\ni.e.\n\n* `reduce` - aggregate elements from a datastructure by applying an aggregator\n    function one element at a time and return the final aggregation result\n    (i.e. calculate the `sum` or `product` of numbers)\n* `collect` - collect elements from the datastructure into a go slice\n\n# Challenges\n\n1. Create the library with approprate structure and tests (use \n    [Go example tests] to showcase your lib)\n1. Make sure to implement at least _two_ different _sources_ for datastructure\n    (i.e. slices, ranges)\n1. Make sure to implement at least two transformer operations (i.e. `map` and \n    `filter`) and at least two consumer operations (i.e. `collect` and `reduce`)\n1. Write benchmark tests to compare the time and memory utilization of your\n    lib in contrast to an _idiomatic_ go implementation of the same algorithm.\n\n## Advanced Challenges\n\nYou may take the following challenges into account when designing the library\nand especially the libray's API. \n\n* How to handle operations that might fail (i.e. `map` with the ability to\n    return an `error` in addition to the regular transformation result)? How\n    should the overall operation behave if the mapping function fails to transform\n    a single element?\n* How to partition transformation work (i.e. for `map`) onto separate goroutines?\n    How to ensure the results are recollected \"in order\"? How to ensure goroutines\n    do not leak?\n* How to improve performance for memory allocating operations (i.e. `collect`ing\n    elements into a slice)? How can you handle the case that the length of some\n    datastructures is known in advance while it is unknown for others?\n\n## Benchmarkung examples\n\nYou can use the following examples as benchmarks:\n\n1. Calculation on generated sequence\n    1. Produce an infinte range of natural numbers starting at `x`. \n    1. Multiply each element of that range by `y`. \n    1. Select only those numbers that are even. \n    1. Calculate the sum of the first `z` of such numbers. \n    1. Use values like `x == 19, y == 3, z == 17`.\n\n1. Parse, filter and aggregate a logfile of JSON-lines \n    1. Read a logfile of JSON-lines (each line is a self-contained JSON object).\n    1. Parse every line as JSON into an appropriate datastructure (i.e. `map` or `struct`).\n    1. Only consider those messages, that have\n        * a `app` field that is not empty\n        * a `severity` field containing either `error` or `warn`\n    1. Aggregate statistics on number of (filtered) log events per `app`.\n    * To run benchmarks on this example use the [testdata generator](./cmd/testdata-generator/)\n        to generate files of configurable sizes (these are not added to this repo)\n\n[Go example tests]: https://go.dev/blog/examples","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalimath%2Fgolang-generics-kata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhalimath%2Fgolang-generics-kata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalimath%2Fgolang-generics-kata/lists"}