only nine more days of this daily-blog-posting exercise left and I can go back to my usual three-times-a-year frequency. Thank goodness

Today, I experimented with converting the NixWRT Lua service monitor scripts into Fennel.

@dan "I haven't found a nice way to iterate through an array and return the first element that matches a predicate (as far as I can tell, an early return from an each is not possible) but I'm sure there must be one" i've never heard of fennel until now (it looks pretty neat), the docs recommend installing lume or luafun for map, reduce, and filter

@dan looking at those, lume has match:
lume.match({1, 5, 8, 7}, function(x) return x % 2 == 0 end) -- Returns 8, 3
luafun doesn't seem to have a direct way of doing it, but it has lazy iterators/lists, so you can do (untested):
head(map(function(x) return x % 2 == 0 end, {1, 5, 8, 7})) -- Returns 8

@dan the map in the luafun example should be a filter
i tried to write a filter in fennel but lisps give me a headache >_<

Sign in to participate in the conversation

personal server for leo60228 (