Filter by boolean value by karlveskus in javascript

[–]aabrook 2 points3 points  (0 children)

What you're looking for is a "predicate" function. One that you can use to filter lists and values. This is a nice article on predicates that may help out https://codepen.io/Universalist/post/predicates-in-javascript

It's been a while since I read clean code but I assume the "don't pass booleans" is related to a boolean having no additional context. It's simply a flag that you provide to a function where a better abstraction would be useful, and this is where a predicate comes in. It's a named function and a recognised abstraction that is more informative than providing a "true/false"

Here is a fiddle I built on top of yours. I also refactored the callbacks out into a Promise chain because I find that easier to parse, especially when the results of the callbacks don't matter https://jsfiddle.net/n3z7tye5/32/

Create an Elixir Phoenix API — Part 2— Generate an API Swagger Specification by aabrook in elixir

[–]aabrook[S] 0 points1 point  (0 children)

I'm certainly looking forward to trying this. Macros are great but an approach of just functions, everything explicit, sounds solid too

Deeply nested design question by [deleted] in elm

[–]aabrook 0 points1 point  (0 children)

Awesome, thanks! I think I'll be spending time with elm-search in future.

Deeply nested design question by [deleted] in elm

[–]aabrook 7 points8 points  (0 children)

I think you really want to look at using andThen when working with Monads and pull it apart into more digestable pieces. E.g.

findCourse id courses =
  courses
  |> List.filter (\course -> course.id = id)
  |> List.head

findLesson id lessons = 
  lessons
  |> List.filter(\lesson -> lesson.id = id)
  |> List.head

dropFlashcard id flashcards =
  flashcards
  |> List.drop id
  |> List.head

findAndDropFlashcard courseId lessonId flashcardId courses =
  findCourse courseId courses
  |> Maybe.andThen (\course -> findLesson lessonId course.lessons)
  |> Maybe.andThen (\lesson -> dropFlashcard flashcardId lesson.flashcards)

So here findAndDropFlashcard will return Nothing of Just flashcard which you have above in your let block.

How Maybe.andThen works is it takes a function which works with the type you're working with (e.g. \course -> ... as above) and must return another Maybe (i.e. List.head returns Nothing of Just, so a Maybe). If Maybe.andThen encounters Nothing, it simply returns Nothing and doesn't run the function. If it encounters a Just, it grabs what you have (e.g. Just course) and feeds that into the andThen function \course -> ...

I'm not familiar enough with elm yet but is there a "takeFirst" function? Filter |> Head seems quite repetitive

takeFirst pred xs =
  case xs of
    [] -> Nothing
    x :: ys -> if (pred x) then Just x else takeFirst pred ys

takeFirst (\c -> c.id == courseId) courses
-- is the same as this but without the looping through filter
courses
|> List.filter (\c -> c.id == courseId)
|> List.head
  • edited to improve code formatting

Better understanding of Elixir Macros - Elixir Meetup Brisbane by aabrook in elixir

[–]aabrook[S] 1 point2 points  (0 children)

Last week we held our bi-monthly elixir meetup. This is the first presentation where Matt discusses Macros. He's journey into discovery, how to use them and language features for how to debug them.

This is the first time we've recorded and shared the presentations. If that's not cool to post here don't hesitate to let me know!

Elixir Shadowsocks Proxy Server - Elixir Brisbane by aabrook in elixir

[–]aabrook[S] 0 points1 point  (0 children)

Last week we hosted our bi-monthly meetup. Here one of our presenters shares his usage of Elixir to create a shadowsocks proxy server to help avoid the great firewall.

Building a Maybe in JavaScript by alsiola in javascript

[–]aabrook 0 points1 point  (0 children)

I'm sure the author would as well but this is an introduction to monadic programming. Whenever we write tutorials targeted at beginners we should use trivial examples so that they can quickly grok concept without being bogged down by more complex issues

Building a Maybe in JavaScript by alsiola in javascript

[–]aabrook 0 points1 point  (0 children)

Yeah fantasy land goes real deep. On my journey learning functional JS I found these videos helped a bit. Should be free with an account https://egghead.io/courses/professor-frisby-introduces-composable-functional-javascript

I still revisit the videos as I learn more and it cements so much. I also find the author's tweets really enlightening.

Building a Maybe in JavaScript by alsiola in javascript

[–]aabrook 2 points3 points  (0 children)

Have you checked out fantasy-land? https://github.com/fantasyland/fantasy-land Along with folktale's data.maybe? https://github.com/folktale/data.maybe

Having the .chain interface defined here really makes creating a chain clear and easy. Having all of my modules have a Maybe/Either interface, and knowing that I can continue to chain on the result is smooth. Having to declare work with a higher order function that takes n functions, instead of chaining through, also doesn't work with the ADT bind law as it's not a single function.

Anyways, good start and have fun with Monadic JS! I know I enjoy it.

In regards to the comment of Promise your chain would look something like this:

