Lift into a Pointed Functor with of

Brian Lonsdorf
InstructorBrian Lonsdorf
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

We examine the of function we've seen on a few types and discover it's the Pointed interface.

[00:00] You may have seen this function of popup here now. It's really a generic interface to be able to place a value into our type, or we call it lifting a value to our type. Here, we have Task.of. If we say ('hello'), we end up with a Task of ('hello'). If we have an Either.of('hello'), we end up with a Right of ('hello').

[00:21] Similarly, if we have a Box.of say (100)...we're just picking arbitrary values here. We're just putting those values inside our types, and this is regardless of any constructor complexities here.

[00:33] If you recall Task as the constructor where we take a reject function, a result function, and resolve this, then this would be much more complex and not to the generic interface that I could use to program functions that just pop a value into a type, not worrying about any constructors or specifics.

[00:49] Why did we choose right instead of left?

[00:52] That's a terrific question. The reason for this is that one of the contracts or intuitions of of here, is that once I popup a value into my of, I want to be able to start mapping and chaining and using all of those generic interface functions on this value. If this was to return a left, we wouldn't be able to actually map over it.

[01:11] It would just ignore maps and chains. That's kind of ignoring the contract of of, which would just lift a value into a type and start working with it as if it's a total success and things work the way they should.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today