Skip to content

Bind Fold#headOption method to this#141

Open
mlegenhausen wants to merge 1 commit into
gcanti:masterfrom
werk85:fold-bind
Open

Bind Fold#headOption method to this#141
mlegenhausen wants to merge 1 commit into
gcanti:masterfrom
werk85:fold-bind

Conversation

@mlegenhausen

Copy link
Copy Markdown
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

felschr commented Jan 19, 2023

Copy link
Copy Markdown

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