Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function guard clauses similar to elixirscript #27

Open
kristianmandrup opened this issue Mar 6, 2017 · 0 comments
Open

Function guard clauses similar to elixirscript #27

kristianmandrup opened this issue Mar 6, 2017 · 0 comments

Comments

@kristianmandrup
Copy link

kristianmandrup commented Mar 6, 2017

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 kristianmandrup changed the title Optionally add function pattern matching and guard clauses similar to elixirscript Function pattern matching and guard clauses similar to elixirscript Mar 6, 2017
@kristianmandrup kristianmandrup changed the title Function pattern matching and guard clauses similar to elixirscript Function guard clauses similar to elixirscript Mar 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant