Comming from Scala back here, I thought I could benefit from recreating some of its nice api in lua. In progress of creating my new script I prepared some of it, that I needed for my new actions and stuff. It is not complete, it might have bugs, it may have stupid design decisions, it is not the best lua code ever, maybe is not the most performant but certainly seems to work and makes me more productive, so I decided to share that I have. I don't have time to explain what each function does, but I probably will update this code and this post over time.
Some of key things are that you should treat all of those objects, i.e. List, Set, Map, Option, Pair as immutable. Each modification creates a new object. I also (what might be odd, that's why I mention it) changed the way you index the collection, it is now (index) instead of [index], so you can say
Here is the code http://wklej.org/id/2661976/ You can for example place it as first script in persistent scripts and just use those functions.PHP Code:
local list = List.of(99, 92, 954)
print(list(2)) -- prints 92
local set = Set.of(1, 2, 54)
print(set(54), set(12)) -- prints true, false
local map = Map.of({k1 = 4, k3 = 1})
print(map('k3')) -- prints 1
To not leave you without a clue on how to use it, I will post my simple open bp action that uses that stuff http://wklej.org/id/2495118/
here is how to create a list of all monsters that are targeted in your script, excluding Others and Categories
Here is how to easly get stack and no stack items from your looting, say that all items you want to deposit have 'd' category.PHP Code:
Monsters = List.ofSettingsEntry('Targeting/Creatures')
:map(function(setting) return getsetting(setting, 'Name') end)
:filter(function(name)
local isCategory = string.sub(name, 1, string.len('Category')) == 'Category'
return name ~= 'Others' and not isCategory
end)
I am aware that I gave hardly any explanation but I plan to do it later. Maybe someone will make some use of it even now.PHP Code:
local stacks, noStacks = List.ofLootingItems('d'):map(extract('id')):partition(function(id) return iteminfo(id).iscumulative end):unpack()