When newcomers to PureScript see some code for the first time, there's a 90% chance that the first comment will be something like, "What does $
do?", or "f <$> a <*> b
? Wat?". This library is for people wondering exactly that.
The standard Prelude
is fine, but it's a bit... well, monotone. Wouldn't it look better if they were a little more... fabulous? 🦄 Let's look at some of the common operators with more panache. 🎩✨
Below is a table of short explanations. For a more fully-formed write-up (and some explanation as to why these symbols were chosen), see the actual code.
Emoji | Symbol | Explanation |
---|---|---|
🚂 | <$> |
Map the function to the left over the Functor -wrapped value to the right. |
🚋 | <*> |
Apply the functor-wrapped function on the left to the functor-wrapped value on the right. |
👉 | *> |
Combine two Apply 's effects, and return the second. |
🎉 | >>= |
Pass the left-hand "inner value" into the right-hand function. |
🔙 | <<< |
Return a function that takes a value, applies it to the right-hand function, and then applies it to the left-hand function. |
🔜 | >>> |
Same as compose , but backwards. |
💨 | $ |
Apply the result of the expression to the left to the expression on the right. |
🐛 | ~> |
f ~> g is a function that turns an f a to an g a for any a value. A natural transformation. |
🙏 | <> |
Combine two Semigroup values. |
🔗 | <|> |
Combine two Alt values. A good starting intuition is to think of this as a "chain of fallbacks". |
💄 | >$< |
"Pre-process" a value for a Contravariant functor. |
Emoji | Implementation | Explanation |
---|---|---|
🔍 | \x y -> traceShow x 💨 const y |
x 🔍 y has the exact same value as y , but it sneakily prints x 's value to the console. Shh! |
💣 | absurd |
The emoji should tell you this probably isn't the function you want... |
🙈 | unsafePartial |
Remove the Partial constraint, e.g. fromJust 🙈 Just 2 == 2 |
🍔 | - | (f 🍔 g) a is a type equivalent to f (g a) . This is composition for functors. |
🆚 | - | An alias for the Either type. |
♊ | - | An alias for the Pair type. |
💱 | - | An alias for the Iso type |
Is f <$> a <*> b
scarier than f 🚂(a)🚋(b)🚋(c)
? If so, why?
The functions may look unfamiliar, especially the infix symbols, but
they're not that scary. Above are all the common symbols, with enough
of an explanation to get you following along with any code you see.
And, of course, if in doubt, ask the community! Send me a tweet, join an IRC forum, whatever. Get involved. This library's documentation is available on Pursuit, where you'll be able to read some more in-depth explanations of some of what we've seen.
Have I missed anything you think belongs? Send a PR!
With ❤️ 💛 💚 💙 💜 🖤 from Tom 🏁