Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ciscoheat/slambda
Short Lambda expressions in a tiny Haxe library
https://github.com/ciscoheat/slambda
Last synced: 15 days ago
JSON representation
Short Lambda expressions in a tiny Haxe library
- Host: GitHub
- URL: https://github.com/ciscoheat/slambda
- Owner: ciscoheat
- Created: 2015-06-03T16:25:30.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-10T13:12:57.000Z (over 6 years ago)
- Last Synced: 2023-03-10T22:42:01.446Z (over 1 year ago)
- Language: Haxe
- Homepage:
- Size: 94.7 KB
- Stars: 39
- Watchers: 10
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Slambda
Pronounced "slam-da", stands for Short Lambda. A tiny library that enables lambda expressions for [Haxe](http://haxe.org) in a simple way.
**Deprecation notice:** With Haxe 4, this will be [built into the language](https://github.com/HaxeFoundation/haxe-evolution/blob/master/proposals/0002-arrow-functions.md). Please use it instead!
Can be used with the common `=>` syntax, but also in a shorter format where `_` is assumed to be the first parameter. If more than one argument, use `_1` and `_2`, etc.
## Examples
```haxe
// This line is all you need to enable the library:
using Slambda;class Main {
static function main() {
var a : Dynamic;
// Short version, parameter name is set to "_"
a = [1, 2, 3].filter.fn(_ > 1);
trace(a); // [2, 3]// Normal version, arrow syntax:
a = [1, 2, 3].filter.fn(x => x > 1);
trace(a); // [2, 3]// For multiple arguments, use _1, _2, etc.
a = [1, 1, 1].mapi.fn(_1 + _2);
trace(a); // [1,2,3]// Multiple arguments can also be used with arrow syntax,
// but must then use brackets:
a = [1, 1, 1].mapi.fn([i, a] => i + a);
trace(a); // [1,2,3]// When used as a static extension, add rest arguments
// for functions like fold:
a = [1, 1, 1].fold.fn(_1 + _2, 10);
trace(a); // 13// Chainable
a = [1, 2, 3].filter.fn(_ > 1).filter.fn(y => y > 2);
trace(a); // [3]// Works inside (single-quoted) strings too
a = [1].map.fn('$_');
trace(a); // ["1"]
}
}
```If you import `Slambda.fn`, you can use it without the static extension:
```haxe
import Slambda.fn;// Only Lambda this time for the sake of the example.
using Lambda;class Main {
static function main() {
var a = [1, 2, 3].filter(fn(_ > 1));
}
}
```## Installation
`haxelib install slambda`, then use it in a `hxml` file with `-lib slambda`.