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

Functions #4

Open
krainboltgreene opened this issue Dec 30, 2016 · 5 comments
Open

Functions #4

krainboltgreene opened this issue Dec 30, 2016 · 5 comments
Projects

Comments

@krainboltgreene
Copy link
Member

krainboltgreene commented Dec 30, 2016

Defining a function will return a Function object.
A Function can only take one argument, but that argument can be an Index List or Pair List.

Single line function definitions are expressed thusly:

ƒ(x): x +(1)

For multiple arguments you can express it thusly:

ƒ({x, z}): x +(z)

Defaults can be expressed as such:

ƒ(x: 0): x +(1)

Multiline functions are expressed thusly (Only the last line is returned):

ƒ(x):
  log("Hello, World.")
  x +(1)

Function invocation is expressed thusly:

increment: ƒ(x): x +(1)
increment(1)

For multiple arguments you would express it thusly:

increment: ƒ({value, by}): x +(z)
increment({value: 1, by: 1})

Of course for currying you would express thusly:

ƒ(x): ƒ(y): x +(y)

And currying with multiline is express thusly:

ƒ(x):
  ƒ(y):
    x +(y)
@krainboltgreene
Copy link
Member Author

krainboltgreene commented Apr 21, 2017

Now I'm starting to like arrows:

point: (x) -> (y) -> [x, y]

Hmm, also I think:

point: (x) ƒ (y) ƒ [x, y]

or

point: (x) ƒ (y) ƒ
  [x, y]

@krainboltgreene
Copy link
Member Author

Also, calling functions maybe force the argument to have the name?

point(x: 4)(y: 3)

vs

point(4)(3)

@krainboltgreene
Copy link
Member Author

I've seen a lot of languages do pipe operators so you can do:

a(b(c))

as

a
  |> b
  |> c

But I'm wondering how this would look in bee, this a first pass:

>- pullAccounts >- mapValues(path(["attributes", "created-at")) >- moment
>- pullAccounts
>- mapValues(path(["attributes", "created-at")) 
>- moment

This is interesting because it's the opposite of ->.

@krainboltgreene
Copy link
Member Author

Oh, also, with that we can also do promises as >>- and actors as >>>-

@krainboltgreene
Copy link
Member Author

Type annotations for functions

# store_printer: UUID -> String -> Cookies -> String
store_printer:
  id ->
  station ->
  cookies ->
    cookies fetch(station) fetch(id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Ideas
Draft
Development

No branches or pull requests

1 participant