-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How would one implement flatMap or bind with zug? #28
Comments
Hi @bradphelan! The name Note that in auto v1 = vector{...};
auto v2 = into_vector(cat | map(...), v1); Cheers! |
I agree conceptually but since transducers are a concept from Clojure, I'm happy to keep the names close to the Clojure's standard library. |
You have the incorrect implementation of mapcat then if you want to mimic the clojure implementation. https://sinusoid.es/zug/transducer.html#mapcat The example you give is ''' Which is not correct. This is what puzzled me in the first place. Mapcat should be the same as flatmap or monadic bind as it is often known. IE: the lambda should return a collection from each item and then the collections are concatenated together. If you read the clojure docs this is what they say. ''' |
You're right! Sorry about that. Reopening the issue so I can tackle this soon. |
And thanks for the report! |
As an aside. I found this while googling. https://english.stackexchange.com/questions/194901/sieve-vs-filter-are-they-opposites the main argument seems to be that sieve or filter refers to the act not the result thus to be precise one must say select or reject or where or filter out to describe which side of the partitioned set one is choosing. |
I quite agree with your remark about the misleading semantics behind "filter" (hence error-prone). Reusing a term because it is "standard" is not a good argument IMHO. Else, when do we change the world? ;) |
For example I'm looking for an equivalent to
result should be
{1,2,3,3,4,5,5,6,7}
ie: flatMap (also known as bind) takes each element of the source and passes it to the function which is expected to return a sequence and all sequences are concatenated together.
Though reading through your doc maybe the way to do this is with map and then cat like.
I notice that you have a mapcat but it doesn't do the same as above. Maybe it should be renamed catmap because it is equivalent to
cat | map
rather thanmap | cat
I have my own two libraries that do the same as transducers with one for space mapping and one for temporal mapping. But I'm intrigued by the design of transducers that allows one implementation to handle both by factoring out the
processes
. I need to spend some time with it.A small point. Somehow I prefer the term
where
rather thanfilter
. I'm always have to think twice withfilter
whether the predicate means to include all things that return positive or exclude them. I think the problem is that filter is most often used with predicates in English as filter out which has the opposite meaning to where and filter as often used in libraries like transducers.All dogs where tail length is longer than 20cm
vs
Filter out all dogs with tail length longer than 20cm
However I'm aware than different libraries use filter and where interchangeably so maybe it's just me.
The text was updated successfully, but these errors were encountered: