futurescript icon indicating copy to clipboard operation
futurescript copied to clipboard

Function guard clauses similar to elixirscript

Open kristianmandrup opened this issue 8 years ago • 0 comments

Would be pretty simple reusing tailored also used by elixirscript

elixir-guard-clauses


greet: guard({age: age}) when kid?(age) -> "just a kid"
greet: guard(_) -> "regular person"

The when would just become the first line in the function and do an early return if not passed

const tailored = require('tailored');
const _ = tailored.wildcard();
const $ = tailored.parameter();

let fact = tailored.defmatch(
  tailored.clause([0], () => 1),
  tailored.clause([$], (n) => n * fact(n - 1))
);

let response = fact(0); //1
response = fact(10); //3628800

Would also be nice with an easier way to operate with Map Set and Symbol

I'd suggest these improvements

# assigning a Map
%{a: 2, b: 3}

# assigning a set
&{a: 1, b: 4}

Assigning and referencing a symbol
:a: 2
z = :a

b: {:a: 2 :b: 3} or {:a => 2 :b => 3}

# Object.assign (get rid of << and >> for indentation, are they ever useful?)

Object.assign(a, b, c)
a << b << c

Alternative to 'wait (similar to yield or await in async/await)

personId <- findPerson 8 
a <- getAds personId

Just some idea ;)

kristianmandrup avatar Mar 06 '17 20:03 kristianmandrup