i-am-tom / purescript-prelewd

An introduction to common PureScript operators through the only truly universal language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ€– Prelewd πŸ™‹

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.

Operators

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.

Utilities

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.

Contributing

Have I missed anything you think belongs? Send a PR!


With ❀️ πŸ’› πŸ’š πŸ’™ πŸ’œ πŸ–€ from Tom 🏁

About

An introduction to common PureScript operators through the only truly universal language.

License:MIT License


Languages

Language:PureScript 100.0%