Question:
var isMinLength = R.compose(R.gte(R.__), R.length);
How do I reformat that so I can get back a function for a specific length, i.e. isMinLength(20)
and then feed that a string to test?
isMinLength('foobar')(20)
isMinLength = flip(useWith(gte, [ length, identity ]))
isMinLength(4, 'foo')
false
isMinLength = curry((n, str) => str.length >= n)
is more readable
flip
would actually be required in that case
:type
to help you determine or discover types. There's no JS equivalent. Plus there's no tuples so that sig was super confusing.
[a, b]
isn't any clearer, since [a]
is generally used for a generic array
->
step, and create a domain specific language for your app using generic but powerful functions
:type
? I wonder how difficult that would be.
isMinLength = useWith(lte, [identity, length]);
isMinLength(4, 'foo');
flip
, gte
? Why not just lte
?
var isMinLength = R.curry((length, a) => R.compose(R.gte(R.__, length), R.length)(a))
isMinLength(4, 'foo')
false
R.evolveKeys({
Make: 'photo_make',
Aperture: 'photo_aperture'
})
R.rekey
.
flip
more than once, it's questionable whether you should do it. The more points that have these sorts of issues, the less likely you should write it pointfree.
R.ap(S.Just(S.parseInt(10)), S.Just('42'))
Just(Just(42))
R.unnest
to the result the best approach?
Just
?
Just
and Maybe
in ramda docs, but never seen it defined anywhere
ap
shouldn't add extra nesting
R.ap
works btw? Does it delegate to Just(...).ap
?
Just(...).ap
seems broken
parseInt
also returns Maybe
S.parseInt(10)
wrapped with S.Just
?
S.Just('42').chain(S.parseInt(10))
?
.chain(x => x)
to remove it afterwards
R.unnest
use chain
under the hood?
R.unnest
is defined as R.chain(R.identity)
.
S.Just('42').chain(S.parseInt(10))
S.Just(S.parseInt(10))
, as the value is the result of applying a function whose type is as follows:customize :: String -> Either String (String -> Either String String)
S.parseInt(10)
, I really do have something like S.Just(S.parseInt(10))
. ;)
R.chain(S.parseInt(10), S.Just('42'))
Just(42)
@davidchambers I have the same issue a lot when I use Future#ap
for parallelism:
Future.of(a => b => asyncDoStuff(a, b)) //asyncDoStuff returns another Future
.ap(Future.of('a'))
.ap(Future.of('b')) //the two aps run in parallel
.chain(identity) //I now have to unnest, meh
It seems fiddly to have to unnest. I haven't found a more elegant way though.
[$.String, Either($.String, $.String)]
is for? runtime type checking?
R.sequence(Future.of, [Future.of('a'), Future.of('b')])
.chain(([a, b]) => asyncDoStuff(a, b))
Future.all([Future.of('a'), Future.of('b')])
.chain(([a, b]) => asyncDoStuff(a, b))
just curious, what
[$.String, Either($.String, $.String)]
is for? runtime type checking?
That's right. I'm using sanctuary-def. It makes it much easier to get the types to line up. :)
R.sequence
, where we need to specify of
of the inner type. But type checking seems useful too.
R.chain(S.parseInt(10), S.Just('42'))
Just(42)
R.chain(S.parseInt(10), S.Right('42'))
TypeError: ‘Either#chain’ is expected to return a value of type (Either a c); returned Just(42)
undefined is not a function
all the time :)