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

added sed #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

added sed #12

wants to merge 1 commit into from

Conversation

ludicast
Copy link
Contributor

The sed combinator transforms a parameter at whatever index you input. Useful in situations analogous to Rails route helpers. user_path(user) is sometimes fed a user and sometimes fed a user id. In cases where it is fed a user's id, sed can transform that id into an actual user as the function parameter (or vice-versa). This prevents the function from needing to contain an if or switch statement that explicitly does the transformation.

So it world be like this

findUser = (sed (user)->
  if _.isObject(user)
    user
  else
    @lookupUserById user
)()
class RouteHelpers
  userPath: findUser (user)->

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

Successfully merging this pull request may close these issues.

1 participant