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

Bind Fold#headOption method to this #141

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

Conversation

mlegenhausen
Copy link
Contributor

Allows the usage of the headOption method when used as reference for example in a pipe statement. Without the bind the this context gets lost and an error like this occurs:

Uncaught TypeError: Cannot read property 'find' of undefined
  at push.../../node_modules/monocle-ts/es6/index.js.Fold.headOption

@mlegenhausen mlegenhausen changed the title Bind Fold#find method to this Bind Fold#headOption method to this Sep 8, 2020
@felschr
Copy link

felschr commented Jan 19, 2023

This should fix #96.

I'm frequently running into this issue. Here is a common example:

pipe(
  [1, 2, 3, 4, 5],
  fromTraversable(Arr.Traversable)<number>().asFold().headOption,
)

Wrapping the headOption call in an arrow function can be used as a workaround:

pipe(
  [1, 2, 3, 4, 5],
  (a) => fromTraversable(Arr.Traversable)<number>().asFold().headOption(a),
)

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.

2 participants