Skip to content

Conversation

@wooorm
Copy link
Member

@wooorm wooorm commented May 28, 2019

Useful for reuse.

Closes GH-5.

Copy link
Member

@ChristianMurphy ChristianMurphy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good,
I'm not sure I follow how it's intended to be used.
Would it look like

function test () {/* some test*/}

const tester = convert(test);
tester(/* a node */);

?

@wooorm
Copy link
Member Author

wooorm commented May 28, 2019

@ChristianMurphy Thanks for asking that question, it’s in my head, but before I answer I’d like to make sure that you saw the docs (https://github.com/syntax-tree/unist-util-is/blob/2ac6b804c42eba6cce804ff5984a71e192836aee/readme.md#isconverttest) and that they aren’t useful enough?

@ChristianMurphy
Copy link
Member

I saw that
The comment:

Create a test function from test, that can later be called with a node, index, and parent

Is what made me think it might be a partially applied function.

@wooorm
Copy link
Member Author

wooorm commented May 28, 2019

The idea is that it would save a little bit of overhead if you know you’re values (node, index, parent) are correct. That it can be used in utilities like unist-util-visit-parents that use that test a lot.

The example you provided in #7 (review) is correct, and:

Is what made me think it might be a partially applied function.

Yup, it’s creating a function from any valid test value, that is thus “applied”

@ChristianMurphy
Copy link
Member

Cool, makes sense, just double checking

@wooorm wooorm merged commit c3801b3 into master May 29, 2019
@wooorm wooorm deleted the convert branch May 29, 2019 08:07
@wooorm wooorm added ⛵️ status/released 🗄 area/interface This affects the public interface 🦋 type/enhancement This is great to have 🧒 semver/minor This is backwards-compatible change labels Aug 12, 2019
@wooorm wooorm added the 💪 phase/solved Post is done label Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have

Development

Successfully merging this pull request may close these issues.

Add /convert.js to convert a Test value into a test function

3 participants