eridal / loda.sh

Bash flauvored lodash port
11 stars 2 forks source link

Docs and Examples #1

Open ChrisCates opened 5 years ago

ChrisCates commented 5 years ago

Spicy project, I like it. Would be nice to have some docs and examples to see how to use it in the wild. 💯

eridal commented 5 years ago

Hey, very nice to hear this got your interest!

I created this project a few years ago when I was curious about how the _ functions would look like on the shell.

The shell itself is quite a bit different from a programming language as execution environment, specially in terms of how the different processes share data. In a language you have input parameters and return values, while in the shell you have stdin/out/err .. which makes hard to implement the functions.

I was able to start making things like map, filter, each, but as I was building those I was also learning more about its limitations, so I decided not to purse and pause the implementation.

I still wonder.. is it possible to implement such library?

ChrisCates commented 5 years ago

Yes, youre right.

The syntax of most shells on DOS and *nix dont have the supporting syntax for majority of the techniques used in lodash.

However, you can use some sort of preprocessor that is directly binded to lodash and outputs procedural shell scripts.

Just a thought! 😇

eridal commented 5 years ago

Hey, this sounds interesting!

How would such preprocessor work? Could you please show some example about what you were thinking?

ChrisCates commented 5 years ago

Absolutely, below is a quick 2-minute sketch of how I think it would work at a high level:

const _= require('loda.sh');
_.print('Hello World');

Result:

echo 'Hello World'