Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
David Chambers
@davidchambers
True. We just need chain rather than map if the underlying ADT is sound.
We also need functions that return Maybe a rather than a | Null | Undefined.
The good news is that this is exactly the sort of problem Sanctuary was designed to solve!
@silly-goat
S.get
silly-goat
@silly-goat
get :: (Any -> Boolean) -> String -> a -> Maybe b
David Chambers
@davidchambers
This allows us to interact with user-provided data in a principled way.
@silly-goat
S.get (S.is ($.Array ($.Integer))) ('foo') ({foo: [1, 2, 3]})
silly-goat
@silly-goat
Just ([1, 2, 3])
David Chambers
@davidchambers
@silly-goat
S.get (S.is ($.Array ($.Integer))) ('foo') ({foo: [0, 0.5, 1]})
silly-goat
@silly-goat
Nothing
David Chambers
@davidchambers
@silly-goat
S.get (S.is ($.Array ($.Integer))) ('foo') ({})
silly-goat
@silly-goat
Nothing
David Chambers
@davidchambers
There is also a “plural” version, S.gets, which performs nested lookups.
@silly-goat
S.gets (S.is ($.Array ($.Integer)))
       (['foo', 'bar', 'baz'])
       ({foo: {bar: {baz: [1, 2, 3]}}})
silly-goat
@silly-goat
Just ([1, 2, 3])
David Chambers
@davidchambers
I just used map (map (map (map (f)))) to transform strings inside arrays inside a string map inside a pair inside an either. Living the dream!
Álvaro Touzón
@kasselTrankos
jajajaja
Brad Compton (he/him)
@Bradcomp
:laughing: ]
Ben Briggs
@ben-eb
mega map
Asad Saeeduddin
@masaeedu
you should map your maps over your maps to get a more mappy map
@silly-goat
const mappymap = S.map(S.map)(S.map)
mappymap(x => x * 2)([{ foo: 1 }, { bar: 2 }])
silly-goat
@silly-goat
[{"foo": 2}, {"bar": 4}]
Ben Briggs
@ben-eb
I had three levels of mapping today, Future [Object], not quite hit 4 levels yet :wink:
David Chambers
@davidchambers
Nice one, @ben-eb. :)
I like that, @masaeedu!

plaid/transcribe#27 includes this code:

const map2 = B (map) (map);
const map3 = B (map) (map2);
const map4 = B (map) (map3);

It clearly should have involved map (map) (map), though. :joy:

Ben Briggs
@ben-eb
Yeah, kind of slow going at the moment so I decided to start learning/using Fluture properly :smiley:
David Chambers
@davidchambers
That's an excellent way to make use of a slow period at work.
Ben Briggs
@ben-eb
I really like it. I have done some experiments in the past but making it work on real projects makes a world of difference
David Chambers
@davidchambers
Not having to reason about promises will be wonderful.
Ben Briggs
@ben-eb
I think I'll probably still have promises in the code? But I'd like to start promoting ways of writing lambdas that promisify a fluture composition
const app = pipe([futureF, futureG, ... ]);

const handler = async (event) => app(event).promise();
If there's better ways of doing it though I'm definitely open to ideas
I think for cloud computing we need either a promise or a callback function to let the system know we finished with our lambda
Ben Briggs
@ben-eb
But at least that way I can contain the promises to one specific place
Brad Compton (he/him)
@Bradcomp
That seems like a good plan
Ben Briggs
@ben-eb
Thanks, yeah I hope so :smile:
David Chambers
@davidchambers
@silly-goat
var map = S.map;

//  map4 :: (Functor f, Functor g, Functor h, Functor i) => (a -> b) -> f (g (h (i a))) -> f (g (h (i b)))
var map4 = map (map) (map (map) (map (map) (map)));

map4 (S.toUpper) (S.Right (S.Pair (42) ({x: ['foo'], y: ['bar', 'baz']})));
silly-goat
@silly-goat
Right (Pair (42) ({"x": ["FOO"], "y": ["BAR", "BAZ"]}))
David Chambers
@davidchambers
:point_up: Credit to Asad for this beauty!
Ben Briggs
@ben-eb
Anyone else get cross-eyed looking at that? :smiley:
Although the type signature helps a lot
Ben Briggs
@ben-eb
Looking at it again, should (a -> b) come first in the signature?
Ohhhh. I missed the fat arrow :D
Been a long day
David Chambers
@davidchambers
No worries. It's a long signature. :D
Asad Saeeduddin
@masaeedu
i'm not sure "credit" is the right word :sweat_smile:
it makes for a good brain teaser though
it seems like the more functional programming i learn the less names i use for things
so many things are map