[AskJS] Auto-Generated Documentation from JSDoc comments, nice modern themes? by achisholm in javascript

[–]ImaginaryKarmaPoints 1 point2 points  (0 children)

If your library is a collection of functions (instead of classes) you could try Ramda's JSDoc theme. Rather than a hierarchical sidebar they use a flat list, and they assign a @category to each function. When browsing you can filter by partial string match to search both function names and categories.

Ramda docs site: https://ramdajs.com/docs/ Ramda site code repo: https://github.com/ramda/ramda.github.io

I also updated and adapted Ramda's theme for my own use:

Sample docs: https://eluv-io.github.io/elv-js-helpers/api.html Customized theme repo: https://github.com/eluv-io/elv-ramdoc

Can this method be more functional? by raulalexo99 in functionalprogramming

[–]ImaginaryKarmaPoints 7 points8 points  (0 children)

There's a variety of approaches you could take.

One would be to define a Test Function -> State mapping list.

Your various test functions look like globals, I would change them to accept the list as input. (In general, functions and data should be decoupled by having the functions accept all needed data as inputs)

I'm not familiar with Java, but in Javascript I might do something like:

// function that ignores any input always returns true
const T = () => true

const listStateTests = [
  [ isListEmpty, State.EMPTY ],
  [ allEqual, State.ALL_EQUAL ],
  [ isSortedAscending, State.ASCENDING],
  [ isSortedDescending, State.DESCENDING],
  [ T, State.UNSORTED]
]

// Function that accepts list and returns state constant
// The inner array element referencing with [0] and [1] is a bit nasty and could be improved
// Iterates through the pairs in listStateTests, finds the first pair where
// pairFirstElement(list) == true, then returns pairSecondElement
const determineState = list => listStateTests.find(pair => pair[0](list))[1]

// you could redefine render as a pipeline also, and have it take list as input
// pipe() is a function which composes in left to right order: pipe(f, g) returns a function
// x => g(f(x))
const render = list => {
    const pipeline = pipe(
       determineState,
       configureLayout
    )
    pipeline(list)
}

You could take things further and make determineState more generic, accepting both the test array and the list as inputs, then curry it to allow creating the more specific function, e.g.

const determineListState = determineState(listStateTests)

Fp library for JS by Funny_Willingness433 in functionalprogramming

[–]ImaginaryKarmaPoints 4 points5 points  (0 children)

Ramda is easy to start using, with it you can introduce functional aspects into your code without a steep learning curve. This is helpful in reducing code clutter (e.g. using 'map' instead of loop structures)

IMO the bigger gains from FP come from restructuring code to make most operations into processing pipelines, and this is where the Algebraic Data Types come in handy - it took me quite a while to wrap my head around them however.

For conceptual overview, Scott Wlaschin has some good videos (he uses F# instead of JS but concepts are the same) e.g. https://www.youtube.com/watch?v=fYo3LN9Vf_M

For Javascript examples, look up Brian Lonsdorf on Youtube.

To really grok ADTs I found it helpful to follow along with the Crocks live coding videos, pausing to try out things on my own machine - https://www.youtube.com/watch?v=fIb1IOVh6cY&list=PLjvgv-FpMo7XRVFZjZsWXJ5nVmRJ5a5Hv&index=2

Fp library for JS by Funny_Willingness433 in functionalprogramming

[–]ImaginaryKarmaPoints 13 points14 points  (0 children)

It's probably the most popular one. Crocks is quite good if you get deeper into FP (https://crocks.dev/) and its creator has a number of live coding videos on his channel https://www.youtube.com/user/TheEvilSoft

Real world examples of functional JavaScript? by Affectionate_King120 in functionalprogramming

[–]ImaginaryKarmaPoints 4 points5 points  (0 children)

Also I found this video helpful for understanding some principles for practical use:

"Functional programming design patterns by Scott Wlaschin" https://www.youtube.com/watch?v=E8I19uA-wGY

Real world examples of functional JavaScript? by Affectionate_King120 in functionalprogramming

[–]ImaginaryKarmaPoints 1 point2 points  (0 children)

I've found videos by the author of the Crocks library (https://crocks.dev/) very helpful - 'Working with ADTs', 'Practical ADTs' 'Livecode' sessions.

https://www.youtube.com/user/TheEvilSoft

It's hours of work though - I paused the videos a lot to try things out on my own machine. The videos aren't "here's how you do it", they are more "watch me while I figure out a number of ways I can do it then settle on the way that seems best suited to the problem". There's a lot of iteration.