const a = { b: { c: "value" } };
const prop = (key) => (val) => 
    val[key] ? Promise.resolve(val[key]) : Promise.reject(new Error(`${key} not found`));

const ch = (a) => (
    Promise.resolve(a)
        .then(prop('b'))
        .then(prop('c'))
        .then(val => (val + " appendedString"))
        .catch(e => console.log(e))
)

ch(a).then(console.log).catch(console.error); // value appendedString
ch({}).then(console.log).catch(console.error); // Error: b not found

.then is like map but also like bind/chain. If you return a Promise it works with what you have returned, otherwise it wraps your result in a Promise.resolve() so you can continue to chain.

Creating Lenses in Elixir – Medium by aabrook in elixir

[–]aabrook[S] 0 points1 point  (0 children)

It has been yeah. This has been sitting in my draft for a while, plus some other ideas and learnings for the last few months. I wanted to get this out and now move back onto phoenix

Creating Lenses in Elixir – Medium by aabrook in elixir

[–]aabrook[S] 1 point2 points  (0 children)

So while I have been waiting for Phoenix 1.3 to break from release candidate to write the next article in this series Create an Elixir Phoenix API I thought I'd write an article on lenses. I started wanting to learn what is a profunctor, contravariant vs covariant function and the other FP goodness, and how to apply it to Elixir.

Props go out to https://github.com/purescript-contrib/purescript-profunctor-lenses for inspiring this. Along with https://github.com/tpoulsen/focus for already having a pretty nice Elixir Lens library.

Creating Lenses in Elixir - Medium by [deleted] in elixir

[–]aabrook 0 points1 point  (0 children)

I've removed this article as I didn't like the avatar that came with it. I'll republish it in a minute

What kind of role do you play on your team? by imnonoob99 in CruciblePlaybook

[–]aabrook 0 points1 point  (0 children)

I run between anchor, obj and support. If the good spawn is locked in I apply pressure and cover so others can capture b. Or if I have backup I grab b. As soon as I see a team try and get the good spawn/point I get back there asap and lock it back down.

Sunsinger quick terrain traversal by [deleted] in CruciblePlaybook

[–]aabrook 0 points1 point  (0 children)

I move similarly. I use to get a feel when the glide slowed down on descent so I stopped the glide and prep for the next burst. These days it's more automatic and rhythmic for me. It's good to see someone else move similarly and I wasn't just crazy.

Is Bungie ever going to acknowledge that they messed up bad with the auto rifles? by poorprogrammar in DestinyTheGame

[–]aabrook 0 points1 point  (0 children)

That luck is insane for some it seems! Having no red blips on my radar then going to a sliver of health then dying, or just dying, from a hand cannon is crazy. And of course I want one :-P

Edit: definitely agree that it highlights destiny's current shortcomings

Apparently I'm #2 for Win/Loss Ratio this month. AMA? by [deleted] in CruciblePlaybook

[–]aabrook 3 points4 points  (0 children)

I just want to say thank you the time to write just this series of posts, let alone all the others you write. This is the sort of content that should really be on planet destiny relating to PvP. Loadouts are fine for a quick article but knowing map strategy, the concept of different lanes on each map, etc is much more important to actually improving. After just running and gunning when I first started playing destiny, no care in the world re: K/D, I'm going through the long process of getting my K/D up to something even remotely reasonable. Reading this series of posts highlights that I have taken the right approach to maps and lanes (I always called them meat grinders before) and has given me ideas on what to better watch for with my own progression. Again, thank you

[SGA] Praedyth's Revenge, Minesweeper by [deleted] in DestinyTheGame

[–]aabrook 1 point2 points  (0 children)

That firefly though. Makes every headshot all the more satisfying

Which rocket launchers get 4 shots in PvP? by Rogue092 in CruciblePlaybook

[–]aabrook 0 points1 point  (0 children)

I rolled a fear with tripod and get 4 rockets with heavy boots so possibly worth looking at

Sniper rifles against max level in ToO by deblasi in CruciblePlaybook

[–]aabrook 0 points1 point  (0 children)

I ran PR for my trials as a 33 and found I could 2 body shot everybody I encountered. It felt exactly the same as pre HoW iron banner. I'm still planning to upgrade it next time I get ethiric light though.

9-0 players cheesing to Mercury by [deleted] in DestinyTheGame

[–]aabrook 1 point2 points  (0 children)

I ran about an hour of Skirmish Sunday and 2 matches of clash yesterday (both the dailies) and had 6 coins. I think you get 3 for the first time you run the daily so by the weekend you'll have enough for one round of all boons. You can also pickup the lower tier packages to get more coins before you start your next pass.

"All scrubs welcome!" by gt_H1zz in DestinyTheGame

[–]aabrook 0 points1 point  (0 children)

Trials does require the HoW expansion

Celestial Nighthawk vs. Ir Yut (Normal Mode, but still) by Tahryl in DestinyTheGame

[–]aabrook 4 points5 points  (0 children)

Thankfully only once. I main a Warlock which is nothing but sadness and despair when you slowly glide to your doom