{"id":25198171,"url":"https://github.com/andrewcodedev/fluent","last_synced_at":"2025-06-29T13:37:33.703Z","repository":{"id":232909882,"uuid":"785489282","full_name":"andrewCodeDev/Fluent","owner":"andrewCodeDev","description":"Fluent interface for REGEX, iteration, and algorithm chaining.","archived":false,"fork":false,"pushed_at":"2024-09-08T18:27:57.000Z","size":224,"stargazers_count":107,"open_issues_count":4,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-06-29T02:51:52.123Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Zig","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/andrewCodeDev.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-04-12T01:33:28.000Z","updated_at":"2025-06-14T17:58:33.000Z","dependencies_parsed_at":"2025-02-24T04:01:50.085Z","dependency_job_id":"6251e07a-12fb-4aa1-bb3d-33769563e16d","html_url":"https://github.com/andrewCodeDev/Fluent","commit_stats":null,"previous_names":["andrewcodedev/fluent"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/andrewCodeDev/Fluent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewCodeDev%2FFluent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewCodeDev%2FFluent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewCodeDev%2FFluent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewCodeDev%2FFluent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewCodeDev","download_url":"https://codeload.github.com/andrewCodeDev/Fluent/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewCodeDev%2FFluent/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262601218,"owners_count":23335215,"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":"2025-02-10T02:41:10.568Z","updated_at":"2025-06-29T13:37:33.652Z","avatar_url":"https://github.com/andrewCodeDev.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"![fluent](https://github.com/andrewCodeDev/Fluent/assets/54549221/6064d88a-ff2a-4970-a494-a432a8e74515)\n\nA fluent-interface for chaining algorithms, iterating, and performing REGEX over slices. \n\n# Installation\n\n## Installation\nYou can install the library by adding it to the `build.zig.zon` file, either manually like so:\n```zig\n.{\n    ...\n    .dependencies = .{\n        .Fluent = .{\n            .url = \"https://github.com/andrewCodeDev/Fluent/archive/refs/tags/release_2.3.3.tar.gz\",\n            .hash = \"...\",\n        }\n    }\n    ...\n}\n```\n\nThe hash can be found using the builtin command:\n```sh\nzig fetch https://github.com/andrewCodeDev/Fluent/archive/refs/tags/release_2.3.3.tar.gz\n```\n\nOr you can also add it automatically like so:\n```sh\nzig fetch --save https://github.com/andrewCodeDev/Fluent/archive/refs/tags/release_2.3.3.tar.gz\n```\n\nThen in the `build.zig`, you can add the following:\n```zig\nconst Fluent = b.dependency(\"Fluent\", .{\n    .target = target,\n    .optimize = optimize,\n});\n\nexe.root_module.addImport(\"Fluent\", Fluent.module(\"Fluent\"));\n```\n\nThe name of the module (`Fluent`) can be changed to whatever you want.\n\nFinally in your code you can import the module using the following:\n```zig\nconst Fluent = @import(\"Fluent\");\n```\n\n# Examples\n\nUse REGEX to find all substrings starting with a, b, or c followed by digits in a string:\n\n```Zig\nvar itr = Fluent.match(\"[abc]\\\\d+\", \"_ab112_c987b123_d16_\");\n\nwhile (itr.next()) |substr| { // ...\n\n```\nUse REGEX to split a string on any whitespace:\n\n```Zig\nvar itr = Fluent.split(\"\\\\s+\", \"This is a string\");\n\nwhile (itr.next()) |substr| { // ...\n\n```\nForm complex REGEX statement to extract email addresses:\n\n```Zig\nconst string = \"myname.myfirstname@gmail.com\";\n\nvar itr = Fluent.match(\"[a-zA-Z0-9_!#$%\u0026.-]+@[a-zA-Z0-9.-]+\", string);\n\nwhile (itr.next()) |str| { ...\n```\nTrim punctuation or whitespace by combining REGEX and the Fluent Interface:\n```Zig\nconst trimmed = Fluent.init(string).trim(.all, .regex, \"[\\\\s.?!,]+\");\n```\nConcatenate, trim, and title string:\n```Zig\nconst result = Fluent.init(str_a)   // initialize our interface on str_a\n        .concat(str_b, buf[0..])    // concatenate str_b into buffer\n        .trim(.left, .scalar, ' ')  // trim spaces on left side\n        .title();                   // python title function\n```\nREGEX statements can be run at comptime:\n```Zig\nfn foo(string: []const u8) bool {\n    comptime {\n        return Fluent.init(string).contains(.regex, \"\\\\w+\");\n    }\n}\n// later...\nconst x: if (foo(\"a\")) usize else u8 = 1;\n\n```\nFuse map-functions to calculate sigmoid to buffer:\n```Zig\nconst x = Fluent.init(buf[0..])\n    .copy(\u0026[_]f32{ -2, -1, 0, 1, 2 })\n    .map(.{\n        Fluent.negate,\n        std.math.exp,\n        Fluent.bind(.{ 1.0 }, Fluent.add),\n        Fluent.bind(.{ 1.0 }, Fluent.div),\n    });\n```\nCopy the reverse of a list using a reverse iterator:\n```Zig\nconst count = Fluent.iterator(.reverse, items_a[0..]).write(items_b[0..]);\n```\nSum up the square of all elements that are even:\n```Zig\nconst rdx = Fluent\n    .iterator(.forward, items[0..])\n    .filter(isEven) // user-defined function\n    .map(sqr)       // user-defined function\n    .reduce(i32, Fluent.add, 0);\n```\nSet stride and iteratively produce slice-windows:\n```Zig\nvar itr = Fluent\n    .iterator(.forward, items[0..])\n    .strided(2);\n\nwhile (itr.window(4)) |window| { // ...\n```\nFuse multiple unary functions and filters:\n```Zig\nvar itr = Fluent\n    .iterator(.forward, items[0..])\n    .map(.{\n        Fluent.negate,\n        std.math.exp,\n    }).filter(.{\n        skipNans,\n        skipInfs,\n    });\n\nwhile (itr.next()) |value| { // ...\n```\n# Fluent Explained\n\n### What makes it \"fluent\"?\n\nThe fluent interface is a programming pattern that centers around method chaining.\n\n```Zig\n// without method-chaining...\nconst y = trim(.all, x, \" \");\nconst z = sort(y, .asc);\n\n// with method-chaining...\nconst y = x.trim(.all, \" \").sort(.asc);\n```\nThis pattern can encourage brevity and reduce intermediate variables.\n\n### Chainable and Terminal methods:\n\nThere are two kinds of methods in fluent: Chainable and Terminal\n\n- Chainable methods return another fluent interface.\n- Terminal methods return various types such as usize\n\nChainable methods include algorithms like sort, rotate, and map.\n\nTerminal methods include algorithms like count and max.\n\n### Function composition:\n\nTo reduce the number of intermediate calls, fluent enables composing unary functions.\n\nAny method starting with the word `map` allows applying a function or a function tuple. This includes `map` and `mapReduce`.\n\nThe iterator function `filter` applies filters sequentially to determine if an element will be returned by `next`.\n\n# Iterators (standard and REGEX)\n\nFluent iterators come in Scalar and REGEX versions.\n\nScalar iterators have the following characteristics:\n\n- Direction - can be forward or reverse.\n- Filters - a single (or tuple) of unary predicates to determine if an element will be included.\n- Transforms - a single (or tuple) of unary mapping functions applied to elements.\n- Stride - the distance an iterator steps on each iteration (default 1).\n\nThese characteristics can be chained to construct a scalar iterator:\n\n```Zig\n// create an iterator with filters, transforms, and stride\nvar itr = Fluent\n    .iterator(.forward, slice)\n    .map(.{\n        // ...\n    }).filter(.{\n        // ...\n    }).strided(N);\n```\nREGEX iterators take an expression and a string and return substrings.\n\nThese iterators include:\n\n- Match - returns substrings that match an expression.\n- Split - splits a string based on an expression.\n\n# Algorithms\n\n### General Backend:\n\n```\nImmutable:\n\nall           - check if all elements of the acquired slice are true by given predicate\nconcat        - appends the aquired slice to a given slice into a given buffer\ncontains      - check if contains a given scalar, sequence, or any\ncontainsFrom  - check if contains a given scalar, sequence, or any after a given index\ncount         - counts all, left, right given a scalar, sequence, or any\nendsWith      - checks if the acquired slice ends with a scalar, sequence, or any\nequal         - returns true if lexicogrpahical order is equal to a given slice\nfind          - returns first index of scalar, slice, or any\nfindFrom      - returns first index after a given position of scalar, slice, or any\ngetAt         - returns an element for given positive or negative index\njoin          - appends the aquired slice to a given range of slices into a given buffer\nmapReduce     - applies unary function and reduces on intial value and binary function\nmax           - returns an optional maximum value from the acquired slice\nmin           - returns an optional minimum value from the acquired slice\nnone          - check if no elements of the acquired slice are true by given predicate\nproduct       - returns the product of all elements or zero if slice is empty\nprint         - prints the acquired slice based on a given format string\norder         - returns the lexicographical order compared to a given slice\nreduce        - returns a reduction based on an intial value and binary function\nslice         - chainable slicing operation for acquired slice\nstartsWith    - checks if the acquired slice starts with a scalar, sequence, or any\nsample        - randomly samples a range from the acquired slice given a size\nsum           - returns the sum of all elements or zero if slice is empty\ntrim          - trims left, right, or all based on any, sequence, or scalar\nwrite         - writes the acquired slice to a given buffer\n\nMutable:\n\ncopy          - copy a given slice into the acquired slice\nfill          - fills the acquired slice with a scalar value\nmap           - transforms every elment in the acquired slice with a given unary function\nreverse       - reverses the acquired slice\nrotate        - rotates the array by both negative and positive amounts\nsetAt         - sets a given position with a provided value using index wrapping\nshuffle       - randomly shuffles the acquired slice\nsort          - sorts the range in ascending or descending order\n```\n\n### String Backend:\n\n```\nImmutable:\n\ncount          - counts all, left, right given a scalar or regex\ndigit          - returns integer (or error) parsed from string\ndifferenceWith - returns set diference between acquired slice and given slice\nfloat          - returns floating-point number (or error) parsed from string\nintersectWith  - returns set intersection between acquired slice and given slice\nisDigit        - check if string only contains digits\nisAlpha        - check if string only contains alphabetic characters\nisSpaces       - check if string only contains whitespace\nisLower        - check if string only contains alphabetic lower case\nisUpper        - check if string only contains alphabetic upper case\nisHex          - check if string only contains hexidecimal characters\nisASCII        - check if string only contains ASCII characters\nisPrintable    - check if string only contains printable characters\nisAlnum        - check if string only contains alpha numeric characters\ntrim           - trims left, right, or all based on scalar or regex\nunionWith      - returns set union between acquired slice and given slice\n\nMutable:\n\nlower          - transform all alphabetic characters to lower case\nupper          - transform all alphabetic characters to upper case\ncapitalize     - transform first character to upper case and rest to lower case\ntitle          - capitalize each sequence separated by spaces\n```\n### Iterator Support:\n\nFluent iterator (forward/reverse):\n```\nnext            - return an optional value and advance by stride\nwindow          - return a slice and advance by stride\nfilter          - acquire a unary predicate or a tuple of unary predicates\nmap             - acquire a unary transform or a tuple of unary transforms\nwrite           - loop and write remaining iterator values to buffer\nreduce          - accumulate the range using a binary function and initial value\nstrided         - set iterator stride (default 1)\n```\nFluent iterator (REGEX):\n```\nmatch           - match substrings based on an expression\nsplit           - splits a string based on a delimiting expression\n```\n# REGEX - (PCRE Standard)\n\n### Special Characters:\n```\n^  - begins with\n$  - ends with\n.  - any character\n\\d - digits\n\\D - no-digits\n\\w - alphanumeric\n\\W - no-alphanumeric\n\\s - whitespace\n\\S - no-whitespace\n```\n### Quantifiers:\n```\n+     - one or more\n*     - any quantity\n?     - none or one\n{n}   - exactly n\n{m,n} - between m and n (inclusive)\n```\n### Operators:\n```\n|     - alternation (or clause)\n()    - capture group\n[]    - character set\n[^]   - negated character set\n[a-z] - character spans\n(?=)  - positive lookahead\n(?!)  - negative lookahead\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewcodedev%2Ffluent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewcodedev%2Ffluent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewcodedev%2Ffluent/lists"}