Skip to content

Commit

Permalink
Basic documentation and a test for :zip
Browse files Browse the repository at this point in the history
  • Loading branch information
Henkoglobin committed Dec 11, 2024
1 parent d0dfcdb commit 5f2d60f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# lazylualinq

[![tests](https://github.com/Henkoglobin/lazylualinq/actions/workflows/test-and-publish.yml/badge.svg)](https://github.com/Henkoglobin/lazylualinq/actions/workflows/test-and-publish.yml) [![luarocks](https://img.shields.io/luarocks/v/henkoglobin/lazylualinq?style=plastic)](https://luarocks.org/modules/henkoglobin/lazylualinq)
[![tests](https://github.com/Henkoglobin/lazylualinq/actions/workflows/test-and-publish.yml/badge.svg)](https://github.com/Henkoglobin/lazylualinq/actions/workflows/test-and-publish.yml) [![luarocks](https://img.shields.io/luarocks/v/henkoglobin/lazylualinq?style=plastic)](https://luarocks.org/modules/henkoglobin/lazylualinq) [![pages-build-deployment](https://github.com/Henkoglobin/lazylualinq/actions/workflows/pages/pages-build-deployment/badge.svg?branch=main)](https://henkoglobin.github.io/lazylualinq/)

LazyLuaLinq provides a simple, _lazy_ implementation of linq-like functions for Lua. With LazyLuaLinq, you can implement data transformation in elegant, expressive _queries_ akin to SQL:

Expand Down Expand Up @@ -401,4 +401,14 @@ local linq = require("lazylualinq")
setfenv(func, env)
return func
end)
```
```

# Dependencies and running tests

In order to develop lazylualinq, you should install the test dependencies:

```bash
sudo luarocks test --prepare
```

Then, you can run the tests using `luarocks test`.
12 changes: 12 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ local seq = linq { "a", "b", "c" }:take(2)
```

## `linq:zip(other, resultSelector)`

`zip` combines elements from the input and the `other` list, calling `resultSelector` for each pair of values.
It will only iterate the input sequences as long as the _shorter_ of both sequences yields values.

`resultSelector` has the following signature: `function(leftValue, leftKey, rightValue, rightKey)`.

```lua
local seq = linq { "foo", "egg", "hello" }
:zip(linq{ "bar", "spam" }, function(l, _, r) return l .. r end)
-- seq is now equivalent to linq { "foobar", "eggspam" }
```

## `linq:defaultIfEmpty(defaultValue, defaultIndex)`
## `linq:reindex()`
## `linq:nonNil()`
Expand Down
12 changes: 12 additions & 0 deletions test/intermediate/zip.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe("intermediate operator #zip", function()
local linq = require("lazylualinq")

it("only iterates until one sequence runs out of items", function()
local iterator = linq { "foo", "egg", "hello" }
:zip(linq{ "bar", "spam" }, function(l, _, r) return l .. r end)
:getIterator()

assert.is_same({"foobar", 1}, { iterator() })
assert.is_same({"eggspam", 2}, { iterator() })
end)
end)

0 comments on commit 5f2d60f

Please sign in to comment.