Comments (7)
Interesting.
The idea is that option are containers, something like a list that can be either empty or with only one element (actually that was the way I emulated options 15 years ago in other languages).
So why does it works here?
It works because Option
is a Foldable, which supports the operation toSeq
and that's used in the default implementation of length
. This function will return either 0 or 1 when applied to options.
We can certainly change that behavior, but to me looks good in principle, unless you have a good reason to remove it.
Sometime ago there was a suggestion in the F# user voice to make Option<'T> implement IEnumerable<'T> which was declined for technical limitation.
If it wasn't for that technical limitation you would be able without this library to do Seq.length None = 0
.
from fsharpplus.
No need to change that. It was only surprising (not knowing that).
effectively I had a Option<Option<string>>
and a Option<string>
which I both piped thru the same generic code. At a later code I was checking the len of the inner value and was surprised that it was always 0 when in effect I was (unconciously) expecting a compiler error.
maybe this should be document
from fsharpplus.
Actually, on my free time, I'm working on documenting the library.
Have a look at the abstractions here for example.
I still need to add the page for Foldable, but you will see as in the others, all methods and all types that are supported.
Although it's a lot of work, but it's something that needs to be done, given the size this library is getting, in terms of features and abstractions.
PS: I think in other languages/libraries (Haskell, Purescript, Idris, Scalaz) it's also a Foldable.
from fsharpplus.
Hey that looks sweet!
Can we have some samples for each of those. I am willing to help on this.
from fsharpplus.
There was quite a bit of criticism and confusion in the Haskell community around this when they were discussing whether to make Foldable part of the Prelude, notably around tuples. https://mail.haskell.org/pipermail/libraries/2016-February/026805.html
Personally I think it's fine.
from fsharpplus.
@mausch Interesting discussion. Here's foldable in purescript, they have lot of interesting instances we still don't. I think is a good source of inspiration since it's relatively new and they don't have the "breaking change problem", like Haskell libraries.
from fsharpplus.
@robkuz It would be really, really nice to have some samples either linked or at the foot of each abstraction page.
I just updated the docs to the latest version I have. If you want to add more stuff or samples, please do it. If you have questions about how to add things to the docs, please open an Issue with the questions and I will help.
Thanks in advance.
from fsharpplus.
Related Issues (20)
- Reader monad transform one env to another HOT 6
- Generic monad functions with SeqT HOT 5
- The link to Result does not work. HOT 2
- Groups should be NonEmptySeqs
- Juxt HOT 9
- GitHub Action to release docs
- Validation.ofResult doesn't require Semigroup
- `(>>=)` should be constrained with `Map` HOT 8
- New Validation type HOT 2
- Array.replace takes in seq for its two first values instead of arrays
- Adjust package info with icon and license elements
- Add more static member operators like >=> HOT 1
- `String.take 0 s` throws IndexOutOfRangeException HOT 2
- Traverse Lens Documentation Needs more Examples HOT 1
- Documentation table of contents is missing list of namespaces HOT 3
- Proposal: A set of modules for list and tree zippers HOT 1
- Upload packages built on main branch onto GitHub NuGet feed
- Int32.TryParse and F#+ tryParse give different results HOT 6
- Fable 4 support HOT 3
- Type inference issue with applicative2 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fsharpplus.