TL;DR: I want the exact behavior as filter ((== 4) . length) . subsequences
. Just using subsequences
also creates variable length of lists, which takes a lot of time to process. Since in the end only lists of length 4 are needed, I was thinking there must be a faster way.
I have a list of functions. The list has the type [Wor -> Wor]
The list looks something like this
[f1, f2, f3 .. fn]
What I want is a list of lists of n
functions while preserving order like this
input : [f1, f2, f3 .. fn]
argument : 4 functions
output : A list of lists of 4 functions.
Expected output would be where if there's an f1
in the sublist, it'll always be at the head
of the list.
If there's a f2
in the sublist and if the sublist doens't have f1
, f2
would be at head
. If fn
is in the sublist, it'll be at last
.
In general if there's a fx
in the list, it never will be infront of f(x - 1)
.
Basically preserving the main list's order when generating sublists.
It can be assumed that length of list will always be greater then given argument.
I'm just starting to learn Haskell so I haven't tried all that much but so far this is what I have tried is this:
Generation permutations with subsequences
function and applying (filter (== 4) . length)
on it seems to generate correct permutations -but it doesn't preserve order- (It preserves order, I was confusing it with my own function).
So what should I do?
Also if possible, is there a function or a combination of functions present in Hackage
or Stackage
which can do this? Because I would like to understand the source.
take 4 [f1, ..., fn]
– Narthexsubsequences
should definitely preserve order in the way it sounds like you want. Can you show an example where it does something wrong? (It doesn’t even have to involve functions, right? Could be lists of numbers?) – Antimonyl