Giter Site home page Giter Site logo

ji's Introduction

ji.lua

Ji.lua is a collection of Lua implementations of functional primitives that work on iterators, based on features from the Julia Base.Iterators library, and a few other data structures that make Lua a little less minimalistic.

Features

Iterators

Most of the functionality of Julia's Base.Iterators, adapted to Lua's iterator protocol.

Types

  • Class
    • OOP boilerplate, used by all the other types
  • Deque
    • tables as stacks, queues or double-ended queues
  • Lens
    • bijective tables, where mapping a key to a value also maps the value to the key.
  • Object
    • tables that can be frozen or sealed like JavaScript objects
  • Set
    • tables with set-like operations

Examples of how to use each of the types can be found in their test files.

string

More string manipulation functions added to the string prototype.

  • chomp
    • Removes a trailing new line, if any.
  • endswith, startswith
    • Check for patterns at the start or end of a string.
  • gsplit, split
    • Split a string with a pattern, returning an iterator or a list of strings.
  • isascii
    • Checks if all characters of a string are in the lower ASCII range.
  • lpad, rpad
    • Pad the start or end of a string to a specified length.
  • lstrip, rstrip, strip
    • Strip characters from a string at the start, the end or both.

table

  • find
    • Finds the index of a value in a list.
  • findall
    • Iterate over all matching values in a list.
  • findsorted
    • Binary search for sorted lists.
  • issorted
    • Check if a list is sorted.

Usage

ji is scoped how you prefer it. Import the whole module as a table, or export to attach the module to a table, _G by default.

local ji = require("ji")
ji.sum(ipairs({ 1, 2, 3 })) --#= 6

-- or alternatively

require("ji"):export()
sum(ipairs({ 1, 2, 3 })) --#= 6

Exporting to a specific table is useful for attaching functionality to another metatable.

local String = require("ji/string")
String.split("hello world", " ") --#= {"hello", "world"}

-- or alternatively

require("ji/string"):export(string)
("hello world"):split(" ") --#= {"hello", "world"}

ji's People

Contributors

stellartux avatar

Stargazers

Pax Newman avatar Richard Lawson avatar Coder of Salvation / Leon van Kammen avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.