1

Coming from a Haskell background, I would like to map over a list of functions. For example I have:

functions fnA(x){ return true }
function  fnB(x){ return false }

// I would like to write this code that applies the same value to all functions
[ fnA, fnB ] .map ( (fn : any) => fn('hello world') )

However I am getting error:

(x : any) => boolean' cannot be used as an index type.

1 Answer 1

3

Prefix the last line with a semicolon:

;[ fnA, fnB ] .map ( (fn : any) => fn('hello world') )

Background: semicolons are optional in Javascript. However there are some edge-cases which require you to apply some style rules.

Starting a line with a bracket [ or parenthesis ( is one of those edge cases.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.