sums_up
fantasy-land
sums_up | fantasy-land | |
---|---|---|
4 | 21 | |
40 | 10,001 | |
- | 0.2% | |
0.0 | 3.1 | |
over 1 year ago | 5 months ago | |
Ruby | JavaScript | |
MIT License | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
sums_up
-
Ruby in FantasyLand: SumsUp
Now with Ruby we have a few different ideas we want to express. Whereas Daggy has tagged and taggedSum we have Struct and SumsUp.define instead. You can find more info on SumsUp here, but we'll be covering the general details in this post.
-
sums_up v1.0.0 - Sum Types for Ruby.
Hello, r/ruby! I wrote a gem, sums_up, for defining and pattern matching against sum types at Ruby. This isn't the first attempt at porting sum types into the language, but the other implementations that I've used either didn't "feel like" traditional Ruby, or didn't "feel like" a native sum type implementation. I tried my best to bridge that gap. Code Sample: require 'sums_up' # Define a sum type for Users; they can either be anonymous or logged in. User = SumsUp.define(:anonymous, logged_in: :email) # => User anon = User.anonymous # => # logged_in = User.logged_in('[email protected]') # => # anon.anonymous? # => true anon.logged_in? # => false logged_in.anonymous? # => false logged_in.logged_in? # => true anon.email # => NoMethodError: undefined method `email' for # logged_in.email # => "[email protected]" def valid_email?(user) user.match do |m| m.anonymous false m.logged_in { |email| URI::MailTo::EMAIL_REGEXP.match?(email) } end end valid_email?(anon) # => false valid_email?(logged_in) # => true valid_email?(User.logged_in('1337h@ck3r')) # => false There are a few more thorough examples in the README. If you're interested, try it out and let me know what you think!
- Sum types for Ruby
- Show HN: Sum Types for Ruby
fantasy-land
-
Functional Programming 1
2. https://github.com/fantasyland/fantasy-land (A bit heavy on jargon)
Note there is a python version of Ramda available on pypi and there’s a lot of FP tidbits inside JAX:
3. https://pypi.org/project/ramda/ (Worth making your own version if you want to learn, though)
4. For nested data, JAX tree_util is epic: https://jax.readthedocs.io/en/latest/jax.tree_util.html and also their curry implementation is funny: https://github.com/google/jax/blob/4ac2bdc2b1d71ec0010412a32...
Anyway don’t put FP on a pedestal, main thing is to focus on the core principles of avoiding external mutation and making helper functions. Doesn’t always work because some languages like Rust don’t have legit support for currying (afaik in 2023 August), but in those cases you can hack it with builder methods to an extent.
Finally, if you want to understand the middle of the midwit meme, check out this wiki article and connect the free monoid to the Kleene star (0 or more copies of your pattern) and Kleene plus (1 or more copies of your pattern). Those are also in regex so it can help you remember the regex symbols. https://en.wikipedia.org/wiki/Free_monoid?wprov=sfti1
The simplest example might be {0}^* in which case
0: “” // because we use *
-
Ramda: A practical functional library for JavaScript programmers
It was never really my jam, but I used to follow the up-and-coming fantasy-land specs with great interest. It just seemed like a sharp dedicated community of folks trying to figure out better fp & algebraic stuff. I'm not sure who trailed off - in general I feel like there's much less connection in tech world, that the tech twitter and every other ultra-active tech channel has somewhat decayed. https://github.com/fantasyland/fantasy-land
Thanks for the links. I know I've seen @gcanti's name a thousand times already, but it's already quite murky to me what it was attached to. Something in this sphere.
-
How elaborate could/should a transducers combiner function be?
Look at the implementations of Fantasy Land. List-in-JS might do the trick.
- General Functional Programming Resources
-
Should I Move From PHP to Node/Express?
There are respective fantasy land and static land specs, with the law conformance checks.
-
I came across the "Fantasy Land Specification", it somewhat conflicts with my own simplistic understanding of monads and functors. Is this specification valid, and should I honor it?
While building a purely functional data structure library for personal fun and professional use, and while using other libraries, I found that the "Fantasy Land Specification" was mentioned from time to time. They use this hierarchy. Although I did read some about category theory (tried and failed to fully understand all the concepts), some of the terms used in the specification are unknown to me (like Chain, Apply). My question:
-
Best explanation of monads ive ever seen, from the practical developper’s point of view.
No: neither of those examples are "properties of futures and of lists as such." "Async/Await" in particular is a special case of monadic behavior of a concurrency monad. This specifically (infamously) came up in the evolution of the Prommise spec in ECMAScript, which in turn led to the development of the Fantasy Land Spec and various implementations of it.
- should i learn design patterns?
-
Design Patterns Book for functional programming?
If you're programming in TypeScript you can checkout the fantasy land spec. It provides a spec for all the algebraic structures used in the JS world. You can learn what they are. You'll want to find alternative resources to learn what they are how they work. Fantasy land is just a spec not a guide.
-
Ruby in FantasyLand: SumsUp
Javascript comes with this lovely little spec called Fantasy Land that defines certain type classes in Category Theory and how they interact.
What are some alternatives?
daggy - Library for creating tagged constructors.
worldle
hkts - Functional programming tools: option, either, task, state, optics, etc.
awesome-functional-programming - Yet another resource for collecting articles, videos etc. regarding functional programming
sum-types - An attempt to emulate sum types using Go generics.
awesome-functional-python - A curated list of awesome things related to functional programming in Python.
lofty-rs - Audio metadata library
ramda - :ram: Practical functional Javascript
mp4ff - Library and tools for parsing and writing MP4 files including video, audio and subtitles. The focus is on fragmented files. Includes mp4ff-info, mp4ff-encrypt, mp4ff-decrypt and other tools.
newtype-ts - Implementation of newtypes in TypeScript
Exercism - website - The codebase for Exercism's website.
folktale - [not actively maintained!] A standard library for functional programming in JavaScript