{"id":20982406,"url":"https://github.com/juliaaplavin/fleximaps.jl","last_synced_at":"2025-12-29T07:52:21.452Z","repository":{"id":238906054,"uuid":"759481624","full_name":"JuliaAPlavin/FlexiMaps.jl","owner":"JuliaAPlavin","description":"Generalize `map`: make it lazy, filtering, flattening, ...","archived":false,"fork":false,"pushed_at":"2024-12-16T16:14:56.000Z","size":67,"stargazers_count":14,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T06:45:51.729Z","etag":null,"topics":["data-manipulation","filtering","lazy","mappings"],"latest_commit_sha":null,"homepage":"","language":"Julia","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/JuliaAPlavin.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":"2024-02-18T17:57:19.000Z","updated_at":"2024-12-16T17:01:28.000Z","dependencies_parsed_at":"2024-05-08T20:12:13.063Z","dependency_job_id":null,"html_url":"https://github.com/JuliaAPlavin/FlexiMaps.jl","commit_stats":null,"previous_names":["juliaaplavin/fleximaps.jl"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaAPlavin%2FFlexiMaps.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaAPlavin%2FFlexiMaps.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaAPlavin%2FFlexiMaps.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaAPlavin%2FFlexiMaps.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JuliaAPlavin","download_url":"https://codeload.github.com/JuliaAPlavin/FlexiMaps.jl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243384982,"owners_count":20282472,"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":["data-manipulation","filtering","lazy","mappings"],"created_at":"2024-11-19T05:45:30.007Z","updated_at":"2025-12-29T07:52:21.423Z","avatar_url":"https://github.com/JuliaAPlavin.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FlexiMaps.jl\n\nAll-familiar `map` on steroids: a set of functions that generalize `map`.\n\n## `filtermap`\n\n`filtermap(f, X)`: map and filter a collection in one go.\nMost useful when the mapped function shares some computations with the filter predicate.\n\nReturns same as `map(f, X)`, dropping elements where `f(x)` is `nothing`.\nReturn `Some(nothing)` from `f` to keep `nothing` in the result.\n\n```julia\nfiltermap(x -\u003e x % 3 == 0 ? x^2 : nothing, 1:10) == [9, 36, 81]\n```\n\n_Analogous to `filter_map` in Rust_\n\n## `flatmap`/`flatten`\n\nThese functions are similar to `Iterators.flatmap` and `Iterators.flatten`, but operate on arrays in a more performant and generic manner.\n\n`flatmap(f, X)`: apply `f` to all elements of `X` and flatten the result by concatenating all `f(x)` collections.\n\n`flatmap(fₒᵤₜ, fᵢₙ, X)`: apply `fₒᵤₜ` to all elements of `X`, and apply `fᵢₙ` to the results. Basically, `[fᵢₙ(x, y) for x in X for y in fₒᵤₜ(x)]`.\n\n`flatmap(f, X)` is similar to `mapreduce(f, vcat, X)` and `SplitApplyCombine.mapmany(f, A)`, but more efficient and generic.\n\nDefining differences include:\n- better result type inference\n- keeps array types, eg `StructArray`\n- works with empty collections\n- supports arbitrary iterators, not only arrays\n\n_Analogous to `flat_map` in Rust, and `SelectMany` in C#_\n\n`flatten(X)`: flatten a collection of collections by concatenating all elements, equivalent to `flatmap(identity, X)`.\n\n## `mapview` (lazy `map`)\n\n`mapview(f, X)`:\n- like `map(f, X)`, but works lazily, doesn't materialize the result returning a view instead.\n- like `Iterators.map(f, X)`, but with better collection support, type stability, etc.\n\nWorks on different collections and arbitrary iterables. Collection types are preserved when possible for ranges, arrays, dictionaires. Passes `length`, `keys` and others directly to the parent. Does its best to determine the resulting `eltype` without evaluating `f`. Supports both getting and setting values (through `Accessors.jl`).\n\n```julia\nX = [1, 2, 3]\nmapview(x -\u003e x + 1, X) == [2, 3, 4]  # a view of X, doesn't take extra memory\n\nX = Dict(:a =\u003e 1, :b =\u003e 2, :c =\u003e 3)\nmapview(x -\u003e x + 1, X) == Dict(:a =\u003e 2, :b =\u003e 3, :c =\u003e 4)  # same with Dict\n\nX = [1, 2, 3]\nmapview(x -\u003e x + 1, (x for x in X))  # and with iterator\n```\n\n```julia\njulia\u003e X = [1, 2, 3.]\n\njulia\u003e Y = mapview(exp10, X)\n3-element FlexiMaps.MappedArray{Float64, 1, typeof(exp10), Vector{Float64}}:\n   10.0\n  100.0\n 1000.0\n\n# setindex! works for all functions/optics supported by Accessors\njulia\u003e Y[2] = 10^10\n\n# when invertible, push! also works\njulia\u003e push!(Y, 10000)\n\njulia\u003e X\n4-element Vector{Float64}:\n  1.0\n 10.0\n  3.0\n  4.0\n```\n\n# `maprange`\n\n`maprange(f, start, stop; length)`: `length` values between `start` and `stop`, so that `f(x)` is incremented in uniform steps. Uses `mapview` in order not to materialize the array.\n\n`maprange(identity, ...)` is equivalent to `range(...)`. Most common application - log-spaced ranges:\n\n`maprange(log, 10, 1000, length=5) ≈ [10, 31.6227766, 100, 316.227766, 1000]`\n\nOther transformations can also be useful:\n\n`maprange(sqrt, 16, 1024, length=5) == [16, 121, 324, 625, 1024]`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliaaplavin%2Ffleximaps.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliaaplavin%2Ffleximaps.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliaaplavin%2Ffleximaps.jl/lists"}