Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Keith Alexander
@kwijibo
so if you break your program down into a series of functions that transform your data R.pipe(f, g, h, i), and f might return a null/undefined, then you need to do either do null checks on g, h,and i as well (even though they are safe themselves), or you need to nest everything inside the first null check (losing compositionality)
Barry G
@bgits
These things sounds good, would be nice to see a nice write up /video with examples to really understand.
The other question for folks using this style in production, is how do your coworkers respond to reading code/ working on a codebase written in this style?
Brad Compton (he/him)
@Bradcomp
Personally, that's a tough one. I've introduced a number of FP concepts at my work, but container types aren't one of them (other than the occasional Future). While I see places where they could be used to good effect, there is definitely a barrier there.
Keith Alexander
@kwijibo
I really like that blogpost
Barry G
@bgits
no, but will take a look
Keith Alexander
@kwijibo
re how do colleagues respond: I suppose it depends on the colleagues in question, and how it's introduced :) Things like Maybe and Either are not very common in javascript of course, but on the other hand, the basic pattern should be sort of familiar from working with Arrays and Promises
Keith Alexander
@kwijibo
eg: [].map(f)has the same effect as S.Nothing().map(f)
and [3].map(f) has the same effect as S.Just(3).map(f)
Similarly,
S.Just(3).filter(x => x > 3) will return S.Nothing()
and
[3].filter(x => x > 3) will return []
David Chambers
@davidchambers

These things sounds good, would be nice to see a nice write up /video with examples to really understand.

I agree that this would be very useful, @bgvianyc. I currently have my hands full preparing the next release, but I look forward to tackling #210 and #211 (and possibly recording some screencasts) in a week or two.

Aldwin Vlasblom
@Avaq
Is there a way I can access the $Maybe type definition, other than via S.env[i], so that I can use it for my own sanctuary-def defined functions?
Aldwin Vlasblom
@Avaq
I'm hacking my way to it like this, currently:
//types.js
const {env} = require('sanctuary');
const last = xs => xs[xs.length - 1];
env.forEach(type => {
  const name = `$${last(type.name.split('/'))}`;
  exports[name] = type;
});
Now I can const {$Maybe} = require('./types')
Aldwin Vlasblom
@Avaq
Nah, that doesn't work, because higher order types don't have names before they are assigned the inner type.
So I get access to everything but Maybe and Either. ^^
Aldwin Vlasblom
@Avaq
Perhaps it'd be nice to create a sanctuary-types which exports all types currently baked into sanctuary-def, and a sanctuary-algebraic-types which exports $Either and $Maybe. Or simply export $Either and $Maybe from sanctuary the same way $FiniteNumber is exported from sanctuary-def.
Aldwin Vlasblom
@Avaq
The nice thing about the first approach is that I can do:
const T = Object.assign(require('sanctuary-types'), require('sanctuary-algebraic-types'), {Future, a, b})

const maybeToFuture = def('maybeToFuture', {}, [T.Maybe(T.b), T.a, T.Future(T.a, T.b)], ...)
Or to prevent naming conflicts: T = {native: require('sanctuary-types'), algebraic: require('sanctuary-algebraic-types')} - you get the point. :)
But with the second approach there is more certainty that I'm using the same type definition that is in my Sanctuary environment. So it's probably the better approach.
David Chambers
@davidchambers
@Avaq, S.EitherType and S.MaybeType are what you seek. ;)
David Chambers
@davidchambers

Perhaps it'd be nice to create a sanctuary-types which exports all types currently baked into sanctuary-def, and a sanctuary-algebraic-types which exports $Either and $Maybe.

This is close to what I have in mind. I created sanctuary-types several months ago for exactly the purpose you described. I created sanctuary-either and sanctuary-maybe a few days ago. I'd like to move the definitions of the Either and Maybe types (and their associated type constructors) from Sanctuary to these separate projects. Sanctuary will then depend on these packages, but people will be free to use the data types without using Sanctuary.

Irakli Safareli
@safareli
<3 nice
Aldwin Vlasblom
@Avaq
Oh. Wow @davidchambers. Alright then. Nothing to add :)
David Chambers
@davidchambers
I'm thrilled to welcome to @JAForbes to the Sanctuary team! He's been doing an admirable job of bridging the gap between the FP and JS communities, which is very much in line with our goals.
Stefano Vozza
@svozza
Welcome!
David Chambers
@davidchambers
I'm very excited about fantasyland/fantasy-land#197, @safareli! I have a feeling Alt will solve some problems I've been experiencing with and, or, and xor when integrating sanctuary-type-classes into Sanctuary.
Kevin Wallace
@kedashoe
@JAForbes :tada: :beer:
Brad Compton (he/him)
@Bradcomp
Loving all the developments that have been happening around here :tada:
James Forbes
@JAForbes
Thank you everyone :D
David Chambers
@davidchambers
I "pinned" three repositories: https://github.com/sanctuary-js.
Travis LaDuke
@laduke

Really appreciating sanctuary giving me nicer error messages.

How do you approach a list of different types of items?
S.tail([ ['a', 'b', 'c'], 'x','y', 'x' ])
I could use R.tail, but then I don't get a Just back.

Brad Compton (he/him)
@Bradcomp
@laduke while this may be a silly question, why do you need a list with different types of items?
Travis LaDuke
@laduke
I'm probably asking a silly question because I'm just doing exercises and this isn't a real problem
Little Schemer (car '(((hotdogs)) (and) (pickle) relish)) ; '((hotdogs))
David Chambers
@davidchambers
Lisps rely on lists being able to contain values of different types. It can be tricky to translate Scheme (or similar) to Haskell (or similar).
Travis LaDuke
@laduke
Thanks. I will skip those examples.
Travis LaDuke
@laduke
Is there a 'join' somewhere I can use to smash Justs together? (I know I could just use chain)
var lat = [[['hotdogs']], ['and'], ['pickle'], 'relish']
var justHotdogs = R.compose(R.map(S.head), S.head)(lat)
justHotdogs
Brad Compton (he/him)
@Bradcomp
It seems like a nested list (tree) could be defined using Sanctuary-def and then it would type check fine. I haven't played around with it, but here's the Haskell code:

data NestedList a = 
  Leaf a 
  | Arr [NestedList a] 
  deriving (Show)

main = putStrLn $ show $ Arr [Leaf 1, Leaf 2, Arr [Leaf 3, Leaf 4, Leaf 5]]
I think that's what you want.
Travis LaDuke
@laduke
I mean to get from Just(Just(["hotdogs"])) to Just(["hotdogs"])
Brad Compton (he/him)
@Bradcomp
Ooohhh, gotcha
chain(identity) :expressionless:
I don't know of another way
Travis LaDuke
@laduke
Okee
David Chambers
@davidchambers
Yep, chain(identity) is the way to go. We'll add this as S.join in the near future. :)
Travis LaDuke
@laduke
Wait, does this mean I know what a monad is?
David Chambers
@davidchambers
Just about, @laduke! You know what a Chain is, at the very least. If you look at the type-class hierarchy you'll see that Monad is just one step from Chain. :smile:
Drew
@dtipson
maybe an esoteric question, but S.head is a natural transformation, right?